mmidy       01/03/13 09:28:44

  Modified:    java/src/org/apache/xalan/res XSLTErrorResources.java
               java/src/org/apache/xalan/xslt Process.java
  Log:
  Implement new arguments for the command line interface: URIResolver, 
EntityResolver and ContentHandler
  
  Revision  Changes    Path
  1.16      +18 -2     
xml-xalan/java/src/org/apache/xalan/res/XSLTErrorResources.java
  
  Index: XSLTErrorResources.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/res/XSLTErrorResources.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- XSLTErrorResources.java   2001/02/28 16:44:01     1.15
  +++ XSLTErrorResources.java   2001/03/13 17:28:34     1.16
  @@ -86,13 +86,13 @@
     public static final String WARNING_SUFFIX = "WR";
   
     /** Maximum error messages, this is needed to keep track of the number of 
messages.    */
  -  public static final int MAX_CODE = 108;          
  +  public static final int MAX_CODE = 109;          
   
     /** Maximum warnings, this is needed to keep track of the number of 
warnings.          */
     public static final int MAX_WARNING = 26;
   
     /** Maximum misc strings.   */
  -  public static final int MAX_OTHERS = 41;
  +  public static final int MAX_OTHERS = 44;
   
     /** Maximum total warnings and error messages.          */
     public static final int MAX_MESSAGES = MAX_CODE + MAX_WARNING + 1;
  @@ -1083,6 +1083,15 @@
       contents[ER_ILLEGAL_DOMSOURCE_INPUT][1] =
         "The input node can not be null for a DOMSource for newTemplates!";
     }
  +     
  +     /** Class not found for option         */
  +  public static final int ER_CLASS_NOT_FOUND_FOR_OPTION = 109;
  +
  +  static
  +  {
  +    contents[ER_CLASS_NOT_FOUND_FOR_OPTION][1] =
  +                     "Class file not found for option {0}";
  +  }
     
   
     // Warnings...
  @@ -1428,6 +1437,13 @@
       contents[MAX_MESSAGES + 41][0] = "noParsermsg5";
       contents[MAX_MESSAGES + 41][1] =
         "IBM's AlphaWorks: http://www.alphaworks.ibm.com/formula/xml";;
  +             contents[MAX_MESSAGES + 42][0] = "optionURIRESOLVER";
  +    contents[MAX_MESSAGES + 42][1] = "   [-URIRESOLVER full class name 
(URIResolver to be used to resolve URIs)]";
  +             contents[MAX_MESSAGES + 43][0] = "optionENTITYRESOLVER";
  +    contents[MAX_MESSAGES + 43][1] = "   [-ENTITYRESOLVER full class name 
(EntityResolver to be used to resolve entities)]";
  +             contents[MAX_MESSAGES + 44][0] = "optionCONTENTHANDLER";
  +    contents[MAX_MESSAGES + 44][1] = "   [-CONTENTHANDLER full class name 
(ContentHandler to be used to serialize output)]";
  +             
     }
   
     // ================= INFRASTRUCTURE ======================
  
  
  
  1.29      +125 -4    xml-xalan/java/src/org/apache/xalan/xslt/Process.java
  
  Index: Process.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xslt/Process.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- Process.java      2001/03/05 19:54:55     1.28
  +++ Process.java      2001/03/13 17:28:42     1.29
  @@ -103,12 +103,18 @@
   import javax.xml.transform.sax.SAXTransformerFactory;
   import javax.xml.transform.OutputKeys;
   import javax.xml.transform.TransformerException;
  +import javax.xml.transform.URIResolver;
   
   import javax.xml.transform.dom.*;
  +import javax.xml.transform.sax.*;
   import javax.xml.parsers.*;
   import org.w3c.dom.Node;
   import org.w3c.dom.Document;
   import org.xml.sax.InputSource;
  +import org.xml.sax.EntityResolver;
  +import org.xml.sax.ContentHandler;
  +import org.xml.sax.XMLReader;
  +import org.xml.sax.helpers.XMLReaderFactory;
   
   // Needed Serializer classes
   import org.apache.xalan.serialize.Serializer;
  @@ -157,6 +163,9 @@
         "   [-FLAVOR flavorName (Explicitly use s2s=SAX or d2d=DOM to do 
transform.)]"); // Added by sboag/scurcuru; experimental
       System.out.println(
         "   [-DIAG (Print overall milliseconds transform took.)]");
  +             System.out.println(resbundle.getString("optionURIRESOLVER"));  
//"   [-URIRESOLVER full class name (URIResolver to be used to resolve URIs)]");
  +             
System.out.println(resbundle.getString("optionENTITYRESOLVER"));  //"   
[-ENTITYRESOLVER full class name (EntityResolver to be used to resolve 
entities)]");
  +             
System.out.println(resbundle.getString("optionCONTENTHANDLER"));  //"   
[-CONTENTHANDLER full class name (ContentHandler to be used to serialize 
output)]");
     }
   
     /** Default properties file          */
  @@ -228,6 +237,9 @@
         String media = null;
         Vector params = new Vector();
         boolean quietConflictWarnings = false;
  +                     URIResolver uriResolver = null;
  +                     EntityResolver entityResolver = null;
  +                     ContentHandler contentHandler = null;
   
         for (int i = 0; i < argv.length; i++)
         {
  @@ -431,6 +443,82 @@
               dumpFileName = argv[++i];
             }
           }
  +                             else if 
("-URIRESOLVER".equalsIgnoreCase(argv[i])) 
  +        {
  +          if (i + 1 < argv.length)
  +                                     {       
  +                                             try{
  +                                                     uriResolver = 
(URIResolver)Class.forName(argv[++i]).newInstance();
  +                                                     
tfactory.setURIResolver(uriResolver);
  +                                             }
  +                                             catch(Exception cnfe)
  +                                             {
  +                                                     System.err.println(
  +              XSLMessages.createMessage(
  +                XSLTErrorResources.ER_CLASS_NOT_FOUND_FOR_OPTION,
  +                new Object[]{ "-URIResolver" })); 
  +                                                     System.exit(-1);
  +                                             }
  +                                     }
  +                                     else
  +                                     {
  +            System.err.println(
  +              XSLMessages.createMessage(
  +                XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
  +                new Object[]{ "-URIResolver" }));  //"Missing argument for);
  +                                             System.exit(-1);
  +                                     }
  +                             }
  +                             else if 
("-ENTITYRESOLVER".equalsIgnoreCase(argv[i])) 
  +        {
  +          if (i + 1 < argv.length)
  +                                     {       
  +                                             try{
  +                                                     entityResolver = 
(EntityResolver)Class.forName(argv[++i]).newInstance();                         
                               
  +                                             }
  +                                             catch(Exception cnfe)
  +                                             {
  +                                                     System.err.println(
  +              XSLMessages.createMessage(
  +                XSLTErrorResources.ER_CLASS_NOT_FOUND_FOR_OPTION,
  +                new Object[]{ "-EntityResolver" }));
  +                                                     System.exit(-1);
  +                                             }
  +                                     }
  +          else
  +                                     {
  +            System.err.println(
  +              XSLMessages.createMessage(
  +                XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
  +                new Object[]{ "-EntityResolver" }));  //"Missing argument 
for);
  +                                             System.exit(-1);
  +                                     }
  +        }
  +                             else if 
("-CONTENTHANDLER".equalsIgnoreCase(argv[i])) 
  +        {
  +          if (i + 1 < argv.length)
  +                                     {       
  +                                             try{
  +                                                     contentHandler = 
(ContentHandler)Class.forName(argv[++i]).newInstance();                         
                               
  +                                             }
  +                                             catch(Exception cnfe)
  +                                             {
  +                                                     System.err.println(
  +              XSLMessages.createMessage(
  +                XSLTErrorResources.ER_CLASS_NOT_FOUND_FOR_OPTION,
  +                new Object[]{ "-ContentHandler" }));
  +                                                     System.exit(-1);
  +                                             }
  +                                     }
  +          else
  +                                     {
  +            System.err.println(
  +              XSLMessages.createMessage(
  +                XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
  +                new Object[]{ "-ContentHandler" }));  //"Missing argument 
for);
  +                                             System.exit(-1);
  +                                     }
  +        }
           else
             System.err.println(
               XSLMessages.createMessage(
  @@ -464,7 +552,7 @@
               DocumentBuilderFactory dfactory = 
DocumentBuilderFactory.newInstance();
               dfactory.setNamespaceAware(true);
               DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
  -            Node xslDOM = docBuilder.parse(new InputSource(xslFileName));
  +                                             Node xslDOM = 
docBuilder.parse(new InputSource(xslFileName));
               stylesheet = tfactory.newTemplates(new DOMSource(xslDOM, 
xslFileName));
             }
             else
  @@ -533,6 +621,8 @@
               transformer.setParameter((String) params.elementAt(i),
                                        (String) params.elementAt(i + 1));
             }
  +                                     if (uriResolver != null)
  +                                             
transformer.setURIResolver(uriResolver);
   
             if (null != inFileName)
             {
  @@ -543,6 +633,8 @@
                 dfactory.setCoalescing(true);
                 dfactory.setNamespaceAware(true);
                 DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
  +                                                     if (entityResolver != 
null)
  +                                                             
docBuilder.setEntityResolver(entityResolver);
                 Node xmlDoc = docBuilder.parse(new InputSource(inFileName));
                 Document doc = docBuilder.newDocument();
                 org.w3c.dom.DocumentFragment outNode = 
doc.createDocumentFragment();
  @@ -553,13 +645,42 @@
                 Transformer serializer = stf.newTransformer();
                 Properties serializationProps = 
stylesheet.getOutputProperties();
                 serializer.setOutputProperties(serializationProps);
  -              serializer.transform(new DOMSource(outNode), 
  +                                                     if (contentHandler != 
null)
  +                                                     {
  +                                                             SAXResult 
result = new SAXResult(contentHandler);
  +                                                             
serializer.transform(new DOMSource(outNode), result);
  +                                                     }
  +                                                     else
  +                                                             
serializer.transform(new DOMSource(outNode), 
                                      new StreamResult(outputStream));
              }
               else
               {
  -              transformer.transform(new StreamSource(inFileName),
  -                                    new StreamResult(outputStream));
  +                                                     if (entityResolver != 
null)
  +                                                     {
  +                                                             XMLReader 
reader = XMLReaderFactory.createXMLReader();
  +                                                             
reader.setEntityResolver(entityResolver);
  +                                                             if 
(contentHandler != null)
  +                                                             {
  +                                                                     
SAXResult result = new SAXResult(contentHandler);
  +                                                                     
transformer.transform(new SAXSource(reader, new InputSource(inFileName)),
  +                                                                             
                                                                                
result);
  +                                                             }
  +                                                             else
  +                                                             {
  +                                                                     
transformer.transform(new SAXSource(reader, new InputSource(inFileName)),
  +                                                                             
                                                                        new 
StreamResult(outputStream));
  +                                                             }
  +                                                     }
  +                                                     else if (contentHandler 
!= null)
  +                                                     {
  +                                                             SAXResult 
result = new SAXResult(contentHandler);
  +                                                             
transformer.transform(new StreamSource(inFileName),
  +                                                                             
                                                                        result);
  +                                                     }
  +                                                     else
  +                                                             
transformer.transform(new StreamSource(inFileName),
  +                                                                             
                                                                        new 
StreamResult(outputStream));
               }
             }
             else
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to