You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mk...@apache.org on 2002/09/18 18:54:24 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/res XSLTErrorResources.properties

mkwan       2002/09/18 09:54:24

  Modified:    java/src/org/apache/xalan/xslt Process.java
               java/src/org/apache/xalan/res XSLTErrorResources.properties
  Log:
  XSLTC support - phase 1
  
  Add the -XSLTC option to enable transforming using XSLTC
  
  The following existing options do not work in XSLTC mode:
  -TT
  -TG
  -TS
  -TTC
  -QC
  -L
  -INCREMENTAL
  -NOOPTIMIZE
  -RL
  
  If any of these options is used with -XSLTC, a message is printed
  and the option is ignored. All other existing options (e.g. -flavor,
  -text, etc.) can be used with -XSLTC.
  
  In phase 2, we are going to migrate the XSLTC specific options in the
  XSLTC command lines (Compile and Transform) to the Process command line.
  One of the new features would be generating translet class files from
  the xsl.
  
  Revision  Changes    Path
  1.50      +109 -95   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.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- Process.java	22 May 2002 20:12:53 -0000	1.49
  +++ Process.java	18 Sep 2002 16:54:24 -0000	1.50
  @@ -116,7 +116,6 @@
    */
   public class Process
   {
  -
     /**
      * Prints argument options.
      *
  @@ -124,9 +123,9 @@
      */
     protected static void printArgOptions(ResourceBundle resbundle)
     {
  -
       System.out.println(resbundle.getString("xslProc_option"));  //"xslproc options: ");
       System.out.println(resbundle.getString("optionIN"));  //"    -IN inputXMLURL");
  +    System.out.println(resbundle.getString("optionXSLTC"));  //"    [-XSLTC (use XSLTC for transformation)]
       System.out.println(resbundle.getString("optionXSL"));  //"   [-XSL XSLTransformationURL]");
       System.out.println(resbundle.getString("optionOUT"));  //"   [-OUT outputFileName]");
   
  @@ -202,8 +201,25 @@
       }
       else
       {
  +      boolean useXSLTC = false;
  +      for (int i = 0; i < argv.length; i++)
  +      {
  +        if ("-XSLTC".equalsIgnoreCase(argv[i]))
  +        {
  +          useXSLTC = true;
  +        }
  +      }
  +        
         TransformerFactory tfactory;
  -
  +      if (useXSLTC)
  +      {
  +	 String key = "javax.xml.transform.TransformerFactory";
  +	 String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl";
  +	 Properties props = System.getProperties();
  +	 props.put(key, value);
  +	 System.setProperties(props);      
  +      }
  +      
         try
         {
           tfactory = TransformerFactory.newInstance();
  @@ -239,39 +255,63 @@
   
         for (int i = 0; i < argv.length; i++)
         {
  -        if ("-TT".equalsIgnoreCase(argv[i]))
  +        if ("-XSLTC".equalsIgnoreCase(argv[i]))
  +        {
  +          // The -XSLTC option has been processed.
  +        }
  +        else if ("-TT".equalsIgnoreCase(argv[i]))
           {
  -          if (null == tracer)
  -            tracer = new PrintTraceListener(diagnosticsWriter);
  +          if (!useXSLTC)
  +          {
  +            if (null == tracer)
  +              tracer = new PrintTraceListener(diagnosticsWriter);
   
  -          tracer.m_traceTemplates = true;
  +            tracer.m_traceTemplates = true;
  +          }
  +          else
  +            printInvalidXSLTCOption("-TT");
   
             // tfactory.setTraceTemplates(true);
           }
           else if ("-TG".equalsIgnoreCase(argv[i]))
           {
  -          if (null == tracer)
  -            tracer = new PrintTraceListener(diagnosticsWriter);
  +          if (!useXSLTC)
  +          {
  +            if (null == tracer)
  +              tracer = new PrintTraceListener(diagnosticsWriter);
   
  -          tracer.m_traceGeneration = true;
  +            tracer.m_traceGeneration = true;
  +          }
  +          else
  +            printInvalidXSLTCOption("-TG");
   
             // tfactory.setTraceSelect(true);
           }
           else if ("-TS".equalsIgnoreCase(argv[i]))
           {
  -          if (null == tracer)
  -            tracer = new PrintTraceListener(diagnosticsWriter);
  +          if (!useXSLTC)
  +          {
  +            if (null == tracer)
  +              tracer = new PrintTraceListener(diagnosticsWriter);
   
  -          tracer.m_traceSelection = true;
  +            tracer.m_traceSelection = true;
  +          }
  +          else
  +            printInvalidXSLTCOption("-TS");
   
             // tfactory.setTraceTemplates(true);
           }
           else if ("-TTC".equalsIgnoreCase(argv[i]))
           {
  -          if (null == tracer)
  -            tracer = new PrintTraceListener(diagnosticsWriter);
  +          if (!useXSLTC)
  +          {
  +            if (null == tracer)
  +              tracer = new PrintTraceListener(diagnosticsWriter);
   
  -          tracer.m_traceElements = true;
  +            tracer.m_traceElements = true;
  +          }
  +          else
  +            printInvalidXSLTCOption("-TTC");
   
             // tfactory.setTraceTemplateChildren(true);
           }
  @@ -361,20 +401,6 @@
                   XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
                   new Object[]{ "-PARAM" }));  //"Missing argument for);
           }
  -        else if ("-TREEDUMP".equalsIgnoreCase(argv[i]))  // sc 28-Feb-01 appears to be unused; can we remove?
  -        {
  -          if (i + 1 < argv.length)
  -            treedumpFileName = argv[++i];
  -          else
  -            System.err.println(
  -              XSLMessages.createMessage(
  -                XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
  -                new Object[]{ "-treedump" }));  //"Missing argument for);
  -        }
  -        else if ("-F".equalsIgnoreCase(argv[i]))  // sc 28-Feb-01 appears to be unused; can we remove?
  -        {
  -          formatOutput = true;
  -        }
           else if ("-E".equalsIgnoreCase(argv[i]))
           {
   
  @@ -391,29 +417,15 @@
           }
           else if ("-QC".equalsIgnoreCase(argv[i]))
           {
  -          quietConflictWarnings = true;
  +          if (!useXSLTC)
  +            quietConflictWarnings = true;
  +          else
  +            printInvalidXSLTCOption("-QC");
           }
           else if ("-Q".equalsIgnoreCase(argv[i]))
           {
             setQuietMode = true;
           }
  -
  -        /*
  -        else if("-VALIDATE".equalsIgnoreCase(argv[i]))
  -        {
  -          String shouldValidate;
  -          if(((i+1) < argv.length) && (argv[i+1].charAt(0) != '-'))
  -          {
  -            shouldValidate = argv[++i];
  -          }
  -          else
  -          {
  -            shouldValidate = "yes";
  -          }
  -
  -          // xmlProcessorLiaison.setUseValidation(shouldValidate.equalsIgnoreCase("yes"));
  -        }
  -        */
           else if ("-DIAG".equalsIgnoreCase(argv[i]))
           {
             doDiag = true;
  @@ -523,12 +535,20 @@
             }
           }
           else if ("-L".equalsIgnoreCase(argv[i]))
  -          useSourceLocation = true;
  +        {
  +          if (!useXSLTC)
  +            useSourceLocation = true;
  +          else
  +            printInvalidXSLTCOption("-L");
  +        }
           else if ("-INCREMENTAL".equalsIgnoreCase(argv[i]))
           {
  -          tfactory.setAttribute
  -            ("http://xml.apache.org/xalan/features/incremental", 
  -             java.lang.Boolean.TRUE);
  +          if (!useXSLTC)
  +            tfactory.setAttribute
  +              ("http://xml.apache.org/xalan/features/incremental", 
  +               java.lang.Boolean.TRUE);
  +          else
  +            printInvalidXSLTCOption("-INCREMENTAL");
           }
           else if ("-NOOPTIMIZE".equalsIgnoreCase(argv[i]))
           {
  @@ -537,19 +557,32 @@
             // %REVIEW% We should have a generalized syntax for negative
             // switches...  and probably should accept the inverse even
             // if it is the default.
  -          tfactory.setAttribute
  -            ("http://xml.apache.org/xalan/features/optimize", 
  -             java.lang.Boolean.FALSE);
  +          if (!useXSLTC)
  +            tfactory.setAttribute
  +              ("http://xml.apache.org/xalan/features/optimize", 
  +               java.lang.Boolean.FALSE);
  +          else
  +            printInvalidXSLTCOption("-NOOPTIMIZE");
   	}
           else if ("-RL".equalsIgnoreCase(argv[i]))
           {
  -          if (i + 1 < argv.length)
  -            recursionLimit = Integer.parseInt(argv[++i]);
  +          if (!useXSLTC)
  +          {
  +            if (i + 1 < argv.length)
  +              recursionLimit = Integer.parseInt(argv[++i]);
  +            else
  +              System.err.println(
  +                XSLMessages.createMessage(
  +                  XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
  +                  new Object[]{ "-rl" }));  //"Missing argument for);
  +          }
             else
  -            System.err.println(
  -              XSLMessages.createMessage(
  -                XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
  -                new Object[]{ "-rl" }));  //"Missing argument for);
  +          {
  +            if (i + 1 < argv.length)
  +             i++;
  +             
  +            printInvalidXSLTCOption("-RL");
  +          }
           }
   
           else
  @@ -620,7 +653,7 @@
           SAXTransformerFactory stf = (SAXTransformerFactory) tfactory;
           
   		// This is currently controlled via TransformerFactoryImpl.
  -        if (useSourceLocation)
  +        if (!useXSLTC && useSourceLocation)
              stf.setAttribute(XalanProperties.SOURCE_LOCATION, Boolean.TRUE);        
   
           // Did they pass in a stylesheet, or should we get it from the 
  @@ -766,8 +799,9 @@
                   reader = XMLReaderFactory.createXMLReader();
                 }
                 
  -              stf.setAttribute(org.apache.xalan.processor.TransformerFactoryImpl.FEATURE_INCREMENTAL, 
  -                 Boolean.TRUE);
  +              if (!useXSLTC)
  +                stf.setAttribute(org.apache.xalan.processor.TransformerFactoryImpl.FEATURE_INCREMENTAL, 
  +                   Boolean.TRUE);
                    
                 TransformerHandler th = stf.newTransformerHandler(stylesheet);
                 
  @@ -798,36 +832,8 @@
                 
                 th.setResult(strResult);
                 
  -              // System.out.println("sending parse events to the handler...");
  -              // for (int i = 0; i < 50; i++) 
  -              {
  -// System.out.print(".");
  -// if((i % 50) == 0)
  -//   System.out.println("");
  -                reader.parse(new InputSource(inFileName));
  -                // Transformer t = ((org.apache.xalan.transformer.TransformerHandlerImpl)th).getTransformer();
  -                // System.err.println("Calling reset");
  -                // ((TransformerImpl)t).reset();
  -              }
  -              
  -              
  -
  -//              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)),
  -//                  strResult);
  -//              }
  -
  -              // ===============
  -              }
  +              reader.parse(new InputSource(inFileName));
  +              }                            
               }
               else
               {
  @@ -983,6 +989,14 @@
      * */
     static void doExit(int i)
     {
  -          System.exit(i);
  +    System.exit(i);
  +  }
  +  
  +  /**
  +   * Print a message if an option cannot be used with -XSLTC.
  +   */
  +  private static void printInvalidXSLTCOption(String option)
  +  {
  +    System.err.println(XSLMessages.createMessage("invalid_xsltc_option", new Object[]{option}));
     }
   }
  
  
  
  1.10      +2 -0      xml-xalan/java/src/org/apache/xalan/res/XSLTErrorResources.properties
  
  Index: XSLTErrorResources.properties
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/res/XSLTErrorResources.properties,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- XSLTErrorResources.properties	29 Jul 2002 18:47:00 -0000	1.9
  +++ XSLTErrorResources.properties	18 Sep 2002 16:54:24 -0000	1.10
  @@ -596,6 +596,8 @@
   column=Column \u0023
   xsldone=XSLProcessor\u003a done
   xslProc_option=Xalan-J command line Process class options\u003a
  +invalid_xsltc_option=The option {0} is not supported in XSLTC mode
  +optionXSLTC=    [-XSLTC (use XSLTC for transformation)]
   optionIN=    -IN inputXMLURL
   optionXSL=   [-XSL XSLTransformationURL]
   optionOUT=   [-OUT outputFileName]
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org