Package javax.xml.transform

Examples of javax.xml.transform.TransformerConfigurationException


  // Pass messages to listener, one by one
  final int count = messages.size();
  for (int pos = 0; pos < count; pos++) {
      String message = messages.elementAt(pos).toString();
      _errorListener.error(
    new TransformerConfigurationException(message));
  }
    }
View Full Code Here


             
          return new TemplatesImpl(translet, transletName, null, _indentNumber, this);
      }
      catch (ClassNotFoundException cnfe) {
          ErrorMsg err = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, transletName);
          throw new TransformerConfigurationException(err.toString());
      }
      catch (Exception e) {
          ErrorMsg err = new ErrorMsg(ErrorMsg.getTransletErrorMessage() + e.getMessage());
          throw new TransformerConfigurationException(err.toString());
      }
  }
 
  // If _autoTranslet is true, we will try to load the bytecodes
  // from the translet classes without compiling the stylesheet.
  if (_autoTranslet)  {
      byte[][] bytecodes = null;
      String transletClassName = getTransletBaseName(source);
     
      if (_packageName != null)
          transletClassName = _packageName + "." + transletClassName;
     
      if (_jarFileName != null)
        bytecodes = getBytecodesFromJar(source, transletClassName);
      else
        bytecodes = getBytecodesFromClasses(source, transletClassName);     
   
      if (bytecodes != null) {
        if (_debug) {
              if (_jarFileName != null)
            System.err.println(new ErrorMsg(
                    ErrorMsg.TRANSFORM_WITH_JAR_STR, transletClassName, _jarFileName));
              else
                System.err.println(new ErrorMsg(
                    ErrorMsg.TRANSFORM_WITH_TRANSLET_STR, transletClassName));
        }

        // Reset the per-session attributes to their default values
        // after each newTemplates() call.
        resetTransientAttributes();
     
        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) {
      // 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,
      xsltc.getOutputProperties(), _indentNumber, this);
    }
View Full Code Here

                try {
                _errorListener.fatalError(e1);
                return null;
          }
    catch (TransformerException e2) {
                new TransformerConfigurationException(e2);
          }
            }
            throw e1;
      }
    }
View Full Code Here

        input = new InputSource(systemId);
    }
      }
      else {
    ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNKNOWN_SOURCE_ERR);
    throw new TransformerConfigurationException(err.toString());
      }
      input.setSystemId(systemId);
  }
  catch (NullPointerException e) {
       ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_SOURCE_ERR,
          "TransformerFactory.newTemplates()");
      throw new TransformerConfigurationException(err.toString());
  }
  catch (SecurityException e) {
       ErrorMsg err = new ErrorMsg(ErrorMsg.FILE_ACCESS_ERR, systemId);
      throw new TransformerConfigurationException(err.toString());
  }
  finally {
      return input;
  }
    }
View Full Code Here

                try {
                    errorListener.fatalError(e1);
                    return null;
                }
                catch( TransformerException e2) {
                    new TransformerConfigurationException(e2);
                }
            }
            throw e1;
        }
    }
View Full Code Here

    private void defineTransletClasses()
  throws TransformerConfigurationException {

  if (_bytecodes == null) {
      ErrorMsg err = new ErrorMsg(ErrorMsg.NO_TRANSLET_CLASS_ERR);
      throw new TransformerConfigurationException(err.toString());
  }

  TransletClassLoader loader =
      (TransletClassLoader) AccessController.doPrivileged(
    new PrivilegedAction() {
      public Object run() {
          /*
           * Get the loader from the current thread instead of
           * the class. This is important for translets that load
           * external Java classes and run in multi-threaded envs.
           */
          return new TransletClassLoader(
        Thread.currentThread().getContextClassLoader());
      }
        }
    );

  try {
      final int classCount = _bytecodes.length;
      _class = new Class[classCount];

      for (int i = 0; i < classCount; i++) {
    _class[i] = loader.defineClass(_bytecodes[i]);
    final Class superClass = _class[i].getSuperclass();

    // Check if this is the main class
    if (superClass.getName().equals(ABSTRACT_TRANSLET)) {
        _transletIndex = i;
    }
      }

      if (_transletIndex < 0) {
    ErrorMsg err= new ErrorMsg(ErrorMsg.NO_MAIN_TRANSLET_ERR, _name);
    throw new TransformerConfigurationException(err.toString());
      }
  }
  catch (ClassFormatError e) {
      ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_CLASS_ERR, _name);
      throw new TransformerConfigurationException(err.toString());
  }
  catch (LinkageError e) {
      ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_OBJECT_ERR, _name);
      throw new TransformerConfigurationException(err.toString());
  }
    }
View Full Code Here

      }
      return translet;
  }
  catch (InstantiationException e) {
      ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_OBJECT_ERR, _name);
      throw new TransformerConfigurationException(err.toString());
  }
  catch (IllegalAccessException e) {
      ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_OBJECT_ERR, _name);
      throw new TransformerConfigurationException(err.toString());
  }
    }
View Full Code Here

        {
          throw ex;
        }
        catch (TransformerException ex)
        {
          throw new TransformerConfigurationException(ex);
        }

        return null;
      }
      else
      {

        // Should remove this later... but right now diagnostics from
        // TransformerConfigurationException are not good.
        // se.printStackTrace();
        throw new TransformerConfigurationException(XSLMessages.createMessage(XSLTErrorResources.ER_PROCESSFROMNODE_FAILED, null), se);
        //"processFromNode failed", se);
      }
    }
    catch (TransformerConfigurationException tce)
    {
      // Assume it's already been reported to the error listener.
      throw tce;
    }
   /* catch (TransformerException tce)
    {
      // Assume it's already been reported to the error listener.
      throw new TransformerConfigurationException(tce.getMessage(), tce);
    }*/
    catch (Exception e)
    {
      if (m_errorListener != null)
      {
        try
        {
          m_errorListener.fatalError(new TransformerException(e));
        }
        catch (TransformerConfigurationException ex)
        {
          throw ex;
        }
        catch (TransformerException ex)
        {
          throw new TransformerConfigurationException(ex);
        }

        return null;
      }
      else
      {
        // Should remove this later... but right now diagnostics from
        // TransformerConfigurationException are not good.
        // se.printStackTrace();
        throw new TransformerConfigurationException(XSLMessages.createMessage(XSLTErrorResources.ER_PROCESSFROMNODE_FAILED, null), e); //"processFromNode failed",
                                                    //e);
      }
    }
  }
View Full Code Here

      // OK, good.
    }
    catch (org.xml.sax.SAXException se)
    {
      throw new TransformerConfigurationException(
        "getAssociatedStylesheets failed", se);
    }
    catch (IOException ioe)
    {
      throw new TransformerConfigurationException(
        "getAssociatedStylesheets failed", ioe);
    }

    return handler.getAssociatedStylesheet();
  }
View Full Code Here

    }
    // This implementation does not support the setting of a feature other than
    // the secure processing feature.
    else
    {
      throw new TransformerConfigurationException(
          XSLMessages.createMessage(
            XSLTErrorResources.ER_UNSUPPORTED_FEATURE,
            new Object[] {name}));
    }
  }
View Full Code Here

TOP

Related Classes of javax.xml.transform.TransformerConfigurationException

Copyright © 2018 www.massapicom. 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.