xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@hyperreal.org
Subject cvs commit: xml-0.0/src/java/stylebook/src/org/apache/stylebook/producers ContextProducer.java ParserProducer.java ProjectProducer.java
Date Mon, 15 Nov 1999 22:08:26 GMT
pier        99/11/15 14:08:23

  Added:       src/java/stylebook/src/org/apache/stylebook
                        AbstractComponent.java BasicContext.java
                        BasicEngine.java BasicEntry.java
                        BasicParameters.java Component.java
                        ComponentFactory.java CreationContext.java
                        CreationException.java Engine.java Entry.java
                        InitializationException.java Loader.java
                        LoadingException.java Logger.java
                        NodeListParameters.java Parameters.java Parser.java
                        Printer.java Processor.java Producer.java
                        Project.java RegExpHandler.java ResourceEntry.java
                        StreamHandler.java StyleBook.java engine.conf.xml
                        loader.conf.xml stylebook.properties
               src/java/stylebook/src/org/apache/stylebook/parsers
                        CachingParser.java XML4JParser.java
                        XercesParser.java
               src/java/stylebook/src/org/apache/stylebook/printers
                        HTMLPrinter.java ImagePrinter.java XMLPrinter.java
               src/java/stylebook/src/org/apache/stylebook/processors
                        ImportProcessor.java LotusXSLProcessor.java
                        NullProcessor.java XalanProcessor.java
               src/java/stylebook/src/org/apache/stylebook/producers
                        ContextProducer.java ParserProducer.java
                        ProjectProducer.java
  Log:
  StyleBook new release primary sources checkin.
  
  Revision  Changes    Path
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/AbstractComponent.java
  
  Index: AbstractComponent.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:04:43 $
   */
  public abstract class AbstractComponent implements Component {
      /** The Engine owning this Component instance. */
      protected Engine engine=null;
      /** This component initialization Parameters. */
      protected Parameters params=null;
  
      /**
       * Initialize this component instance.
       *
       * @param e The Engine owning this Component instance
       * @param p This component initialization Parameters
       */
      public void init(Engine e, Parameters p)
      throws InitializationException {
          if (e==null) throw new NullPointerException("Null Engine");
          if (p==null) throw new NullPointerException("Null Parameters");
          this.engine=e;
          this.params=p;
          this.debug("Initializing");
      }
  
      /**
       * Report a debug message to the owning Engine.
       *
       * @param msg The debug message to report.
       */
      protected void debug(String message) {
          this.engine.debug(this, message);
      }
  
      /**
       * Report a log message to the owning Engine.
       *
       * @param msg The log message to report.
       */
      protected void log(String message) {
          this.engine.log(this, message);
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/BasicContext.java
  
  Index: BasicContext.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.util.Enumeration;
  import java.util.Hashtable;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:04:51 $
   */
  public class BasicContext extends BasicParameters implements CreationContext {
      /** Our Source */
      private String source=null;
      /** Our Target */
      private String target=null;
  
      public BasicContext(String source, String target) {
          super();
          this.source=source;
          this.target=target;
      }
  
      public String getSourceName() {
          return(this.source);
      }
  
      public String getTargetName() {
          return(this.target);
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/BasicEngine.java
  
  Index: BasicEngine.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.util.Enumeration;
  import java.util.Hashtable;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import org.xml.sax.InputSource;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:04:58 $
   */
  public class BasicEngine implements Engine {
      /** Our Parser instance */
      private Parser parser=null;
      /** The Producer table */
      private Hashtable producers=new Hashtable();
      /** The Processor table */
      private Hashtable processors=new Hashtable();
      /** The Printers table */
      private Hashtable printers=new Hashtable();
      /** The Logger instance */
      private Logger logger=null;
      /** The debug() activation flag */
      private boolean debug=false;
  
      /**
       * Create a new instance of this Engine.
       *
       * @param parser The name of the Parser class used to read configuration.
       * @param cont The SystemID of the configuration file.
       * @param logger The Logger used by this Engine.
       */
      public BasicEngine(String parser, String conf, Logger logger)
      throws InitializationException {
          super();
          // Check the Logger
          if (logger==null)
              throw new InitializationException("No Logger instance specified");
          else this.logger=logger;
          // Parse the configuration file with the specified Parser
          Parser pars=ComponentFactory.getParser(parser);
          pars.init(this,new BasicParameters());
          Document d=null;
          try {
              if ((d=pars.parse(new InputSource(conf)))==null)
                  throw new InitializationException("Parser returned null doc");
          } catch (Exception e) {
              throw new InitializationException("Cannot parse configurations \""+
                                                conf+"\"");
          }
          // Step thru the different elements to configure the engine
          this.logger.log(this,"Initializing");
          Element e=d.getDocumentElement();
          if (!e.getTagName().equals("engine"))
              throw new InitializationException("Conf don't begin with <engine>");
          NodeList l=e.getChildNodes();
          for (int x=0; x<l.getLength(); x++) {
              if (l.item(x).getNodeType()!=Node.ELEMENT_NODE) continue;
              Element n=(Element)l.item(x);
              String t=n.getTagName();
              if (t.equals("debug"))
                  if(n.getAttribute("enabled").equalsIgnoreCase("true"))
                      this.debug=true;
                  else this.debug=false;
              else if (t.equals("parser")) configureParser(n);
              else if (t.equals("producer")) configureProducer(n);
              else if (t.equals("processor")) configureProcessor(n);
              else if (t.equals("printer")) configurePrinter(n);
              else throw new InitializationException("Unknown Element <"+t+">");
          }
          if(this.parser==null) this.parser=pars;
      }
  
      /** Configure the Parser from a givent Element */
      private void configureParser(Element e)
      throws InitializationException {
          if (this.parser!=null)
              throw new InitializationException("Parser already configured");
          String classname=e.getAttribute("class");
          this.parser=ComponentFactory.getParser(classname);
          this.parser.init(this,new NodeListParameters(e.getChildNodes()));
      }
  
      /** Configure a Producer from a givent Element */
      private void configureProducer(Element e)
      throws InitializationException {
          String name=e.getAttribute("name");
          String cls=e.getAttribute("class");
          if(name.length()==0)
              throw new InitializationException("No name specified for Producer");
          Producer p=ComponentFactory.getProducer(cls);
          p.init(this,new NodeListParameters(e.getChildNodes()));
          if(this.producers.put(name,p)!=null)
              throw new InitializationException("Duplucate Producer \""+
                                                name+"\"");
      }
  
      /** Configure a Processor from a givent Element */
      private void configureProcessor(Element e)
      throws InitializationException {
          String name=e.getAttribute("name");
          String cls=e.getAttribute("class");
          if(name.length()==0)
              throw new InitializationException("No name specified for Processor");
          Processor p=ComponentFactory.getProcessor(cls);
          p.init(this,new NodeListParameters(e.getChildNodes()));
          if(this.processors.put(name,p)!=null)
              throw new InitializationException("Duplucate Processor \""+
                                                name+"\"");
      }
  
      /** Configure a Printer from a givent Element */
      private void configurePrinter(Element e)
      throws InitializationException {
          String name=e.getAttribute("name");
          String cls=e.getAttribute("class");
          if(name.length()==0)
              throw new InitializationException("No name specified for Printer");
          Printer p=ComponentFactory.getPrinter(cls);
          p.init(this,new NodeListParameters(e.getChildNodes()));
          if(this.printers.put(name,p)!=null)
              throw new InitializationException("Duplucate Printer \""+
                                                name+"\"");
      }
  
      /**
       * Return the Parser instance owned by this Engine.
       *
       * @return A non-null Parser instance.
       */
      public Parser getParser() {
          return(this.parser);
      }
  
      /**
       * Return a Producer instance associated with the specified name.
       *
       * @param name A non-null String representing the Producer name.
       * @return A non-null Producer instance or null if no Producer is associated
       *         with the specified name.
       */
      public Producer getProducer(String name) {
          return((Producer)this.producers.get(name));
      }
  
      /**
       * Return a Processor instance associated with the specified name.
       *
       * @param name A non-null String representing the Processor name.
       * @return A non-null Processor instance or null if no Processor is
       *         associated with the specified name.
       */
      public Processor getProcessor(String name) {
          return((Processor)this.processors.get(name));
      }
  
      /**
       * Return a Printer instance associated with the specified name.
       *
       * @param name A non-null String representing the Printer name.
       * @return A non-null Printer instance or null if no Printer is
       *         associated with the specified name.
       */
      public Printer getPrinter(String name) {
          return((Printer)this.printers.get(name));
      }
  
      /**
       * Report a debug message to the user.
       *
       * @param msg The debug message to report.
       */
      public void debug(Object source, String msg) {
          if(this.debug) this.logger.log(source,msg);
      }
  
      /**
       * Report a log message to the user.
       *
       * @param msg The log message to report.
       */
      public void log(Object source, String msg) {
          this.logger.log(source,msg);
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/BasicEntry.java
  
  Index: BasicEntry.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.io.IOException;
  import java.io.OutputStream;
  import java.util.Enumeration;
  import java.util.Vector;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:05:05 $
   */
  public class BasicEntry extends BasicContext implements Entry {
      private Producer producer=null;
      private Printer printer=null;
      private Vector tasks=new Vector();
  
      public BasicEntry(Engine e, String s, String t, Element d, Parameters p)
      throws LoadingException {
          super(s,t);
          String prod=d.getAttribute("producer");
          String prnt=d.getAttribute("printer");
          e.debug(this,"Creating Entry Source=\""+s+"\" Target=\""+t+"\""+
                       " Producer=\""+prod+"\" Printer=\""+prnt+"\"");
          if ((this.producer=e.getProducer(prod))==null)
              throw new LoadingException("Invalid Producer \""+prod+"\"");
          if ((this.printer=e.getPrinter(prnt))==null)
              throw new LoadingException("Invalid Printer \""+prnt+"\"");
          NodeList l=d.getChildNodes();
          Parameters p2=new NodeListParameters(l).merge(p);
          for(int x=0;x<l.getLength();x++) {
              if(l.item(x).getNodeType()!=Node.ELEMENT_NODE) continue;
              Element el=(Element)l.item(x);
              if(el.getTagName().equals("parameter")) continue;
              if(!el.getTagName().equals("processor"))
                  throw new LoadingException("Invalid Tag <"+el.getTagName()+">");
              Processor proc=e.getProcessor(el.getAttribute("name"));
              if(proc==null)
                      throw new LoadingException("Invalid Processr \""+proc+"\"");
              Parameters par=new NodeListParameters(el.getChildNodes()).merge(p2);
              this.tasks.add(new Task(proc,par));
          }
          this.merge(p2);
      }
  
      public void create(OutputStream out)
      throws IOException, CreationException {
          Document d=this.producer.produce(this);
          Enumeration e=this.tasks.elements();
          while(e.hasMoreElements()) {
              Task t=(Task)e.nextElement();
              d=t.processor.process(d,this,t.parameters);
          }
          this.printer.print(d,this,out);
      }
  
      private class Task {
          public Processor processor=null;
          public Parameters parameters=null;
  
          public Task(Processor proc, Parameters param) {
              this.processor=proc;
              this.parameters=param;
          }
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/BasicParameters.java
  
  Index: BasicParameters.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.util.Enumeration;
  import java.util.Hashtable;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:05:15 $
   */
  public class BasicParameters implements Parameters {
      private Hashtable table=null;
  
      public BasicParameters() {
          super();
          this.table=new Hashtable();
      }
  
      /**
       * Retrieve a value for a specified parameter.
       *
       * @param name The parameter name.
       * @return The parameter value or null if the parameter has no specified
       *         value.
       */
      public String getParameter(String name) {
          return((String)this.table.get(name));
      }
  
      /**
       * Retrieve a value for a specified parameter.
       *
       * @param name The parameter name.
       * @param def The parameter default value.
       * @return The parameter value or def if the parameter has no specified
       *         value.
       */
      public String getParameter(String name, String def) {
          String val=getParameter(name);
          if (val==null) return(def);
          else return(val);
      }
  
      /**
       * Get all valid parameter names.
       *
       * @return A non-null (maybe empty) Enumeration.
       */
      public Enumeration getParameterNames() {
          return(table.keys());
      }
  
      /**
       * Set or update parameter value.
       *
       * @parameter name The parameter name.
       * @parameter value The parameter value.
       * @return The old value of the parameter or null.
       */
      public String setParameter(String name, String value) {
          if (value==null) return((String)this.table.remove(name));
          else return((String)this.table.put(name,value));
      }
  
      /**
       * Merge the values from another Parameters object into this instance.
       *
       * @param p The Parameters object from wich values must be retrieved.
       */
      public Parameters merge(Parameters p) {
          if (p==null) return(this);
          Enumeration e=p.getParameterNames();
          while (e.hasMoreElements()) {
              String name=(String)e.nextElement();
              String value=p.getParameter(name);
              this.setParameter(name,value);
          }
          return(this);
      }
  }
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/Component.java
  
  Index: Component.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:05:22 $
   */
  public interface Component {
      /**
       * Initialize this component instance.
       *
       * @param e The Engine owning this Component instance
       * @param p This component initialization Parameters
       * @exception InitializationException If this Component instance cannot be
       *                                    initialized.
       */
      public void init(Engine e, Parameters p)
      throws InitializationException;
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/ComponentFactory.java
  
  Index: ComponentFactory.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:05:27 $
   */
  public class ComponentFactory {
      /** Deny construction. */
      private ComponentFactory() {
          super();
      }
  
      /**
       * Create a new Component instance.
       *
       * @param classname The name of the Component class.
       * @return A non-null Component instance.
       * @exception InitializationException If the Component instance cannot be
       *                                    created.
       */
      public static Component getComponent(String classname)
      throws InitializationException {
          try {
              return ((Component)Class.forName(classname).newInstance());
          } catch (ClassCastException e) {
              throw new InitializationException("Class \""+classname+
                                                "\" is not a Component");
          } catch (InstantiationException e) {
              throw new InitializationException("Class \""+classname+
                                                "\" cannot be instantiated");
          } catch (IllegalAccessException e) {
              throw new InitializationException("Class \""+classname+
                                                "\" cannot be accessed");
          } catch (ClassNotFoundException e) {
              throw new InitializationException("Class \""+classname+
                                                "\" not found");
          }
      }
  
      /**
       * Create a new Parser instance.
       *
       * @param classname The name of the Parser class.
       * @return A non-null Parser instance.
       * @exception InitializationException If the Parser instance cannot be
       *                                    created.
       */
      public static Parser getParser(String classname)
      throws InitializationException {
          try {
              return ((Parser)getComponent(classname));
          } catch (ClassCastException e) {
              throw new InitializationException("Class \""+classname+
                                                "\" is not a Parser");
          }
      }
  
      /**
       * Create a new Producer instance.
       *
       * @param classname The name of the Producer class.
       * @return A non-null Producer instance.
       * @exception InitializationException If the Producer instance cannot be
       *                                    created.
       */
      public static Producer getProducer(String classname)
      throws InitializationException {
          try {
              return ((Producer)getComponent(classname));
          } catch (ClassCastException e) {
              throw new InitializationException("Class \""+classname+
                                                "\" is not a Producer");
          }
      }
  
      /**
       * Create a new Processor instance.
       *
       * @param classname The name of the Processor class.
       * @return A non-null Processor instance.
       * @exception InitializationException If the Processor instance cannot be
       *                                    created.
       */
      public static Processor getProcessor(String classname)
      throws InitializationException {
          try {
              return ((Processor)getComponent(classname));
          } catch (ClassCastException e) {
              throw new InitializationException("Class \""+classname+
                                                "\" is not a Processor");
          }
      }
  
      /**
       * Create a new Printer instance.
       *
       * @param classname The name of the Printer class.
       * @return A non-null Printer instance.
       * @exception InitializationException If the Printer instance cannot be
       *                                    created.
       */
      public static Printer getPrinter(String classname)
      throws InitializationException {
          try {
              return ((Printer)getComponent(classname));
          } catch (ClassCastException e) {
              throw new InitializationException("Class \""+classname+
                                                "\" is not a Printer");
          }
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/CreationContext.java
  
  Index: CreationContext.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.util.Enumeration;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:05:33 $
   */
  public interface CreationContext extends Parameters {
      public String getSourceName();
      public String getTargetName();
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/CreationException.java
  
  Index: CreationException.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import org.w3c.dom.Document;
  
  /**
   * A CreationException is thrown whenever an Entry cannot be produced for
   * any reason.
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:05:39 $
   */
  public class CreationException extends Exception {
      private transient Exception exception=null;
      private transient Document document=null;
  
      /**
       * Create a new CreationException instance.
       */
      public CreationException() {
          this(null,null,null);
      }
  
      /**
       * Create a new CreationException instance with a specified detail message.
       *
       * @param m The detail message.
       */
      public CreationException(String m) {
          this(m,null,null);
      }
  
      /**
       * Create a new CreationException instance with a specified nested
       * exception.
       *
       * @param e The nested exception.
       */
      public CreationException(Exception e) {
          this(null,e,null);
      }
  
      /**
       * Create a new CreationException instance with a specified invalid
       * document.
       *
       * @param d The invalid document.
       */
      public CreationException(Document d) {
          this(null,null,d);
      }
  
      /**
       * Create a new CreationException instance with a specified detail message
       * and a specified nested exception.
       *
       * @param m The detail message.
       * @param e The nested exception.
       */
      public CreationException(String m, Exception e) {
          this(m,e,null);
      }
  
      /**
       * Create a new CreationException instance with a specified detail message
       * and a specified invalid document.
       *
       * @param m The detail message.
       * @param d The invalid document.
       */
      public CreationException(String m, Document d) {
          this(m,null,d);
      }
  
      /**
       * Create a new CreationException instance with a specified nested
       * exception and a specified invalid document.
       *
       * @param e The nested exception.
       * @param d The invalid document.
       */
      public CreationException(Exception e, Document d) {
          this(null,e,d);
      }
  
      /**
       * Create a new CreationException instance with a specified detail message,
       * a specified nested exception and a specified invalid document.
       *
       * @param m The detail message.
       * @param e The nested exception.
       * @param d The invalid document.
       */
      public CreationException(String m, Exception e, Document d) {
          super(m);
          this.exception=e;
          this.document=d;
      }
  
      /**
       * Retrieve the nested exception of this CreationException.
       *
       * @return The invalid document or null if this wasn't specified.
       */
      public Exception getException() {
          return(this.exception);
      }
  
      /**
       * Retrieve the invalid document of this CreationException.
       *
       * @return The invalid document or null if this wasn't specified.
       */
      public Document getDocument() {
          return(this.document);
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/Engine.java
  
  Index: Engine.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.util.Enumeration;
  import org.w3c.dom.Document;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:05:44 $
   */
  public interface Engine {
      /**
       * Return the Parser instance owned by this Engine.
       *
       * @return A non-null Parser instance.
       */
      public Parser getParser();
  
      /**
       * Return a Producer instance associated with the specified name.
       *
       * @param name A non-null String representing the Producer name.
       * @return A non-null Producer instance or null if no Producer is associated
       *         with the specified name.
       */
      public Producer getProducer(String name);
  
      /**
       * Return a Processor instance associated with the specified name.
       *
       * @param name A non-null String representing the Processor name.
       * @return A non-null Processor instance or null if no Processor is
       *         associated with the specified name.
       */
      public Processor getProcessor(String name);
  
      /**
       * Return a Printer instance associated with the specified name.
       *
       * @param name A non-null String representing the Printer name.
       * @return A non-null Printer instance or null if no Printer is
       *         associated with the specified name.
       */
      public Printer getPrinter(String name);
  
      /**
       * Report a debug message to the user.
       *
       * @param msg The debug message to report.
       */
      public void debug(Object source, String message);
  
      /**
       * Report a log message to the user.
       *
       * @param msg The log message to report.
       */
      public void log(Object source, String message);
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/Entry.java
  
  Index: Entry.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.io.IOException;
  import java.io.OutputStream;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:05:48 $
   */
  public interface Entry {
      public void create(OutputStream out)
      throws IOException, CreationException;
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/InitializationException.java
  
  Index: InitializationException.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  /**
   * A InitializationException is thrown whenever a Component cannot be
   * initialized for any reason.
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:05:51 $
   */
  public class InitializationException extends Exception {
      /**
       * Create a new InitializationException instance.
       */
      public InitializationException() {
          super();
      }
  
      /**
       * Create a new InitializationException instance with a specified detail
       * message.
       *
       * @param m The detail message.
       */
      public InitializationException(String m) {
          super(m);
      }
  
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/Loader.java
  
  Index: Loader.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.io.IOException;
  import org.xml.sax.InputSource;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:05:56 $
   */
  public class Loader {
      private Engine engine=null;
  
      public Loader(Engine e) {
          this.engine=e;
      }
  
      public Project load(String loader, String project)
      throws LoadingException {
          try {
              // Parse the project file
              this.engine.log(this,"Parsing Project file");
              Document p=this.engine.getParser().parse(new InputSource(project));
              // Prepare a temporary creationcontext
              CreationContext c=new BasicContext(project,project);
              // Parse the loader configuration file
              this.engine.debug(this,"Parsing Loader configuration");
              Document d=this.engine.getParser().parse(new InputSource(loader));
              // Check the parsed loader configuration root element
              if (!d.getDocumentElement().getTagName().equals("loader"))
                  throw new LoadingException("Loader config is not <loader>");
              // Apply the different processors
              NodeList l=d.getDocumentElement().getChildNodes();
              for(int x=0;x<l.getLength();x++) {
                  if (l.item(x).getNodeType()!=Node.ELEMENT_NODE) continue;
                  p=process(p,(Element)l.item(x),c);
              }
              // Create the project
              Parameters param=new BasicParameters();
              param.setParameter("stylebook.project",project);
              Project pr=new Project(this.engine,p,param);
              return(pr);
          } catch (IOException e) {
              this.engine.log(this,"Caught "+e.getClass().getName());
              throw new LoadingException(e.getMessage());
          } catch (CreationException e) {
              this.engine.log(this,"Caught "+e.getClass().getName());
              throw new LoadingException(e.getMessage());
          }
      }
  
      private Document process(Document d, Element e, CreationContext c)
      throws IOException, CreationException, LoadingException {
          if(!e.getTagName().equals("processor"))
              throw new LoadingException("Unknown element <"+e.getTagName()+">");
          String name=e.getAttribute("name");
          d=this.engine.getProcessor(name).process(d,c,new BasicParameters());
          return(d);
      }
  }
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/LoadingException.java
  
  Index: LoadingException.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  /**
   * A LoadingException is thrown whenever the Loaded cannot load and create a
   * project.
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:05:59 $
   */
  public class LoadingException extends Exception {
      /**
       * Create a new LoadingException instance.
       */
      public LoadingException() {
          super();
      }
  
      /**
       * Create a new LoadingException instance with a specified detail
       * message.
       *
       * @param m The detail message.
       */
      public LoadingException(String m) {
          super(m);
      }
  
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/Logger.java
  
  Index: Logger.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:06:03 $
   */
  public interface Logger {
      /**
       * Report a message to the user.
       *
       * @param msg The log message to report.
       */
      public void log(Object source, String message);
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/NodeListParameters.java
  
  Index: NodeListParameters.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.util.Enumeration;
  import java.util.Hashtable;
  import org.w3c.dom.Element;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:06:07 $
   */
  public class NodeListParameters extends BasicParameters implements Parameters {
  
      public NodeListParameters(NodeList l) {
          super();
          if (l!=null) for (int x=0; x<l.getLength(); x++) {
              if (l.item(x).getNodeType()!=Node.ELEMENT_NODE) continue;
              Element e=(Element)l.item(x);
              if (!e.getTagName().equals("parameter")) continue;
              this.setParameter(e.getAttribute("name"),e.getAttribute("value"));
          }
      }
  }
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/Parameters.java
  
  Index: Parameters.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.util.Enumeration;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:06:09 $
   */
  public interface Parameters {
      /**
       * Retrieve a value for a specified parameter.
       *
       * @param name The parameter name.
       * @return The parameter value or null if the parameter has no specified
       *         value.
       */
      public String getParameter(String name);
  
      /**
       * Retrieve a value for a specified parameter.
       *
       * @param name The parameter name.
       * @param def The parameter default value.
       * @return The parameter value or def if the parameter has no specified
       *         value.
       */
      public String getParameter(String name, String def);
  
      /**
       * Get all valid parameter names.
       *
       * @return A non-null (maybe empty) Enumeration.
       */
      public Enumeration getParameterNames();
  
      /**
       * Set or update parameter value.
       *
       * @parameter name The parameter name.
       * @parameter value The parameter value.
       * @return The old value of the parameter or null.
       */
      public String setParameter(String name, String value);
  
      /**
       * Merge the values from another Parameters object into this instance.
       *
       * @param p The Parameters object from wich values must be retrieved.
       */
      public Parameters merge(Parameters p);
  }
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/Parser.java
  
  Index: Parser.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.io.IOException;
  import org.w3c.dom.Document;
  import org.xml.sax.InputSource;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:06:12 $
   */
  public interface Parser extends Component{
      /**
       * Parse the specified InputSource.
       *
       * @param in The InputSource to parse.
       * @return A non-null DOM Document object.
       * @exception IOException If an I/O error occourred accessing the specified
       *                        System-ID.
       * @exception CreationException If an error occourred parsing the document.
       */
      public Document parse(InputSource in)
      throws IOException, CreationException;
  
      /**
       * Create a new empty DOM Document object.
       *
       * @return A non-null DOM Document object.
       */
      public Document create();
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/Printer.java
  
  Index: Printer.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.io.IOException;
  import java.io.OutputStream;
  import org.w3c.dom.Document;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:06:14 $
   */
  public interface Printer extends Component {
      public void print(Document doc, CreationContext c, OutputStream out)
      throws CreationException, IOException;
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/Processor.java
  
  Index: Processor.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.io.IOException;
  import org.w3c.dom.Document;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:06:18 $
   */
  public interface Processor extends Component {
      public Document process(Document doc, CreationContext c, Parameters p)
      throws CreationException, IOException;
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/Producer.java
  
  Index: Producer.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.io.IOException;
  import org.w3c.dom.Document;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:06:24 $
   */
  public interface Producer extends Component{
      public Document produce(CreationContext c)
      throws CreationException, IOException;
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/Project.java
  
  Index: Project.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.io.IOException;
  import java.io.OutputStream;
  import java.util.Enumeration;
  import java.util.Hashtable;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:06:28 $
   */
  public class Project {
      private Hashtable entries=new Hashtable();
      private Engine engine=null;
  
      public Project(Engine engine, Document project, Parameters parambase)
      throws LoadingException {
          this.engine=engine;
          Element root=project.getDocumentElement();
          if(!root.getTagName().equals("project"))
              throw new LoadingException("Project does not start with <project>");
          NodeList l=root.getChildNodes();
          Parameters parameters=new NodeListParameters(l);
          parameters.merge(parambase);
          for(int x=0;x<l.getLength();x++) {
              if(l.item(x).getNodeType()!=Node.ELEMENT_NODE) continue;
              Element e=(Element)l.item(x);
              String name=e.getTagName();
              if(name.equals("create")) setCreateEntry(e,parameters);
              else if(name.equals("resource")) setResourceEntry(e);
              else throw new LoadingException("Invalid element <"+name+">");
          }
      }
  
      public Enumeration getEntryNames() {
          return(this.entries.keys());
      }
  
      public void create(String name, OutputStream out)
      throws IOException, CreationException {
          this.engine.log(this,"Creating \""+name+"\"");
          Entry e=(Entry)this.entries.get(name);
          if(e==null) throw new CreationException("No Entry \""+name+"\"");
          e.create(out);
      }
  
      private void setCreateEntry(Element e, Parameters parambase)
      throws LoadingException {
          String sourcebase=e.getAttribute("source");
          String targetbase=e.getAttribute("target");
          RegExpHandler r=new RegExpHandler();
          try {
              r.match(sourcebase);
          } catch (IllegalArgumentException x) {
              throw new LoadingException("Performing RegExp "+x.getMessage());
          } catch (IOException x) {
              throw new LoadingException("IOException performing RegExp");
          }
          Enumeration sourcelist=r.expand(sourcebase);
          Enumeration targetlist=r.expand(targetbase);
          while(sourcelist.hasMoreElements()) {
              String source=(String)sourcelist.nextElement();
              String target=(String)targetlist.nextElement();
              Entry entry=new BasicEntry(this.engine,source,target,e,parambase);
              if(this.entries.put(target,entry)!=null)
                  throw new LoadingException("Duplicate Entry \""+target+"\"");
          }
      }
  
      private void setResourceEntry(Element e)
      throws LoadingException {
          String sourcebase=e.getAttribute("source");
          String targetbase=e.getAttribute("target");
          RegExpHandler r=new RegExpHandler();
          try {
              r.match(sourcebase);
          } catch (IllegalArgumentException x) {
              throw new LoadingException("Performing RegExp "+x.getMessage());
          } catch (IOException x) {
              throw new LoadingException("IOException performing RegExp");
          }
          Enumeration sourcelist=r.expand(sourcebase);
          Enumeration targetlist=r.expand(targetbase);
          while(sourcelist.hasMoreElements()) {
              String source=(String)sourcelist.nextElement();
              String target=(String)targetlist.nextElement();
              Entry entry=new ResourceEntry(source);
              if(this.entries.put(target,entry)!=null)
                  throw new LoadingException("Duplicate Entry \""+target+"\"");
          }
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/RegExpHandler.java
  
  Index: RegExpHandler.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.io.File;
  import java.io.IOException;
  import java.util.Enumeration;
  import java.util.Vector;
  
  /**
   * The regular expression handler expands a pattern string into a list of String
   * object that can be expanded from it.
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:06:30 $
   */
  public class RegExpHandler {
      private File base=null;
      private Vector data=null;
  
      /**
       *
       */
      public RegExpHandler() {
          this(System.getProperty("user.dir"));
      }
  
      /**
       *
       */
      public RegExpHandler(String path) {
          super();
          this.base=new File(path);
      }
  
      /**
       * Specify the pattern to match and that need to be expanded.
       *
       * @param pattern A non null string.
       * @exception IllegalArgumentException In case the pattern is invalid.
       */
      public void match(String pattern)
      throws IOException {
          // Check for the * character
          int pos=pattern.indexOf('*');
          if (pos<0) {
              this.data=new Vector();
              this.data.add("");
              return;
          }
          if (pattern.indexOf('*',pos+1)>0)
              throw new IllegalArgumentException("Multiple '*' char in pattern");
          // Split the string in two parts
          String prefix=pattern.substring(0,pos);
          String suffix=pattern.substring(pos+1);
          // Update the base path
          pos=prefix.lastIndexOf(File.separatorChar);
          if(prefix.lastIndexOf('/')>pos) pos=prefix.lastIndexOf('/');
          if(pos>=0) this.base=new File(base,prefix.substring(0,pos));
          this.base=this.base.getCanonicalFile();
          prefix=prefix.substring(pos+1);
          // Check for the existance of the base path
          if(!this.base.isDirectory())
              throw new IOException("Directory \""+this.base+"\" not found.");
          // List all files in the base path and
          int preflen=prefix.length();
          int sufflen=suffix.length();
          this.data=new Vector();
          String list[]=this.base.list();
          for (int x=0;x<list.length;x++) {
              String item=list[x];
              if ((item.startsWith(prefix))&&(item.endsWith(suffix))) {
                  int itemlen=item.length();
                  this.data.add(item.substring(preflen,itemlen-sufflen));
              }
          }
      }
  
      /**
       * Expand the given string.
       *
       * @param pattern A non null string.
       */
      public Enumeration expand(String pattern) {
          Vector val=new Vector(this.data.size());
          // Check for the * character
          int pos=pattern.indexOf('*');
          if (pos<0)
              for(int x=0;x<this.data.size();x++) val.add(pattern);
          else if (pattern.indexOf('*',pos+1)>0)
              throw new IllegalArgumentException("Multiple '*' char in pattern");
          else {
              String prefix=pattern.substring(0,pos);
              String suffix=pattern.substring(pos+1);
              Enumeration e=this.data.elements();
              while (e.hasMoreElements())
                  val.add(new String(prefix+e.nextElement()+suffix));
          }
          return(val.elements());
      }
  
      public static void main(String argv[])
      throws IOException {
          RegExpHandler f=new RegExpHandler(argv[0]);
          f.match(argv[1]);
          Enumeration e=f.expand(argv[1]);
          while(e.hasMoreElements()) {
              System.out.println(e.nextElement());
          }
          System.out.println();
          e=f.expand("my.*.asdf");
          while(e.hasMoreElements()) {
              System.out.println(e.nextElement());
          }
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/ResourceEntry.java
  
  Index: ResourceEntry.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.io.IOException;
  import java.io.BufferedInputStream;
  import java.io.BufferedOutputStream;
  import java.io.FileInputStream;
  import java.io.InputStream;
  import java.io.OutputStream;
  
  /**
   * 
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:06:36 $
   */
  public class ResourceEntry implements Entry {
      private String src=null;
  
      public ResourceEntry(String src) {
          this.src=src;
      }
  
      public void create(OutputStream o)
      throws IOException, CreationException {
          InputStream in=new BufferedInputStream(new FileInputStream(this.src));
          OutputStream out=new BufferedOutputStream(o);
          int data=-1;
          while((data=in.read())!=-1) out.write(data);
          in.close();
          out.flush();
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/StreamHandler.java
  
  Index: StreamHandler.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.OutputStream;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:06:39 $
   */
  public class StreamHandler {
      private File base=null;
  
      public StreamHandler(String base) throws IOException {
          if(base==null) base=System.getProperty("user.dir");
          this.base=new File(base).getCanonicalFile();
          if(!this.base.isDirectory()) {
              mkdir(this.base);
          }
      }
  
      public OutputStream getOutputStream(String name)
      throws IOException {
          File f=new File(name);
          if (f.isAbsolute()) return new FileOutputStream(f);
          if (f.getParent()!=null) mkdir(new File(base,f.getParent()));
          return(new FileOutputStream(new File(base,name)));
      }
  
      private void mkdir(File file)
      throws IOException {
          if (file==null) return;
          mkdir(file.getParentFile());
          if (file.isDirectory()) return;
          else file.mkdir();
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/StyleBook.java
  
  Index: StyleBook.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook;
  
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.io.IOException;
  import java.net.URL;
  import java.util.Enumeration;
  import java.util.Properties;
  
  /**
   * 
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:06:43 $
   */
  public class StyleBook implements Logger {
      /** The file on wich we must operate */
      private String project=null;
      /** Our properties */
      private Properties properties=null;
      /** The properties file */
      private String propertiesfile="org/apache/stylebook/stylebook.properties";
      /** Deny construction */
      private StyleBook() {}
  
      /** Create the StyleBook object */
      private StyleBook(String argv[])
      throws IOException {
          super();
          this.properties=new Properties();
          ClassLoader loader=this.getClass().getClassLoader();
          InputStream in=loader.getResourceAsStream(propertiesfile);
          this.properties.load(in);
          for(int x=0;x<argv.length;x++) {
              String line=argv[x];
              int pos=line.indexOf('=');
              if (pos<0) {
                  if(this.project!=null) exit("Duplicate Project (\""+
                                              this.project+"\",\""+line+"\")",1);
                  else project=line;
              } else {
                  String name=line.substring(0,pos);
                  String value=line.substring(pos+1);
                  String old=(String)this.properties.setProperty(name,value);
                  log("Overriding "+name+"=\""+value+"\" (Old=\""+old+"\")");
              }
          }
          if(this.project==null) exit("Project file non specified",1);
      }
  
      /**
       * Run StyleBook.
       *
       * @param argv Command Line Arguments
       */
      public static void main(String argv[]) throws IOException{
          try {
              StyleBook sb=new StyleBook(argv);
              Engine e=sb.getEngine();
              if (e==null) exit("Error creating engine",3);
              Project p=sb.getProject(e);
              if (p==null) exit("Error creating project",3);
              StreamHandler s=new StreamHandler(sb.properties.getProperty("target.dir"));
              Enumeration n=p.getEntryNames();
              while (n.hasMoreElements()) {
                  String t=(String)n.nextElement();
                  p.create(t,s.getOutputStream(t));
              }
          } catch (CreationException x) {
              Exception x2=x.getException();
              if(x2!=null) log(x2);
              exit(x,255);
          }
          exit("All done successfully",0);
      }
  
      /** Create and Initialize Engine */
      private Engine getEngine() {
          try {
              String parser=properties.getProperty("parser.class");
              String config=properties.getProperty("engine.conf");
              if (config.startsWith("resource:///")) {
                  config=config.substring(12);
                  URL configURL=getClass().getClassLoader().getResource(config);
                  if (configURL==null) {
                      log("Cannot find Engine config file \"res:"+config+"\"");
                      return(null);
                  } else config=configURL.toString();
              }
              return(new BasicEngine(parser,config,this));
          } catch (InitializationException e) {
              log(e);
              return(null);
          }
      }
  
      /** Create and Initialize Project */
      private Project getProject(Engine e) {
          try {
              Loader l=new Loader(e);
              String config=properties.getProperty("loader.conf");
              if (config.startsWith("resource:///")) {
                  config=config.substring(12);
                  URL configURL=getClass().getClassLoader().getResource(config);
                  if (configURL==null) {
                      log("Cannot find Loader config file \"res:"+config+"\"");
                      return(null);
                  } else config=configURL.toString();
              }
              return(l.load(config,project));
          } catch (LoadingException x) {
              log(x);
              return(null);
          }
      }
  
  /* ************************************************************************** */
  
      /**
       * Report a message to the user.
       *
       * @param msg The log message to report.
       */
      public void log(Object source, String msg) {
          String cls=source.getClass().getName();
          cls=cls.substring(cls.lastIndexOf('.')+1);
          System.out.println("["+cls+"] "+msg);
      }
  
      /** Report a message thru System.out */
      private static void log(String msg) {
          System.out.println("[StyleBook] "+msg);
      }
  
      /** Report an exception thru System.out */
      private static void log(Exception e) {
          log("Caught "+e.getClass().getName());
          e.printStackTrace(System.out);
      }
  
      /** Report a message and exit with the specified error number */
      private static void exit(String msg, int exit) {
          log(msg);
          System.exit(exit);
      }
  
      /** Report an exception and exit with the specified error number */
      private static void exit(Exception e, int exit) {
          log(e);
          System.exit(exit);
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/engine.conf.xml
  
  Index: engine.conf.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <!-- CVS $Revision: 1.1 $ $Date: 1999/11/15 22:06:51 $ -->
  
  <engine>
    <debug enabled="true"/>
  
    <parser class="org.apache.stylebook.parsers.CachingParser">
      <parameter name="parserclass" value="org.apache.stylebook.parsers.XercesParser"/>
      <parameter name="cachesize" value="10"/>
    </parser>
  
    <producer name="parser" class="org.apache.stylebook.producers.ParserProducer"/>
    <producer name="context" class="org.apache.stylebook.producers.ContextProducer"/>
    <producer name="project" class="org.apache.stylebook.producers.ProjectProducer"/>
  
    <processor name="null" class="org.apache.stylebook.processors.NullProcessor"/>
    <processor name="xslt" class="org.apache.stylebook.processors.XalanProcessor"/>
    <processor name="import" class="org.apache.stylebook.processors.ImportProcessor"/>
  
    <printer name="xml" class="org.apache.stylebook.printers.XMLPrinter"/>
    <printer name="html" class="org.apache.stylebook.printers.HTMLPrinter"/>
    <printer name="image" class="org.apache.stylebook.printers.ImagePrinter"/>
  </engine>
  
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/loader.conf.xml
  
  Index: loader.conf.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <!-- CVS $Revision: 1.1 $ $Date: 1999/11/15 22:06:56 $ -->
  
  <loader>
      <processor name="xslt"/>
  </loader>
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/stylebook.properties
  
  Index: stylebook.properties
  ===================================================================
  # CVS $Revision: 1.1 $ $Date: 1999/11/15 22:07:01 $
  
  parser.class=org.apache.stylebook.parsers.XercesParser
  target.dir=.
  engine.conf=resource:///org/apache/stylebook/engine.conf.xml
  loader.conf=resource:///org/apache/stylebook/loader.conf.xml
  
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/parsers/CachingParser.java
  
  Index: CachingParser.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook.parsers;
  
  import org.apache.stylebook.*;
  import java.io.IOException;
  import java.util.Enumeration;
  import java.util.Hashtable;
  import org.xml.sax.InputSource;
  import org.w3c.dom.Document;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:07:40 $
   */
  public class CachingParser extends AbstractComponent implements Parser {
      private Parser parser=null;
      private int cachesize=10;
      private Hashtable cache=new Hashtable();
  
      /**
       * Initialize this component instance.
       *
       * @param e The Engine owning this Component instance
       * @param p This component initialization Parameters
       */
      public void init(Engine e, Parameters p)
      throws InitializationException {
          super.init(e,p);
          // Instantiate the sub-parser
          String cls=p.getParameter("parserclass");
          if (cls==null)
              throw new InitializationException("Parameter \"parserclass\" not "+
                                                "specified");
          this.parser=ComponentFactory.getParser(cls);
          // Create the parameters for the sub-parser
          Parameters p2=new BasicParameters();
          Enumeration n=p.getParameterNames();
          while(n.hasMoreElements()) {
              String name=(String)n.nextElement();
              String value=p.getParameter(name);
              if(!name.startsWith("parser.")) continue;
              name=name.substring(7);
              p2.setParameter(name,value);
          }
          // Initialize the sub-parser
          this.parser.init(e,p2);
          // Set up the cache size
          try {
              this.cachesize=Integer.parseInt(p.getParameter("cachesize"));
          } catch (Exception x) {
              debug("Cache size not specified (default=10)");
              this.cachesize=10;
          }
      }
  
      /**
       * Create a new empty DOM Document object.
       *
       * @return A non-null DOM Document object.
       * @exception DocumentException If the new Document cannot be created.
       */
      public Document create() {
          return(this.parser.create());
      }
  
      /**
       * Parse the specified InputSource.
       *
       * @param in The InputSource to parse.
       * @return A non-null DOM Document object.
       * @exception IOException If an I/O error occourred accessing the specified
       *                        System-ID.
       * @exception CreationException If an error occourred parsing the document.
       */
      public Document parse(InputSource in)
      throws IOException, CreationException {
          String name=in.getSystemId();
          if (name==null) return(this.parser.parse(in));
          CachedEntry ent=(CachedEntry)this.cache.get(name);
          Document doc=null;
          if (ent==null) {
              doc=this.parser.parse(in);
              ent=new CachedEntry(doc);
              this.cache.put(name,ent);
          } else {
              ent.hits++;
              doc=ent.document;
              if (doc==null) doc=this.parser.parse(in);
              else log("Serving cached document \""+name+"\" ("+ent.hits+")");
              ent.document=doc;
          }
          purge();
          return(doc);
      }
  
      private void purge() {
          // Cache purging algorithm...
      }
  
      private class CachedEntry {
          public Document document=null;
          public int hits=0;
  
          public CachedEntry(Document doc) {
              this.document=doc;
          }
      }
  }
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/parsers/XML4JParser.java
  
  Index: XML4JParser.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook.parsers;
  
  import java.io.IOException;
  import org.apache.stylebook.AbstractComponent;
  import org.apache.stylebook.Parser;
  import org.apache.stylebook.CreationException;
  import com.ibm.xml.dom.DocumentImpl;
  import com.ibm.xml.parsers.DOMParser;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  import org.w3c.dom.Document;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:07:42 $
   */
  public class XML4JParser extends AbstractComponent implements Parser {
      /**
       * Parse the specified InputSource.
       *
       * @param in The InputSource to parse.
       * @return A non-null DOM Document object.
       * @exception IOException If an I/O error occourred accessing the specified
       *                        System-ID.
       * @exception CreationException If an error occourred parsing the document.
       */
      public Document parse(InputSource in)
      throws IOException, CreationException {
          this.debug("Parsing \""+in.getSystemId()+"\"");
          try {
              DOMParser parser=new DOMParser();
              parser.parse(in);
              Document document=parser.getDocument();
              if (document==null) {
                  throw new CreationException("Cannot retrieve parsed document");
              } else return(document);
          } catch (SAXException e) {
              Exception e2=e.getException();
              if(e2!=null) this.log(e2.getMessage());
              this.log(e.getMessage());
              throw new CreationException("SAXException caught while parsing",e);
          }
      }
  
      /**
       * Create a new empty DOM Document object.
       *
       * @return A non-null DOM Document object.
       * @exception DocumentException If the new Document cannot be created.
       */
      public Document create() {
          this.debug("Creating new Document");
          return new DocumentImpl();
      }
  }
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/parsers/XercesParser.java
  
  Index: XercesParser.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook.parsers;
  
  import java.io.IOException;
  import org.apache.stylebook.AbstractComponent;
  import org.apache.stylebook.Parser;
  import org.apache.stylebook.CreationException;
  import org.apache.xml.dom.DocumentImpl;
  import org.apache.xml.parsers.DOMParser;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  import org.w3c.dom.Document;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:07:44 $
   */
  public class XercesParser extends AbstractComponent implements Parser {
      /**
       * Parse the specified InputSource.
       *
       * @param in The InputSource to parse.
       * @return A non-null DOM Document object.
       * @exception IOException If an I/O error occourred accessing the specified
       *                        System-ID.
       * @exception CreationException If an error occourred parsing the document.
       */
      public Document parse(InputSource in)
      throws IOException, CreationException {
          this.debug("Parsing \""+in.getSystemId()+"\"");
          try {
              DOMParser parser=new DOMParser();
              parser.setFeature("http://xml.org/sax/features/validation",true);
              parser.setFeature("http://ibm.com/xml/features/validation/dynamic",
                                true);
              parser.parse(in);
              Document document=parser.getDocument();
              if (document==null) {
                  throw new CreationException("Cannot retrieve parsed document");
              } else return(document);
          } catch (SAXException e) {
              this.log(e.getMessage());
              throw new CreationException("SAXException caught while parsing",e);
          }
      }
  
      /**
       * Create a new empty DOM Document object.
       *
       * @return A non-null DOM Document object.
       * @exception DocumentException If the new Document cannot be created.
       */
      public Document create() {
          this.debug("Creating new Document");
          return new DocumentImpl();
      }
  }
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/printers/HTMLPrinter.java
  
  Index: HTMLPrinter.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook.printers;
  
  import org.apache.stylebook.*;
  import java.io.IOException;
  import java.io.OutputStream;
  import java.io.PrintStream;
  import org.w3c.dom.Attr;
  import org.w3c.dom.CDATASection;
  import org.w3c.dom.Comment;
  import org.w3c.dom.Document;
  import org.w3c.dom.DocumentFragment;
  import org.w3c.dom.DocumentType;
  import org.w3c.dom.Element;
  import org.w3c.dom.Entity;
  import org.w3c.dom.EntityReference;
  import org.w3c.dom.NamedNodeMap;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.Notation;
  import org.w3c.dom.ProcessingInstruction;
  import org.w3c.dom.Text;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:07:49 $
   */
  public class HTMLPrinter extends AbstractComponent implements Printer {
  
      /**
       * Print a DOM Document.
       *
       * @param doc The Document to print.
       * @param out The OutputStream used for printing.
       * @param env The Environment of this printing request.
       * @exception IOException If an I/O error occourred accessing resources.
       * @exception CreationException If the Document cannot be printed.
       */
      public void print(Document doc, CreationContext c, OutputStream out)
      throws CreationException, IOException {
          printDocument(doc,new PrintStream(out));
      }
  
      /** Process a nodelist calling the appropriate print...() method. */
      private void printNodeList(NodeList list, PrintStream out,int indent) {
          for (int x=0;x<list.getLength();x++) {
              Node node=list.item(x);
              switch (node.getNodeType()) {
                  case Node.ATTRIBUTE_NODE:
                      printAttribute((Attr)node,out);
                      break;
                  case Node.CDATA_SECTION_NODE:
                      printCDATASection((CDATASection)node,out);
                      break;
                  case Node.COMMENT_NODE:
                      printComment((Comment)node,out);
                      break;
                  case Node.DOCUMENT_FRAGMENT_NODE:
                      printDocumentFragment((DocumentFragment)node,out);
                      break;
                  case Node.DOCUMENT_NODE:
                      printDocument((Document)node,out);
                      break;
                  case Node.DOCUMENT_TYPE_NODE:
                      printDocumentType((DocumentType)node,out);
                      break;
                  case Node.ELEMENT_NODE:
                      printElement((Element)node,out,indent);
                      break;
                  case Node.ENTITY_NODE:
                      printEntity((Entity)node,out);
                      break;
                  case Node.ENTITY_REFERENCE_NODE:
                      printEntityReference((EntityReference)node,out);
                      break;
                  case Node.NOTATION_NODE:
                      printNotation((Notation)node,out);
                      break;
                  case Node.PROCESSING_INSTRUCTION_NODE:
                      printProcessingInstruction((ProcessingInstruction)node,out);
                      break;
                  case Node.TEXT_NODE:
                      printText((Text)node,out);
                      break;
              }
          }
      }
  
      /** Print an ATTRIBUTE (name="value") node. */
      private void printAttribute(Attr node, PrintStream out) {
          out.print(node.getName()+"=\""+node.getValue()+"\"");
      }
  
      /** Print a CDATA (<[CDATA[ ... ]]>) node. */
      private void printCDATASection(CDATASection node, PrintStream out) {
          String data=node.getData();
          out.print("<!-- CDATA -->");
          for (int x=0; x<data.length(); x++) {
              char c=data.charAt(x);
              if (c=='<') out.print("&lt;");
              else if (c=='>') out.print("&gt;");
              else if (c=='\n') out.println("");
              else out.print(c);
          }
          out.print("<!-- CDATA ends -->");
      }
  
      /** Print a COMMENT (<!-- ... -->) node. */
      private void printComment(Comment node, PrintStream out) {
          out.print("<!--"+node.getData()+"-->");
      }
  
      /** Print a DOCUMENT FRAGMENT (????) node. */
      private void printDocumentFragment(DocumentFragment node, PrintStream out) {
          out.print("<!-- Document Fragment Node -->");
      }
  
      /** Print a DOCUMENT node. */
      private void printDocument(Document node, PrintStream out) {
          printNodeList(node.getChildNodes(),out,0);
      }
  
      /** Print a DOCUMENT TYPE (<!DOCTYPE ... bla bla bla>) node. */
      private void printDocumentType(DocumentType node, PrintStream out) {
          out.print("<!-- DOCTYPE "+node.getName()+" -->");
          // Should we insert ENTITIES and NOTATIONS?
      }
  
      /** Print a ELEMENT (do I need to supply the example ??? :) node. */
      private void printElement(Element node, PrintStream out, int indent) {
          if(!node.getTagName().equalsIgnoreCase("br")) {
              if (indent>0) out.println();
              for(int x=0;x<indent;x++) out.print(' ');
          }
          out.print("<"+node.getTagName());
          // Process attributes
          NamedNodeMap atts=node.getAttributes();
          if ((null!=atts) && (atts.getLength()>0)) {
              for (int x=0; x<atts.getLength(); x++) {
                  out.print(' ');
                  printAttribute((Attr)atts.item(x),out);
              }
          }
          // Process child nodes
          if ((null!=node.getChildNodes()) &&
                  (node.getChildNodes().getLength()>0)) {
              out.print(">");
              printNodeList(node.getChildNodes(),out,indent+1);
              out.print("</"+node.getTagName()+">");
          } else {
              out.print(">");
          }
      }
  
      /** Print a ENTITY node (NOTE: This should be used with DOCTYPE). */
      private void printEntity(Entity node, PrintStream out) {
          out.print("<!-- Entity Node -->");
      }
  
      /** Print a ENTITY REFERENCE node (NOTE: Again, used in within DOCTYPE). */
      private void printEntityReference(EntityReference node, PrintStream out) {
          out.print("<!-- Entity Reference Node -->");
      }
  
      /** Print a NOTATION node (NOTE: Again -3rd-, used in within DOCTYPE). */
      private void printNotation(Notation node, PrintStream out) {
          out.print("<!-- Notation Node -->");
      }
  
      /** Print a PROCESSING INSTRUCTION (<?name ...?>) node. */
      private void printProcessingInstruction(ProcessingInstruction node, PrintStream out) {
          out.print("<!-- PI:"+node.getTarget()+" "+node.getData()+"-->");
      }
  
      /** Print a TEXT (see example for ELEMENT) node. */
      private void printText(Text node, PrintStream out) {
          String data=node.getData();
          if (data.trim().length()<=0) return;
          for (int x=0; x<data.length(); x++) {
              char c=data.charAt(x);
              if (c=='<') out.print("&lt;");
              else if (c=='>') out.print("&gt;");
              else if (c=='\n') out.println("");
              else out.print(c);
          }
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/printers/ImagePrinter.java
  
  Index: ImagePrinter.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook.printers;
  
  import org.apache.stylebook.*;
  import com.sun.image.codec.jpeg.*;
  import java.io.IOException;
  import java.io.OutputStream;
  import java.io.PrintStream;
  import java.awt.*;
  import java.awt.geom.AffineTransform;
  import java.awt.image.*;
  import java.util.*;
  import javax.swing.*;
  import org.w3c.dom.Attr;
  import org.w3c.dom.CDATASection;
  import org.w3c.dom.Comment;
  import org.w3c.dom.Document;
  import org.w3c.dom.DocumentFragment;
  import org.w3c.dom.DocumentType;
  import org.w3c.dom.Element;
  import org.w3c.dom.Entity;
  import org.w3c.dom.EntityReference;
  import org.w3c.dom.NamedNodeMap;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.Notation;
  import org.w3c.dom.ProcessingInstruction;
  import org.w3c.dom.Text;
  
  /**
   * The ImagePrinter Printer writes images.
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:07:55 $
   */
  public class ImagePrinter extends AbstractComponent implements Printer {
  
      int R=0;
      int G=1;
      int B=2;
      int A=3;
  
      /**
       * Print a DOM Document.
       *
       * @param doc The Document to print.
       * @param out The OutputStream used for printing.
       * @param env The Environment of this printing request.
       * @exception IOException If an I/O error occourred accessing resources.
       * @exception CreationException If the Document cannot be printed.
       */
      public void print(Document doc, CreationContext ctx, OutputStream out)
      throws CreationException, IOException {
          // Check for proper root element
          Element element=doc.getDocumentElement();
          if (!element.getTagName().equals("image")) {
              throw new CreationException("Invalid document supplied",doc);
          }
          // Check wether we have a source image
          String source=element.getAttribute("source");
          BufferedImage img=null;
          Graphics2D gr=null;
          // If we have a source image, this is taken as our source.
          if (source.length()>0) {
              ImageIcon ico=new ImageIcon(source);
              if ((ico.getIconWidth()<1) | (ico.getIconHeight()<1)) {
                  throw new CreationException("Cannot load image \""+source+"\"");
              }
              img=new BufferedImage(ico.getIconWidth(), ico.getIconHeight(),
                                    BufferedImage.TYPE_INT_RGB);
              gr=img.createGraphics();
              gr.drawImage(ico.getImage(),0,0,ico.getImageObserver());
          } else {
              // We don't have a source image. Build up a new getting height and
              // width from attributes
              int w=0;
              int h=0;
              try {
                  String width=element.getAttribute("width");
                  String height=element.getAttribute("height");
                  w=Integer.parseInt(width);
                  h=Integer.parseInt(height);
              } catch (NumberFormatException e) {
                  throw new CreationException("Image witdth or height error");
              }
              if ((w<1) | (h<1)) {
                  throw new CreationException("Image witdth or height unspecified");
              }
              img=new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
              gr=img.createGraphics();
              // Now process the bgcolor attribute for background colorization
              int bg=0;
              try {
                  String bgcolor=element.getAttribute("bgcolor");
                  bg=Integer.parseInt(bgcolor,16);
              } catch (NumberFormatException e) {
                  throw new CreationException("Background color error");
              }
              Color c=new Color(bg);
              gr.setBackground(c);
              gr.clearRect(0,0,w,h);
              // Check if we have a background to tile
              String background=element.getAttribute("background");
              if (background.length()>0) {
                  // We have a background image. Load it.
                  ImageIcon ico=new ImageIcon(background);
                  if ((ico.getIconWidth()<1) | (ico.getIconHeight()<1)) {
                      throw new CreationException("Cannot load background \""+source+"\"");
                  }
                  // Tile the image.
                  int x=0;
                  int y=0;
                  while (true) {
                      gr.drawImage(ico.getImage(),x,y,ico.getImageObserver());
                      x+=ico.getIconWidth();
                      if (x>w) {
                          x=0;
                          y+=ico.getIconHeight();
                      }
                      if (y>h) break;
                  }
              }
          }
  
          // Process child elements
          NodeList l=element.getChildNodes();
          for (int x=0;x<l.getLength();x++) {
              if (l.item(x).getNodeType()==Node.ELEMENT_NODE) {
                  processElement((Element)l.item(x),img);
              }
          }
  
          // Write out image (highest quality for jpeg data)
          JPEGEncodeParam jpar=JPEGCodec.getDefaultJPEGEncodeParam(img);
          jpar.setQuality(1,true);
          JPEGImageEncoder jenc=JPEGCodec.createJPEGEncoder(out,jpar);
          jenc.encode(img);
          out.flush();
      }
  
      void processElement(Element e, BufferedImage i)
      throws CreationException {
          if (e==null) return;
          int R=0; int G=1; int B=2; int A=3;
          // Create new alpha image
          int w=i.getWidth();
          int h=i.getHeight();
          BufferedImage n=new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB);
          // Clear new alpha image
          int np[]=new int[]{0,0,0,0};
          WritableRaster nr=n.getRaster();
          for (int x=0;x<nr.getWidth();x++) for (int y=10;y<nr.getHeight();y++) {
              nr.setPixel(x,y,np);
          }
          // Check wich element is being processed.
          boolean ret=false;
          if (e.getTagName().equals("text")) ret=placeText(e,n);
          if(!ret) return;
          // Apply new image over existing
          WritableRaster ir=i.getRaster();
          int ip[]=new int[]{0,0,0,0};
          double ia=0;
          double na=1;
          for (int x=0;x<ir.getWidth();x++) for (int y=0;y<ir.getHeight();y++) {
              ir.getPixel(x,y,ip);
              nr.getPixel(x,y,np);
              if (np[A]>0) {
                  na=((double)np[A]/255);
                  ia=(1-na);
                  ip[R]=(int)(((double)ip[R]*ia) + ((double)np[R]*na));
                  ip[G]=(int)(((double)ip[G]*ia) + ((double)np[G]*na));;
                  ip[B]=(int)(((double)ip[B]*ia) + ((double)np[B]*na));;
              }
              ir.setPixel(x,y,ip);
          }
      }
  
      private boolean placeText(Element e, BufferedImage i)
      throws CreationException {
          String text=e.getAttribute("text");
          String font=e.getAttribute("font");
          String ssize=e.getAttribute("size");
          String sstyle=e.getAttribute("style");
          String scolor=e.getAttribute("color");
          String sx=e.getAttribute("x");
          String sy=e.getAttribute("y");
          String halign=e.getAttribute("halign");
          String valign=e.getAttribute("valign");
          // Check proper text
          if (text.length()<1) return(false);
          // Check size, x and y parameters
          int color,size,insx,insy;
          try {
              size=Integer.parseInt(ssize);
              insx=Integer.parseInt(sx);
              insy=Integer.parseInt(sy);
              color=Integer.parseInt(scolor,16);
          } catch (NumberFormatException ex) {
              throw new CreationException("Attribute size, x, y or color error");
          }
          // Get style
          int style=Font.PLAIN;
          if (sstyle.equals("bold")) style=Font.BOLD;
          else if (sstyle.equals("italic")) style=Font.ITALIC;
          else if (sstyle.equals("bolditalic")) style=Font.BOLD+Font.ITALIC;
          Font f=new Font(font,style,size);
          FontMetrics m=i.createGraphics().getFontMetrics(f);
          // Create temporary image
          int w=m.stringWidth(text)*2;
          int h=m.getHeight()*2;
          BufferedImage n=new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB);
          // Write out some text
          Graphics2D gr=n.createGraphics();
          gr.setColor(new Color(0x0ff000000,true));
          gr.setFont(f);
          gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                              RenderingHints.VALUE_ANTIALIAS_ON);
          gr.drawString(text,5,h-(h/4));
          // Resize image
          int minx=w;
          int miny=h;
          int maxx=0;
          int maxy=0;
          WritableRaster nr=n.getRaster();
          int np[]=new int[]{0,0,0,0};
          for (int x=0;x<nr.getWidth();x++) for (int y=10;y<nr.getHeight();y++) {
              nr.getPixel(x,y,np);
              if (np[A]>0) {
                  if(x<minx) minx=x;
                  if(x>maxx) maxx=x;
                  if(y<miny) miny=y;
                  if(y>maxy) maxy=y;
              }
          }
          if (halign.equals("right")) insx=insx-((maxx-minx)+1);
          if (halign.equals("center")) insx=insx-(((maxx-minx)+1)/2);
          if (valign.equals("bottom")) insy=insy-((maxy-miny)+1);
          if (valign.equals("center")) insy=insy-(((maxy-miny)+1)/2);
          WritableRaster ir=i.getRaster();
          int newx,newy;
          newy=insy;
          for (int y=miny;y<=maxy;y++) {
              newx=insx;
              if(newy>=0) {
                  for (int x=minx;x<=maxx;x++) {
                      nr.getPixel(x,y,np);
                      np[R]=(color >> 16) & 0x0ff;
                      np[G]=(color >> 8) & 0x0ff;
                      np[B]=(color & 0x0ff);
                      if(newx>=0) ir.setPixel(newx,newy,np);
                      newx++;
                      if(newx>=i.getWidth()) break;
                  }
              }
              newy++;
              if(newy>=i.getHeight()) break;
          }
          return(true);
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/printers/XMLPrinter.java
  
  Index: XMLPrinter.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook.printers;
  
  import org.apache.stylebook.*;
  import java.io.IOException;
  import java.io.OutputStream;
  import java.io.PrintStream;
  import org.w3c.dom.Attr;
  import org.w3c.dom.CDATASection;
  import org.w3c.dom.Comment;
  import org.w3c.dom.Document;
  import org.w3c.dom.DocumentFragment;
  import org.w3c.dom.DocumentType;
  import org.w3c.dom.Element;
  import org.w3c.dom.Entity;
  import org.w3c.dom.EntityReference;
  import org.w3c.dom.NamedNodeMap;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.Notation;
  import org.w3c.dom.ProcessingInstruction;
  import org.w3c.dom.Text;
  
  /**
   * The XMLPrinter Printer writes documents in their canonical XML form.
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:07:59 $
   */
  public class XMLPrinter extends AbstractComponent implements Printer {
      /**
       * Print a DOM Document.
       */
      public void print(Document doc, CreationContext c, OutputStream out)
      throws CreationException, IOException {
          printDocument(doc,new PrintStream(out),0);
      }
  
      /** Process a nodelist calling the appropriate print...() method. */
      private void printNodeList(NodeList list, PrintStream out, int indent) {
          for (int x=0;x<list.getLength();x++) {
              Node node=list.item(x);
              switch (node.getNodeType()) {
                  case Node.ATTRIBUTE_NODE:
                      printAttribute((Attr)node,out,indent);
                      break;
                  case Node.CDATA_SECTION_NODE:
                      printCDATASection((CDATASection)node,out,indent);
                      break;
                  case Node.COMMENT_NODE:
                      printComment((Comment)node,out,indent);
                      break;
                  case Node.DOCUMENT_FRAGMENT_NODE:
                      printDocumentFragment((DocumentFragment)node,out,indent);
                      break;
                  case Node.DOCUMENT_NODE:
                      printDocument((Document)node,out,indent);
                      break;
                  case Node.DOCUMENT_TYPE_NODE:
                      printDocumentType((DocumentType)node,out,indent);
                      break;
                  case Node.ELEMENT_NODE:
                      printElement((Element)node,out,indent);
                      break;
                  case Node.ENTITY_NODE:
                      printEntity((Entity)node,out,indent);
                      break;
                  case Node.ENTITY_REFERENCE_NODE:
                      printEntityReference((EntityReference)node,out,indent);
                      break;
                  case Node.NOTATION_NODE:
                      printNotation((Notation)node,out,indent);
                      break;
                  case Node.PROCESSING_INSTRUCTION_NODE:
                      printProcessingInstruction((ProcessingInstruction)node,out,indent);
                      break;
                  case Node.TEXT_NODE:
                      printText((Text)node,out,indent);
                      break;
              }
          }
      }
  
      /** Print an ATTRIBUTE (name="value") node. */
      private void printAttribute(Attr node, PrintStream out, int indent) {
          out.print(node.getName()+"=\""+node.getValue()+"\"");
      }
  
      /** Print a CDATA (<[CDATA[ ... ]]>) node. */
      private void printCDATASection(CDATASection node, PrintStream out, int indent) {
          indent(out,indent);
          out.println("<[CDATA["+node.getData()+"]]>");
      }
  
      /** Print a COMMENT (<!-- ... -->) node. */
      private void printComment(Comment node, PrintStream out, int indent) {
          indent(out,indent);
          out.println("<!--"+node.getData()+"-->");
      }
  
      /** Print a DOCUMENT FRAGMENT (????) node. */
      private void printDocumentFragment(DocumentFragment node, PrintStream out, int indent) {
          indent(out,indent);
          out.println("<!-- Document Fragment Node -->");
      }
  
      /** Print a DOCUMENT node. */
      private void printDocument(Document node, PrintStream out, int indent) {
          indent(out,indent);
          out.println("<?xml version=\"1.0\"?>");
          printNodeList(node.getChildNodes(),out,indent);
      }
  
      /** Print a DOCUMENT TYPE (<!DOCTYPE ... bla bla bla>) node. */
      private void printDocumentType(DocumentType node, PrintStream out, int indent) {
          indent(out,indent);
          out.println("<!DOCTYPE "+node.getName()+">");
          // Should we insert ENTITIES and NOTATIONS?
      }
  
      /** Print a ELEMENT (do I need to supply the example ??? :) node. */
      private void printElement(Element node, PrintStream out, int indent) {
          // Print the tag name
          indent(out,indent);
          out.print("<"+node.getTagName());
          // Process attributes
          NamedNodeMap atts=node.getAttributes();
          if ((null!=atts) && (atts.getLength()>0)) {
              for (int x=0; x<atts.getLength(); x++) {
                  out.print(' ');
                  printAttribute((Attr)atts.item(x),out,indent);
              }
          }
          // Process child nodes
          if ((null!=node.getChildNodes()) &&
                  (node.getChildNodes().getLength()>0)) {
              out.println(">");
              printNodeList(node.getChildNodes(),out,indent+1);
              indent(out,indent);
              out.println("</"+node.getTagName()+">");
          } else {
              out.println("/>");
          }
      }
  
      /** Print a ENTITY node (NOTE: This should be used with DOCTYPE). */
      private void printEntity(Entity node, PrintStream out, int indent) {
          indent(out,indent);
          out.println("<!-- Entity Node -->");
      }
  
      /** Print a ENTITY REFERENCE node (NOTE: Again, used in within DOCTYPE). */
      private void printEntityReference(EntityReference node, PrintStream out, int indent) {
          indent(out,indent);
          out.println("<!-- Entity Reference Node -->");
      }
  
      /** Print a NOTATION node (NOTE: Again -3rd-, used in within DOCTYPE). */
      private void printNotation(Notation node, PrintStream out, int indent) {
          indent(out,indent);
          out.println("<!-- Notation Node -->");
      }
  
      /** Print a PROCESSING INSTRUCTION (<?name ...?>) node. */
      private void printProcessingInstruction(ProcessingInstruction node, PrintStream out, int indent) {
          indent(out,indent);
          out.println("<?"+node.getTarget()+" "+node.getData()+"?>");
      }
  
      /** Print a TEXT (see example for ELEMENT) node. */
      private void printText(Text node, PrintStream out, int indent) {
          String data=node.getData();
          if (data.length()==0) return;
          data=leftTrim(data);
          if (data.length()==0) return;
          Text curr=node;
          while(true) {
              Node nextnode=curr.getNextSibling();
              if (nextnode==null) break;
              if (nextnode.getNodeType()!=Node.TEXT_NODE) break;
              Text next=(Text)nextnode;
              String app=next.getData();
              if (app.length()>0) {
                  if (Character.isWhitespace(app.charAt(0))) {
                      data=trim(data)+' '+leftTrim(app);
                  } else {
                      data=trim(data)+leftTrim(app);
                  }
              }
              next.setData("");
              curr=next;
          }
          data=trim(data);
          node.setData(data);
          if (data.length()>0) {
              indent(out,indent);
              out.println(data);
          }
      }
  
      /** Remove white space at string beginning. */
      private String leftTrim(String data) {
          if (data.length()==0) return(data);
          int index=0;
          for (int x=0;x<data.length();x++) {
              if (Character.isWhitespace(data.charAt(x))) index=x+1;
              else break;
          }
          if (index==data.length()) return("");
          return(data.substring(index));
      }
  
      /** Remove white space at string ending. */
      private String rightTrim(String data) {
          if (data.length()==0) return(data);
          int index=data.length();
          for (int x=index-1;x>=0;x--) {
              if (Character.isWhitespace(data.charAt(x))) index=x;
              else break;
          }
          return(data.substring(0,index));
      }
  
      /** Remove white space at string beginning and ending. */
      private String trim(String data) {
          return(leftTrim(rightTrim(data)));
      }
  
      /** Indent data (print whitespaces). */
      private void indent(PrintStream out, int indent) {
          for (int x=0; x<indent; x++) out.print("  ");
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/processors/ImportProcessor.java
  
  Index: ImportProcessor.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook.processors;
  
  import org.apache.stylebook.*;
  import java.io.IOException;
  import java.io.OutputStream;
  import java.io.PrintStream;
  import java.util.StringTokenizer;
  import org.w3c.dom.*;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:08:09 $
   */
  public class ImportProcessor extends AbstractComponent implements Processor {
  
      public Document process(Document doc, CreationContext c, Parameters p)
      throws CreationException, IOException {
          processNode(doc.getDocumentElement(),doc,c);
          return(doc);
      }
  
      private void processNode(Node node, Document doc, CreationContext ctx)
      throws IOException, CreationException {
          if(node==null) return;
          if(node.getNodeType()!=Node.PROCESSING_INSTRUCTION_NODE) {
              NodeList l=node.getChildNodes();
              for (int x=0; x<l.getLength(); x++) processNode(l.item(x),doc,ctx);
              return;
          }
          ProcessingInstruction pi=(ProcessingInstruction)node;
          if (pi.getTarget().equals("import")) {
              String producer=null;
              String source="";
              StringTokenizer tok=new StringTokenizer(pi.getData());
              while(tok.hasMoreTokens()) {
                  String p=tok.nextToken();
                  StringTokenizer tok2=new StringTokenizer(p,"\"=",false);
                  if(tok2.countTokens()!=2)
                      throw new CreationException("Invalid parameter \""+p+"\"");
                  String name=tok2.nextToken();
                  String value=tok2.nextToken();
                  if(name.equals("producer")) producer=value;
                  else if(name.equals("source")) source=value;
                  else throw new CreationException("Invalid parameter \""+p+"\"");
              }
              if(producer==null)
                  throw new CreationException("Producer not specified");
              log("Importing \""+source+"\" using Producer \""+producer+"\"");
              BasicContext ctx2=new BasicContext(source,ctx.getTargetName());
              ctx2.merge(ctx);
              Document newdoc=this.engine.getProducer(producer).produce(ctx2);
              Node elem=copyNode(doc,newdoc.getDocumentElement());
              if (elem==null) return;
              pi.getParentNode().replaceChild(elem,pi);
          }
      }
  
      private Node copyNode(Document d, Node n) {
          if (n==null) return(null);
          Node copy=null;
          switch(n.getNodeType()) {
              case Node.ELEMENT_NODE:
                  copy=d.createElement(((Element)n).getTagName());
                  NamedNodeMap m=n.getAttributes();
                  for (int k=0; k<m.getLength(); k++) {
                      Attr a=(Attr)m.item(k);
                      ((Element)copy).setAttribute(a.getName(),a.getValue());
                  }
                  break;
              case Node.CDATA_SECTION_NODE:
                  copy=d.createCDATASection(((CharacterData)n).getData());
                  break;
              case Node.COMMENT_NODE:
                  copy=d.createComment(((CharacterData)n).getData());
                  break;
              case Node.TEXT_NODE:
                  copy=d.createTextNode(((CharacterData)n).getData());
                  break;
              case Node.ENTITY_REFERENCE_NODE:
                  copy=d.createEntityReference(n.getNodeValue());
                  break;
              case Node.PROCESSING_INSTRUCTION_NODE:
                  String target=((ProcessingInstruction)n).getTarget();
                  String data=((ProcessingInstruction)n).getData();
                  copy=d.createProcessingInstruction(target,data);
                  break;
          }
          if (copy==null) return(null);
          NodeList l=n.getChildNodes();
          for (int x=0;x<l.getLength();x++) {
              Node child=copyNode(d,l.item(x));
              if (child!=null) copy.appendChild(child);
          }
          return(copy);
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/processors/LotusXSLProcessor.java
  
  Index: LotusXSLProcessor.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook.processors;
  
  import org.apache.stylebook.*;
  import com.lotus.xsl.XSLProcessor;
  import com.lotus.xsl.XSLProcessorException;
  import com.lotus.xml.XMLParserLiaisonDefault;
  import java.io.IOException;
  import java.io.OutputStream;
  import java.io.PrintStream;
  import java.io.Reader;
  import java.net.URL;
  import java.util.StringTokenizer;
  import org.w3c.dom.Document;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.ProcessingInstruction;
  import org.xml.sax.InputSource;
  
  /**
   * The LotusXSLProcessor applies an XSL stylesheet to a given Document.
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:08:09 $
   */
  public class LotusXSLProcessor extends AbstractComponent implements Processor {
      /**
       * Construct a new instance of this Processor.
       */
      public LotusXSLProcessor() {
          super();
      }
  
      public Document process(Document doc, CreationContext c, Parameters p)
      throws CreationException, IOException {
          try {
              // Create a new XSLProcessor instance
              XSLProcessor proc=new XSLProcessor(new Liaison(this.engine));
              // Retrieve the style
              String stylesheet=p.getParameter("stylesheet");
              if (null==stylesheet) stylesheet=this.getStyleSheetURIfromDoc(doc);
              if (null==stylesheet) return(doc);
              log("Applying XSL sheet \""+stylesheet+"\"");
              Document style=this.engine.getParser().parse(new InputSource(stylesheet));
              return(proc.process(doc,style,stylesheet));
          } catch (Exception e) {
              throw new CreationException(e.getMessage(),e,doc);
          }
      }
  
      /** Search for the &lt;?xml:stylesheet ... ?&gt; processing instruction. */
      private String getStyleSheetURIfromDoc(Document sourceTree) {
          String stylesheetURI=null;
          NodeList children=sourceTree.getChildNodes();
          int nNodes=children.getLength();
          for(int i=0; i<nNodes; i++) {
              Node child=children.item(i);
              if (Node.PROCESSING_INSTRUCTION_NODE==child.getNodeType()) {
                  ProcessingInstruction pi=(ProcessingInstruction)child;
                  if(pi.getNodeName().equals("xml-stylesheet")) {
                      boolean isOK=true;
                      StringTokenizer tok=new StringTokenizer(pi.getNodeValue(),
                                                                    " \t=");
                      while(tok.hasMoreTokens()) {
                          if(tok.nextToken().equals("type")) {
                              String typeVal=tok.nextToken();
                              typeVal=typeVal.substring(1, typeVal.length()-1);
                              if(!typeVal.equals("text/xsl")) isOK=false;
                          }
                      }
                      if(isOK) {
                          tok=new StringTokenizer(pi.getNodeValue()," \t=");
                          while(tok.hasMoreTokens()) {
                              if(tok.nextToken().equals("href")) {
                                  stylesheetURI=tok.nextToken();
                                  stylesheetURI=stylesheetURI.substring(1,
                                                        stylesheetURI.length()-1);
                              }
                          }
                          break;
                      }
                  }
              }
          }
          return stylesheetURI;
      }
  
      public class Liaison extends XMLParserLiaisonDefault {
          private Parser parser;
  
          public Liaison(Engine e) {
              super();
              this.parser=e.getParser();
          }
  
          public Document createDocument() {
              return(this.parser.create());
          }
  
          public Document parseXMLStream(Reader reader, String filename)
          throws XSLProcessorException {
              try {
                  return(this.parser.parse(new InputSource(reader)));
              } catch (CreationException e) {
                  throw new XSLProcessorException(e.getMessage());
              } catch (IOException e) {
                          throw new XSLProcessorException(e.getMessage());
              }
          }
  
          public Document parseXMLStream(Reader reader)
          throws XSLProcessorException {
              try {
                  return(this.parser.parse(new InputSource(reader)));
              } catch (CreationException e) {
                  throw new XSLProcessorException(e.getMessage());
              } catch (IOException e) {
                          throw new XSLProcessorException(e.getMessage());
              }
          }
  
          public Document parseXMLStream(URL url)
          throws XSLProcessorException {
              try {
                  return(this.parser.parse(new InputSource(url.toString())));
              } catch (CreationException e) {
                  throw new XSLProcessorException(e.getMessage());
              } catch (IOException e) {
                          throw new XSLProcessorException(e.getMessage());
              }
          }
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/processors/NullProcessor.java
  
  Index: NullProcessor.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook.processors;
  
  import org.apache.stylebook.*;
  import java.io.IOException;
  import org.w3c.dom.Document;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:08:10 $
   */
  public class NullProcessor extends AbstractComponent implements Processor {
      public Document process(Document doc, CreationContext c, Parameters p)
      throws CreationException, IOException {
          log("Processing document");
          return(doc);
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/processors/XalanProcessor.java
  
  Index: XalanProcessor.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook.processors;
  
  import org.apache.stylebook.*;
  import java.io.IOException;
  import java.io.OutputStream;
  import java.io.PrintStream;
  import java.io.Reader;
  import java.net.URL;
  import java.util.StringTokenizer;
  import org.apache.xpath.xml.FormatterToDOM;
  import org.apache.xpath.xml.XMLParserLiaison;
  import org.apache.xpath.xml.XMLParserLiaisonDefault;
  import org.apache.xslt.XSLTInputSource;
  import org.apache.xslt.XSLTProcessor;
  import org.apache.xslt.XSLTProcessorFactory;
  import org.apache.xslt.XSLTResultTarget;
  import org.w3c.dom.Document;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.ProcessingInstruction;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:08:11 $
   */
  public class XalanProcessor extends AbstractComponent implements Processor {
  
      public Document process(Document doc, CreationContext c, Parameters p)
      throws CreationException, IOException {
          try {
  
              // Create a new XSLTProcessor instance
              XMLParserLiaison liaison=new Liaison(this.engine);
              XSLTProcessor proc=XSLTProcessorFactory.getProcessor(liaison);
              // Retrieve the style
              String styf=p.getParameter("stylesheet");
              if (null==styf) styf=this.getStyleSheet(doc);
              if (null==styf) return(doc);
              // Setup the input sources and the result target
              Document res=this.engine.getParser().create();
              Document sty=this.engine.getParser().parse(new InputSource(styf));
              XSLTInputSource docin=new XSLTInputSource(doc);
              XSLTInputSource styin=new XSLTInputSource(sty);
              XSLTResultTarget out=new XSLTResultTarget(new FormatterToDOM(res));
              // Process the document
              log("Applying XSL sheet \""+styf+"\"");
              proc.process(docin,styin,out);
              return(res);
          } catch (Exception e) {
              e.printStackTrace(System.out);
              throw new CreationException(e.getMessage(),e,doc);
          }
      }
  
      /** Search for the &lt;?xml:stylesheet ... ?&gt; processing instruction. */
      private String getStyleSheet(Document sourceTree) {
          String uri=null;
          NodeList children=sourceTree.getChildNodes();
          int nNodes=children.getLength();
          for(int i=0; i<nNodes; i++) {
              Node child=children.item(i);
              if (Node.PROCESSING_INSTRUCTION_NODE==child.getNodeType()) {
                  ProcessingInstruction pi=(ProcessingInstruction)child;
                  if(pi.getNodeName().equals("xml-stylesheet")) {
                      boolean isOK=true;
                      StringTokenizer tok=new StringTokenizer(pi.getNodeValue(),
                                                                    " \t=");
                      while(tok.hasMoreTokens()) {
                          if(tok.nextToken().equals("type")) {
                              String typeVal=tok.nextToken();
                              typeVal=typeVal.substring(1, typeVal.length()-1);
                              if(!typeVal.equals("text/xsl")) isOK=false;
                          }
                      }
                      if(isOK) {
                          tok=new StringTokenizer(pi.getNodeValue()," \t=");
                          while(tok.hasMoreTokens()) {
                              if(tok.nextToken().equals("href")) {
                                  uri=tok.nextToken();
                                  uri=uri.substring(1,uri.length()-1);
                              }
                          }
                          break;
                      }
                  }
              }
          }
          return(uri);
      }
  
      private class Liaison extends XMLParserLiaisonDefault {
          private Engine engine=null;
          private Document document=null;
  
          public Liaison(Engine e) {
              this.engine=e;
          }
  
          public Document createDocument() {
              return(this.engine.getParser().create());
          }
  
          public void parse(InputSource in)
          throws IOException, SAXException {
              try {
                  this.document=this.engine.getParser().parse(in);
              } catch (CreationException e) {
                  this.engine.debug(this,"CreationException "+e.getMessage());
                  Exception e2=e.getException();
                  if((e2==null)||(!(e2 instanceof SAXException)))
                      throw new SAXException("Exception parsing from Xalan");
                  throw (SAXException)e2;
              }
          }
  
          public Document getDocument() {
              return(this.document);
          }
  
          public boolean supportsSAX() {
              return(false);
          }
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/producers/ContextProducer.java
  
  Index: ContextProducer.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook.producers;
  
  import org.apache.stylebook.*;
  import java.io.IOException;
  import java.util.Enumeration;
  import org.xml.sax.InputSource;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:08:16 $
   */
  public class ContextProducer extends AbstractComponent implements Producer {
      public Document produce(CreationContext c)
      throws CreationException, java.io.IOException {
          Document d=engine.getParser().create();
          Element root=d.createElement("context");
          root.setAttribute("source",c.getSourceName());
          root.setAttribute("target",c.getTargetName());
          Enumeration e=c.getParameterNames();
          while(e.hasMoreElements()) {
              String name=(String)e.nextElement();
              String value=c.getParameter(name);
              Element param=d.createElement("parameter");
              param.setAttribute("name",name);
              param.setAttribute("value",value);
              root.appendChild(param);
          }
          d.appendChild(root);
          return(d);
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/producers/ParserProducer.java
  
  Index: ParserProducer.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook.producers;
  
  import org.apache.stylebook.*;
  import java.io.IOException;
  import org.xml.sax.InputSource;
  import org.w3c.dom.Document;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:08:17 $
   */
  public class ParserProducer extends AbstractComponent implements Producer {
      public Document produce(CreationContext c)
      throws CreationException, java.io.IOException {
          return(engine.getParser().parse(new InputSource(c.getSourceName())));
      }
  }
  
  
  
  1.1                  xml-0.0/src/java/stylebook/src/org/apache/stylebook/producers/ProjectProducer.java
  
  Index: ProjectProducer.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) 1999 The Apache Software Foundation.   All rights reserved. *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1,  a copy of wich has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.stylebook.producers;
  
  import org.apache.stylebook.*;
  import java.io.IOException;
  import org.xml.sax.InputSource;
  import org.w3c.dom.Document;
  
  /**
   *
   *
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
   *         Software Foundation</a>. All rights reserved.
   * @version CVS $Revision: 1.1 $ $Date: 1999/11/15 22:08:18 $
   */
  public class ProjectProducer extends AbstractComponent implements Producer {
      public Document produce(CreationContext c)
      throws CreationException, java.io.IOException {
          String project=c.getParameter("stylebook.project");
          if(project==null) throw new CreationException("Cannot produce project");
          return(engine.getParser().parse(new InputSource(project)));
      }
  }
  
  
  

Mime
View raw message