Examples of XSLTC


Examples of org.apache.xalan.xsltc.compiler.XSLTC

        return new TemplatesImpl(bytecodes, transletClassName, null, _indentNumber, this);     
      }
  }
 
  // Create and initialize a stylesheet compiler
  final XSLTC xsltc = new XSLTC();
  if (_debug) xsltc.setDebug(true);
  if (_enableInlining) xsltc.setTemplateInlining(true);
  xsltc.init();

  // Set a document loader (for xsl:include/import) if defined
  if (_uriResolver != null) {
      xsltc.setSourceLoader(this);
  }

  // Pass parameters to the Parser to make sure it locates the correct
  // <?xml-stylesheet ...?> PI in an XML input document
  if ((_piParams != null) && (_piParams.get(source) != null)) {
      // Get the parameters for this Source object
      PIParamWrapper p = (PIParamWrapper)_piParams.get(source);
      // Pass them on to the compiler (which will pass then to the parser)
      if (p != null) {
    xsltc.setPIParameters(p._media, p._title, p._charset);
      }
  }

  // Set the attributes for translet generation
  int outputType = XSLTC.BYTEARRAY_OUTPUT;
  if (_generateTranslet || _autoTranslet) {
      // Set the translet name
      xsltc.setClassName(getTransletBaseName(source));
   
      if (_destinationDirectory != null)
        xsltc.setDestDirectory(_destinationDirectory);
      else {
        String xslName = getStylesheetFileName(source);
        if (xslName != null) {
              File xslFile = new File(xslName);
              String xslDir = xslFile.getParent();
     
              if (xslDir != null)
                  xsltc.setDestDirectory(xslDir);
        }
      }
   
      if (_packageName != null)
          xsltc.setPackageName(_packageName);
 
      if (_jarFileName != null) {
        xsltc.setJarFileName(_jarFileName);
        outputType = XSLTC.BYTEARRAY_AND_JAR_OUTPUT;
      }
      else
        outputType = XSLTC.BYTEARRAY_AND_FILE_OUTPUT;
  }

  // Compile the stylesheet
  final InputSource input = Util.getInputSource(xsltc, source);
  byte[][] bytecodes = xsltc.compile(null, input, outputType);
  final String transletName = xsltc.getClassName();

  // Output to the jar file if the jar file name is set.
  if ((_generateTranslet || _autoTranslet)
       && bytecodes != null && _jarFileName != null) {
      try {
        xsltc.outputToJar();
      }
      catch (java.io.IOException e) { }
  }

  // Reset the per-session attributes to their default values
  // after each newTemplates() call.
  resetTransientAttributes();

  // Pass compiler warnings to the error listener
  if (_errorListener != this) {
      try {
    passWarningsToListener(xsltc.getWarnings());
      }
      catch (TransformerException e) {
    throw new TransformerConfigurationException(e);
      }
  }
  else {
      xsltc.printWarnings();
  }

  // Check that the transformation went well before returning
    if (bytecodes == null) {
       
        ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR);
        TransformerConfigurationException exc =  new TransformerConfigurationException(err.toString());
       
        // Pass compiler errors to the error listener
        if (_errorListener != null) {
            passErrorsToListener(xsltc.getErrors());
           
            // As required by TCK 1.2, send a fatalError to the
            // error listener because compilation of the stylesheet
            // failed and no further processing will be possible.
            try {
                _errorListener.fatalError(exc);
            } catch (TransformerException te) {
                // well, we tried.
            }   
        }
        else {
            xsltc.printErrors();
        }
        throw exc;
    }

  return new TemplatesImpl(bytecodes, transletName,
      xsltc.getOutputProperties(), _indentNumber, this);
    }
View Full Code Here

Examples of org.apache.xalan.xsltc.compiler.XSLTC

        return new TemplatesImpl(bytecodes, transletClassName, null, _indentNumber, this);     
      }
  }
 
  // Create and initialize a stylesheet compiler
  final XSLTC xsltc = new XSLTC();
  if (_debug) xsltc.setDebug(true);
  if (_enableInlining) xsltc.setTemplateInlining(true);
  xsltc.init();

  // Set a document loader (for xsl:include/import) if defined
  if (_uriResolver != null) {
      xsltc.setSourceLoader(this);
  }

  // Pass parameters to the Parser to make sure it locates the correct
  // <?xml-stylesheet ...?> PI in an XML input document
  if ((_piParams != null) && (_piParams.get(source) != null)) {
      // Get the parameters for this Source object
      PIParamWrapper p = (PIParamWrapper)_piParams.get(source);
      // Pass them on to the compiler (which will pass then to the parser)
      if (p != null) {
    xsltc.setPIParameters(p._media, p._title, p._charset);
      }
  }

  // Set the attributes for translet generation
  int outputType = XSLTC.BYTEARRAY_OUTPUT;
  if (_generateTranslet || _autoTranslet) {
      // Set the translet name
      xsltc.setClassName(getTransletBaseName(source));
   
      if (_destinationDirectory != null)
        xsltc.setDestDirectory(_destinationDirectory);
      else {
        String xslName = getStylesheetFileName(source);
        if (xslName != null) {
              File xslFile = new File(xslName);
              String xslDir = xslFile.getParent();
     
              if (xslDir != null)
                  xsltc.setDestDirectory(xslDir);
        }
      }
   
      if (_packageName != null)
          xsltc.setPackageName(_packageName);
 
      if (_jarFileName != null) {
        xsltc.setJarFileName(_jarFileName);
        outputType = XSLTC.BYTEARRAY_AND_JAR_OUTPUT;
      }
      else
        outputType = XSLTC.BYTEARRAY_AND_FILE_OUTPUT;
  }

  // Compile the stylesheet
  final InputSource input = Util.getInputSource(xsltc, source);
  byte[][] bytecodes = xsltc.compile(null, input, outputType);
  final String transletName = xsltc.getClassName();

  // Output to the jar file if the jar file name is set.
  if ((_generateTranslet || _autoTranslet)
       && bytecodes != null && _jarFileName != null) {
      try {
        xsltc.outputToJar();
      }
      catch (java.io.IOException e) { }
  }

  // Reset the per-session attributes to their default values
  // after each newTemplates() call.
  resetTransientAttributes();

  // Pass compiler warnings to the error listener
  if (_errorListener != this) {
      try {
    passWarningsToListener(xsltc.getWarnings());
      }
      catch (TransformerException e) {
    throw new TransformerConfigurationException(e);
      }
  }
  else {
      xsltc.printWarnings();
  }

  // Check that the transformation went well before returning
    if (bytecodes == null) {
       
        ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR);
        TransformerConfigurationException exc =  new TransformerConfigurationException(err.toString());
       
        // Pass compiler errors to the error listener
        if (_errorListener != null) {
            passErrorsToListener(xsltc.getErrors());
           
            // As required by TCK 1.2, send a fatalError to the
            // error listener because compilation of the stylesheet
            // failed and no further processing will be possible.
            try {
                _errorListener.fatalError(exc);
            } catch (TransformerException te) {
                // well, we tried.
            }   
        }
        else {
            xsltc.printErrors();
        }
        throw exc;
    }

  return new TemplatesImpl(bytecodes, transletName,
      xsltc.getOutputProperties(), _indentNumber, this);
    }
View Full Code Here

Examples of org.apache.xalan.xsltc.compiler.XSLTC

    {
  _indentNumber = indentNumber;
  _tfactory = tfactory;

        // Instantiate XSLTC and get reference to parser object
        _parser = new XSLTC().getParser();
    }
View Full Code Here

Examples of org.apache.xalan.xsltc.compiler.XSLTC

    /**
     * Re-initialize parser and forward SAX2 event.
     */
    public void startDocument() {
        XSLTC xsltc = _parser.getXSLTC();
        xsltc.init();   // calls _parser.init()
        xsltc.setOutputType(XSLTC.BYTEARRAY_OUTPUT);
        _parser.startDocument();
    }
View Full Code Here

Examples of org.apache.xalan.xsltc.compiler.XSLTC

    public void endDocument() throws SAXException {
        _parser.endDocument();

        // create the templates
        try {
            XSLTC xsltc = _parser.getXSLTC();

            // Set the translet class name if not already set
            String transletName = null;
            if (_systemId != null) {
                transletName = Util.baseName(_systemId);
            }
            else {
                transletName = (String)_tfactory.getAttribute("translet-name");
            }
            xsltc.setClassName(transletName);

            // Get java-legal class name from XSLTC module
            transletName = xsltc.getClassName();

            Stylesheet stylesheet = null;
            SyntaxTreeNode root = _parser.getDocumentRoot();

            // Compile the translet - this is where the work is done!
            if (!_parser.errorsFound() && root != null) {
                // Create a Stylesheet element from the root node
                stylesheet = _parser.makeStylesheet(root);
                stylesheet.setSystemId(_systemId);
                stylesheet.setParentStylesheet(null);

                // Set a document loader (for xsl:include/import) if defined
                if (_uriResolver != null) {
                    stylesheet.setSourceLoader(this);
                }

                _parser.setCurrentStylesheet(stylesheet);

                // Set it as top-level in the XSLTC object
                xsltc.setStylesheet(stylesheet);

                // Create AST under the Stylesheet element
                _parser.createAST(stylesheet);
            }

            // Generate the bytecodes and output the translet class(es)
            if (!_parser.errorsFound() && stylesheet != null) {
                stylesheet.setMultiDocument(xsltc.isMultiDocument());
                stylesheet.setHasIdCall(xsltc.hasIdCall());

                // Class synchronization is needed for BCEL
                synchronized (xsltc.getClass()) {
                    stylesheet.translate();
                }
            }

            if (!_parser.errorsFound()) {
                // Check that the transformation went well before returning
                final byte[][] bytecodes = xsltc.getBytecodes();
                if (bytecodes != null) {
                    _templates =
                    new TemplatesImpl(xsltc.getBytecodes(), transletName,
                        _parser.getOutputProperties(), _indentNumber, _tfactory);

                    // Set URIResolver on templates object
                    if (_uriResolver != null) {
                        _templates.setURIResolver(_uriResolver);
View Full Code Here

Examples of org.apache.xalan.xsltc.compiler.XSLTC

      boolean useStdIn = false;
      boolean classNameSet = false;
      final GetOpt getopt = new GetOpt(args, "o:d:j:p:uxhsinv");
      if (args.length < 1) printUsage();

      final XSLTC xsltc = new XSLTC();
      xsltc.init();

      int c;
      while ((c = getopt.getNextOption()) != -1) {
    switch(c) {
    case 'i':
        useStdIn = true;
        break;
    case 'o':
        xsltc.setClassName(getopt.getOptionArg());
        classNameSet = true;
        break;
    case 'd':
        xsltc.setDestDirectory(getopt.getOptionArg());
        break;
    case 'p':
        xsltc.setPackageName(getopt.getOptionArg());
        break;
    case 'j'
        xsltc.setJarFileName(getopt.getOptionArg());
        break;
    case 'x':
        xsltc.setDebug(true);
        break;
    case 'u':
        inputIsURL = true;
        break;
    case 's':
        _allowExit = false;
        break;
    case 'n':
        xsltc.setTemplateInlining(true)// used to be 'false'
        break;
    case 'v':
        // fall through to case h
    case 'h':
    default:
        printUsage();
        break;
    }
      }

      boolean compileOK;

      if (useStdIn) {
    if (!classNameSet) {
        System.err.println(new ErrorMsg(ErrorMsg.COMPILE_STDIN_ERR));
        if (_allowExit) System.exit(-1);
    }
    compileOK = xsltc.compile(System.in, xsltc.getClassName());
      }
      else {
    // Generate a vector containg URLs for all stylesheets specified
    final String[] stylesheetNames = getopt.getCmdArgs();
    final Vector   stylesheetVector = new Vector();
    for (int i = 0; i < stylesheetNames.length; i++) {
        final String name = stylesheetNames[i];
        URL url;
        if (inputIsURL)
      url = new URL(name);
        else
      url = (new File(name)).toURL();
        stylesheetVector.addElement(url);
    }
    compileOK = xsltc.compile(stylesheetVector);
      }

      // Compile the stylesheet and output class/jar file(s)
      if (compileOK) {
    xsltc.printWarnings();
    if (xsltc.getJarFileName() != null) xsltc.outputToJar();
    if (_allowExit) System.exit(0);
      }
      else {
    xsltc.printWarnings();
    xsltc.printErrors();
    if (_allowExit) System.exit(-1);
      }
  }
  catch (GetOptsException ex) {
      System.err.println(ex);
View Full Code Here

Examples of org.apache.xalan.xsltc.compiler.XSLTC

      if (_uriResolver != null)
    _copyTransformer.setURIResolver(_uriResolver);
      return _copyTransformer;
  }

  XSLTC xsltc = new XSLTC();
  if (_debug) xsltc.setDebug(true);
  xsltc.init();

  // Compile the default copy-stylesheet
  byte[] bytes = COPY_TRANSLET_CODE.getBytes();
  ByteArrayInputStream bytestream = new ByteArrayInputStream(bytes);
  InputSource input = new InputSource(bytestream);
  input.setSystemId(_defaultTransletName);
  byte[][] bytecodes = xsltc.compile(_defaultTransletName, input);

  // Check that the transformation went well before returning
  if (bytecodes == null) {
      ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR);
      throw new TransformerConfigurationException(err.toString());
View Full Code Here

Examples of org.apache.xalan.xsltc.compiler.XSLTC

     */
    public Templates newTemplates(Source source)
  throws TransformerConfigurationException {

  // Create and initialize a stylesheet compiler
  final XSLTC xsltc = new XSLTC();
  if (_debug) xsltc.setDebug(true);
  xsltc.init();

  // Set a document loader (for xsl:include/import) if defined
  if (_uriResolver != null) xsltc.setSourceLoader(this);

  // Pass parameters to the Parser to make sure it locates the correct
  // <?xml-stylesheet ...?> PI in an XML input document
  if ((_piParams != null) && (_piParams.get(source) != null)) {
      // Get the parameters for this Source object
      PIParamWrapper p = (PIParamWrapper)_piParams.get(source);
      // Pass them on to the compiler (which will pass then to the parser)
      if (p != null)
    xsltc.setPIParameters(p._media, p._title, p._charset);
  }

  // Compile the stylesheet
  final InputSource input = getInputSource(xsltc, source);
  byte[][] bytecodes = xsltc.compile(null, input);
  final String transletName = xsltc.getClassName();

  // Pass compiler warnings to the error listener
  if (_errorListener != null)
      passWarningsToListener(xsltc.getWarnings());
  else
      xsltc.printWarnings();

  // Check that the transformation went well before returning
  if (bytecodes == null) {
      // Pass compiler errors to the error listener
      if (_errorListener != null)
    passErrorsToListener(xsltc.getErrors());
      else
    xsltc.printErrors();
      ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR);
      throw new TransformerConfigurationException(err.toString());
  }
  return(new TemplatesImpl(bytecodes, transletName));
    }
View Full Code Here

Examples of org.apache.xalan.xsltc.compiler.XSLTC

      boolean classNameSet = false;

      final GetOpt getopt = new GetOpt(args, "o:d:j:p:uxhsi");
      if (args.length < 1) printUsage();

      final XSLTC xsltc = new XSLTC();
      xsltc.init();

      int c;
      while ((c = getopt.getNextOption()) != -1) {
    switch(c) {
    case 'i':
        useStdIn = true;
        break;
    case 'o':
        xsltc.setClassName(getopt.getOptionArg());
        classNameSet = true;
        break;
    case 'd':
        xsltc.setDestDirectory(getopt.getOptionArg());
        break;
    case 'p':
        xsltc.setPackageName(getopt.getOptionArg());
        break;
    case 'j'
        xsltc.setJarFileName(getopt.getOptionArg());
        break;
    case 'x':
        xsltc.setDebug(true);
        break;
    case 'u':
        inputIsURL = true;
        break;
    case 's':
        _allowExit = false;
        break;
    case 'h':
    default:
        printUsage();
        break;
    }
      }

      boolean compileOK;

      if (useStdIn) {
    if (!classNameSet) {
        System.err.println(new ErrorMsg(ErrorMsg.COMPILE_STDIN_ERR));
        if (_allowExit) System.exit(-1);
    }
    compileOK = xsltc.compile(System.in, xsltc.getClassName());
      }
      else {
    // Generate a vector containg URLs for all stylesheets specified
    final String[] stylesheetNames = getopt.getCmdArgs();
    final Vector   stylesheetVector = new Vector();
    for (int i = 0; i < stylesheetNames.length; i++) {
        final String name = stylesheetNames[i];
        URL url;
        if (inputIsURL)
      url = new URL(name);
        else
      url = (new File(name)).toURL();
        stylesheetVector.addElement(url);
    }
    compileOK = xsltc.compile(stylesheetVector);
      }

      // Compile the stylesheet and output class/jar file(s)
      if (compileOK) {
    xsltc.printWarnings();
    if (xsltc.getJarFileName() != null) xsltc.outputToJar();
    if (_allowExit) System.exit(0);
      }
      else {
    xsltc.printWarnings();
    xsltc.printErrors();
    if (_allowExit) System.exit(-1);
      }
  }
  catch (GetOptsException ex) {
      System.err.println(ex);
View Full Code Here

Examples of org.apache.xalan.xsltc.compiler.XSLTC

      out.println("<h1>Compilation error</h1>");
      out.println("The parameter <b><tt>sheet</tt></b> "+
      "must be specified");
  }
  else {
      XSLTC xsltc = new XSLTC();

      xsltc.init();
      xsltc.compile(new URL(stylesheetName));
      out.println("<h1>Compilation successful</h1>");
      out.println("The stylesheet was compiled into the translet "+
      "class "+xsltc.getClassName() + " and is now "+
      "available for transformations on this server.");
  }
  out.println("</body></html>");
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.