xsddoc/src/net/sf/xframe/xsddoc ProcessorListener.java,NONE,1.1 Processor.java,1.36,1.37

Kurt Riede <[email protected]> Thu, 03 Mar 2005 17:10:16 +0000
Newsgroups gmane.text.xml.xframe.xsddoc.devel
Message-ID <[email protected]>
Update of /cvsroot/xframe/xsddoc/src/net/sf/xframe/xsddoc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10369/src/net/sf/xframe/xsddoc

Modified Files:
	Processor.java 
Added Files:
	ProcessorListener.java 
Log Message:
Logging changed to use a Listener interface instead of direct logging. A programatic user now can decide externaly how logging is done.

Index: Processor.java
===================================================================
RCS file: /cvsroot/xframe/xsddoc/src/net/sf/xframe/xsddoc/Processor.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** Processor.java	26 Feb 2005 14:27:50 -0000	1.36
--- Processor.java	3 Mar 2005 17:10:13 -0000	1.37
***************
*** 227,230 ****
--- 227,233 ----
      private Map schemaLocationProcessedMap = new HashMap();
  
+     /** Reference to the current activ listener. */
+     private ProcessorListener listener;
+ 
      ////////////////////////////////////////////////
      // instantiation
***************
*** 235,238 ****
--- 238,242 ----
       */
      public Processor() {
+         listener = new ConsoleListener();
      }
  
***************
*** 416,419 ****
--- 420,441 ----
  
      /**
+      * Getter method for listener property.
+      *
+      * @return Returns the listener.
+      */
+     public ProcessorListener getListener() {
+         return listener;
+     }
+ 
+     /**
+      * Setter method for the listener.
+      *
+      * @param theListener The listener to set.
+      */
+     public void setListener(final ProcessorListener theListener) {
+         this.listener = theListener;
+     }
+ 
+     /**
       * Depending on xml attribute returns file extension for XML ro HTML files.
       *
***************
*** 442,446 ****
          }
          if (debug) {
!             status(System.out);
          }
          try {
--- 464,468 ----
          }
          if (debug) {
!             status();
          }
          try {
***************
*** 487,497 ****
      /**
       * Write environment status to given PrintStream.
-      *
-      * @param stream output stream for status report
       */
!     private void status(final PrintStream stream) {
!         stream.println("xsddoc.home: " + this.xsddocHome);
!         stream.println("out.folder: " + this.out);
!         stream.println("schema.location: " + this.mainSchemaLocation);
      }
  
--- 509,517 ----
      /**
       * Write environment status to given PrintStream.
       */
!     private void status() {
!         getListener().debug("xsddoc.home: " + this.xsddocHome);
!         getListener().debug("out.folder: " + this.out);
!         getListener().debug("schema.location: " + this.mainSchemaLocation);
      }
  
***************
*** 519,523 ****
      private void initBuilder() throws ParserConfigurationException {
          if (debug) {
!             System.out.println("create document builder");
          }
          builderFactory = DocumentBuilderFactory.newInstance();
--- 539,543 ----
      private void initBuilder() throws ParserConfigurationException {
          if (debug) {
!             getListener().debug("create document builder");
          }
          builderFactory = DocumentBuilderFactory.newInstance();
***************
*** 536,540 ****
          throws TransformerConfigurationException, IOException {
          tFactory = TransformerFactory.newInstance();
!         tFactory.setErrorListener(new ConsoleErrorListener());
          tFactory.setURIResolver(new ResourceResolver());
          tOverviewAll = createTransformer("overview-all.xsl");
--- 556,560 ----
          throws TransformerConfigurationException, IOException {
          tFactory = TransformerFactory.newInstance();
!         tFactory.setErrorListener(new ProcessorErrorListener());
          tFactory.setURIResolver(new ResourceResolver());
          tOverviewAll = createTransformer("overview-all.xsl");
***************
*** 562,566 ****
          throws TransformerConfigurationException, IOException {
          if (debug) {
!             System.out.println("create transformer for " + fileName);
          }
          final String resourceName = "/" + this.resourcePrefix + "/xslt/" + fileName;
--- 582,586 ----
          throws TransformerConfigurationException, IOException {
          if (debug) {
!             getListener().debug("create transformer for " + fileName);
          }
          final String resourceName = "/" + this.resourcePrefix + "/xslt/" + fileName;
***************
*** 589,593 ****
      private void process() throws TransformerException, SAXException, IOException, SchemaException {
          if (debug) {
!             System.out.println("start processing...");
          }
          FileUtil.copyFile(getResource("/" + this.resourcePrefix + "/css/stylesheet.css"), out + FILE_SEP + "stylesheet.css");
--- 609,613 ----
      private void process() throws TransformerException, SAXException, IOException, SchemaException {
          if (debug) {
!             getListener().debug("start processing...");
          }
          FileUtil.copyFile(getResource("/" + this.resourcePrefix + "/css/stylesheet.css"), out + FILE_SEP + "stylesheet.css");
***************
*** 596,600 ****
                  FileUtil.copyFile(css, out + FILE_SEP + "stylesheet.css");
              } catch (IOException e) {
!                 System.out.println("CSS file not found: " + css);
              }
          }
--- 616,620 ----
                  FileUtil.copyFile(css, out + FILE_SEP + "stylesheet.css");
              } catch (IOException e) {
!                 getListener().error("CSS file not found: " + css);
              }
          }
***************
*** 633,637 ****
          throws TransformerException, SAXException, IOException, SchemaException {
          if (debug) {
!             System.out.println("process schema " + schemaLocation);
          }
          final String namespaceURI = getTargetNamespace(schema);
--- 653,657 ----
          throws TransformerException, SAXException, IOException, SchemaException {
          if (debug) {
!             getListener().debug("process schema " + schemaLocation);
          }
          final String namespaceURI = getTargetNamespace(schema);
***************
*** 663,667 ****
          throws TransformerException, SAXException, IOException, SchemaException {
          if (debug) {
!             System.out.println("process components of schema " + schemaLocation);
          }
          final Element schemaRoot = schema.getDocumentElement();
--- 683,687 ----
          throws TransformerException, SAXException, IOException, SchemaException {
          if (debug) {
!             getListener().debug("process components of schema " + schemaLocation);
          }
          final Element schemaRoot = schema.getDocumentElement();
***************
*** 718,727 ****
              }
              if (name == null) {
!                 System.out.println("Ignoring unnamed component " + componentType);
                  return;
              }
              if (verbose) {
                  final String targetNamespace = DomUtil.getAttributeValue(schema.getDocumentElement(), TARGETNAMESPACE);
!                 System.out.println("process " + componentType + " {" + targetNamespace + "}" + name + " from file "
                          + schemaLocation);
              }
--- 738,747 ----
              }
              if (name == null) {
!                 getListener().info("Ignoring unnamed component " + componentType);
                  return;
              }
              if (verbose) {
                  final String targetNamespace = DomUtil.getAttributeValue(schema.getDocumentElement(), TARGETNAMESPACE);
!                 getListener().info("process " + componentType + " {" + targetNamespace + "}" + name + " from file "
                          + schemaLocation);
              }
***************
*** 747,752 ****
                  transform(new DOMSource(result, DOM_PROTOCOL), tHtml,
                      subfolder + FILE_SEP + componentType + FILE_SEP + name + getExtension());
                  if (isDebug()) {
!                     System.out.println(ExceptionUtil.printStackTrace(t));
                  }
              }
--- 767,773 ----
                  transform(new DOMSource(result, DOM_PROTOCOL), tHtml,
                      subfolder + FILE_SEP + componentType + FILE_SEP + name + getExtension());
+                 getListener().error("xsddoc caused an error: " + ExceptionUtil.getMessage(t));
                  if (isDebug()) {
!                     getListener().debug(ExceptionUtil.printStackTrace(t));
                  }
              }
***************
*** 850,854 ****
          final String rawSchemaLocation = DomUtil.getAttributeValue(component, "schemaLocation");
          if (rawSchemaLocation == null || "".equals(rawSchemaLocation)) {
!             System.out.println("included schema without schemaLocation");
              return;
          }
--- 871,875 ----
          final String rawSchemaLocation = DomUtil.getAttributeValue(component, "schemaLocation");
          if (rawSchemaLocation == null || "".equals(rawSchemaLocation)) {
!             getListener().error("included schema without schemaLocation");
              return;
          }
***************
*** 859,863 ****
          final String includedSchemaLocation = FileUtil.getLocation(schemaLocation, rawSchemaLocation);
          if (debug) {
!             System.out.println("process included schema " + includedSchemaLocation);
          }
          final Document includedSchema = getDocument(getSystemId(includedSchemaLocation));
--- 880,884 ----
          final String includedSchemaLocation = FileUtil.getLocation(schemaLocation, rawSchemaLocation);
          if (debug) {
!             getListener().debug("process included schema " + includedSchemaLocation);
          }
          final Document includedSchema = getDocument(getSystemId(includedSchemaLocation));
***************
*** 899,903 ****
          final String importedNamespace = DomUtil.getAttributeValue(component, "namespace");
          if (rawSchemaLocation == null || "".equals(rawSchemaLocation)) {
!             System.out.println("imported schema without schemaLocation: " + importedNamespace);
              return;
          }
--- 920,924 ----
          final String importedNamespace = DomUtil.getAttributeValue(component, "namespace");
          if (rawSchemaLocation == null || "".equals(rawSchemaLocation)) {
!             getListener().error("imported schema without schemaLocation: " + importedNamespace);
              return;
          }
***************
*** 908,912 ****
          final String importedSchemaLocation = FileUtil.getLocation(schemaLocation, rawSchemaLocation);
          if (debug) {
!             System.out.println("process imported schema " + importedSchemaLocation);
          }
          if (!importCache.containsKey(importedSchemaLocation)) {
--- 929,933 ----
          final String importedSchemaLocation = FileUtil.getLocation(schemaLocation, rawSchemaLocation);
          if (debug) {
!             getListener().info("process imported schema " + importedSchemaLocation);
          }
          if (!importCache.containsKey(importedSchemaLocation)) {
***************
*** 915,919 ****
              process(importedSchema, importedSchemaLocation);
          } else if (debug) {
!             System.out.println("Abort import (already processed): " + importedSchemaLocation);
          }
      }
--- 936,940 ----
              process(importedSchema, importedSchemaLocation);
          } else if (debug) {
!             getListener().debug("Abort import (already processed): " + importedSchemaLocation);
          }
      }
***************
*** 1033,1037 ****
          throws FileNotFoundException, TransformerException {
          if (debug) {
!             System.out.println("create " + outFile);
          }
          setParameters(transformer);
--- 1054,1058 ----
          throws FileNotFoundException, TransformerException {
          if (debug) {
!             getListener().debug("create " + outFile);
          }
          setParameters(transformer);
***************
*** 1142,1146 ****
      private InputStream getResource(final String resourceName) throws IOException {
          if (debug) {
!             System.out.println("Loading resource " + resourceName);
          }
          synchronized (this) {
--- 1163,1167 ----
      private InputStream getResource(final String resourceName) throws IOException {
          if (debug) {
!             getListener().debug("Loading resource " + resourceName);
          }
          synchronized (this) {
***************
*** 1302,1306 ****
       * Error listener writing all events to console.
       */
!     private final class ConsoleErrorListener implements ErrorListener {
  
          /**
--- 1323,1327 ----
       * Error listener writing all events to console.
       */
!     private final class ProcessorErrorListener implements ErrorListener {
  
          /**
***************
*** 1311,1315 ****
           */
          public void warning(final TransformerException e) {
!             System.out.println("xsddoc caused a warning: " + XMLUtil.getLocallizedMessageAndLocation(e));
          }
  
--- 1332,1336 ----
           */
          public void warning(final TransformerException e) {
!             getListener().warn("xsddoc caused a warning: " + XMLUtil.getLocallizedMessageAndLocation(e));
          }
  
***************
*** 1321,1325 ****
           */
          public void error(final TransformerException e) {
!             System.out.println("xsddoc caused an error: " + XMLUtil.getLocallizedMessageAndLocation(e));
          }
  
--- 1342,1346 ----
           */
          public void error(final TransformerException e) {
!             getListener().error("xsddoc caused an error: " + XMLUtil.getLocallizedMessageAndLocation(e));
          }
  
***************
*** 1331,1339 ****
           */
          public void fatalError(final TransformerException e) {
!             System.out.println("xsddoc caused a fatal error: " + XMLUtil.getLocallizedMessageAndLocation(e));
              if (isDebug()) {
!                 e.printStackTrace();
              }
          }
      }
  }
--- 1352,1402 ----
           */
          public void fatalError(final TransformerException e) {
!             getListener().fatal("xsddoc caused a fatal error: " + XMLUtil.getLocallizedMessageAndLocation(e));
              if (isDebug()) {
!                 getListener().debug(ExceptionUtil.printStackTrace(e));
              }
          }
      }
+ 
+     /**
+      * Implementation of the {@link net.sf.xframe.xsddoc.ProcessorListener}
+      * interface that simple logs everything to the console.
+      */
+     public final class ConsoleListener implements ProcessorListener {
+ 
+         /**
+          * @see net.sf.xframe.xsddoc.ProcessorListener#debug(java.lang.String)
+          */
+         public void debug(final String message) {
+             System.out.println(message);
+         }
+ 
+         /**
+          * @see net.sf.xframe.xsddoc.ProcessorListener#info(java.lang.String)
+          */
+         public void info(final String message) {
+             System.out.println(message);
+         }
+ 
+         /**
+          * @see net.sf.xframe.xsddoc.ProcessorListener#warn(java.lang.String)
+          */
+         public void warn(final String message) {
+             System.out.println(message);
+         }
+ 
+         /**
+          * @see net.sf.xframe.xsddoc.ProcessorListener#error(java.lang.String)
+          */
+         public void error(final String message) {
+             System.out.println(message);
+         }
+ 
+         /**
+          * @see net.sf.xframe.xsddoc.ProcessorListener#fatal(java.lang.String)
+          */
+         public void fatal(final String message) {
+             System.out.println(message);
+         }
+     }
  }

--- NEW FILE: ProcessorListener.java ---
/*
This file is part of the xframe software package
hosted at http://xframe.sourceforge.net

Copyright (c) 2003 Kurt Riede.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package net.sf.xframe.xsddoc;

/**
 * Listener interface for logging.
 *
 * @author <a href="mailto:[email protected]">Kurt Riede</a>
 */
public interface ProcessorListener {

    /**
     * @param message the message of the event
     */
    void debug(String message);

    /**
     * @param message the message of the event
     */
    void info(String message);

    /**
     * @param message the message of the event
     */
    void warn(String message);

    /**
     * @param message the message of the event
     */
    void error(String message);

    /**
     * @param message the message of the event
     */
    void fatal(String message);
}


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click