Java Code Examples for com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg#toString()

The following examples show how to use com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransformerImpl.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Implements JAXP's Transformer.setParameter()
 * Add a parameter for the transformation. The parameter is simply passed
 * on to the translet - no validation is performed - so any unused
 * parameters are quitely ignored by the translet.
 *
 * @param name The name of the parameter
 * @param value The value to assign to the parameter
 */
@Override
public void setParameter(String name, Object value) {

    if (value == null) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_INVALID_SET_PARAM_VALUE, name);
        throw new IllegalArgumentException(err.toString());
    }

    if (_isIdentity) {
        if (_parameters == null) {
            _parameters = new HashMap<>();
        }
        _parameters.put(name, value);
    }
    else {
        _translet.addParameter(name, value);
    }
}
 
Example 2
Source File: TemplatesImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 *  Overrides the default readObject implementation since we decided
 *  it would be cleaner not to serialize the entire tranformer
 *  factory.  [ ref bugzilla 12317 ]
 *  We need to check if the user defined class for URIResolver also
 *  implemented Serializable
 *  if yes then we need to deserialize the URIResolver
 *  Fix for bugzilla bug 22438
 */
private void  readObject(ObjectInputStream is)
  throws IOException, ClassNotFoundException
{
    SecurityManager security = System.getSecurityManager();
    if (security != null){
        String temp = SecuritySupport.getSystemProperty(DESERIALIZE_TRANSLET);
        if (temp == null || !(temp.length()==0 || temp.equalsIgnoreCase("true"))) {
            ErrorMsg err = new ErrorMsg(ErrorMsg.DESERIALIZE_TRANSLET_ERR);
            throw new UnsupportedOperationException(err.toString());
        }
    }

    is.defaultReadObject();
    if (is.readBoolean()) {
        _uriResolver = (URIResolver) is.readObject();
    }

    _tfactory = new TransformerFactoryImpl();
}
 
Example 3
Source File: TransformerImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Implements JAXP's Transformer.setOutputProperties().
 * Set the output properties for the transformation. These properties
 * will override properties set in the Templates with xsl:output.
 * Unrecognised properties will be quitely ignored.
 *
 * @param properties The properties to use for the Transformer
 * @throws IllegalArgumentException Never, errors are ignored
 */
@Override
public void setOutputProperties(Properties properties)
    throws IllegalArgumentException
{
    if (properties != null) {
        final Enumeration names = properties.propertyNames();

        while (names.hasMoreElements()) {
            final String name = (String) names.nextElement();

            // Ignore lower layer properties
            if (isDefaultProperty(name, properties)) continue;

            if (validOutputProperty(name)) {
                _properties.setProperty(name, properties.getProperty(name));
            }
            else {
                ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNKNOWN_PROP_ERR, name);
                throw new IllegalArgumentException(err.toString());
            }
        }
    }
    else {
        _properties = _propertiesClone;
    }
}
 
Example 4
Source File: TransformerFactoryImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * javax.xml.transform.sax.TransformerFactory implementation.
 * Set the error event listener for the TransformerFactory, which is used
 * for the processing of transformation instructions, and not for the
 * transformation itself.
 *
 * @param listener The error listener to use with the TransformerFactory
 * @throws IllegalArgumentException
 */
@Override
public void setErrorListener(ErrorListener listener)
    throws IllegalArgumentException
{
    if (listener == null) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.ERROR_LISTENER_NULL_ERR,
                                    "TransformerFactory");
        throw new IllegalArgumentException(err.toString());
    }
    _hasUserErrListener = true;
    _errorListener = listener;
}
 
Example 5
Source File: Parser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create an instance of the <code>Stylesheet</code> class,
 * and then parse, typecheck and compile the instance.
 * Must be called after <code>parse()</code>.
 */
public Stylesheet makeStylesheet(SyntaxTreeNode element)
    throws CompilerException {
    try {
        Stylesheet stylesheet;

        if (element instanceof Stylesheet) {
            stylesheet = (Stylesheet)element;
        }
        else {
            stylesheet = new Stylesheet();
            stylesheet.setSimplified();
            stylesheet.addElement(element);
            stylesheet.setAttributes((AttributesImpl) element.getAttributes());

            // Map the default NS if not already defined
            if (element.lookupNamespace(EMPTYSTRING) == null) {
                element.addPrefixMapping(EMPTYSTRING, EMPTYSTRING);
            }
        }
        stylesheet.setParser(this);
        return stylesheet;
    }
    catch (ClassCastException e) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.NOT_STYLESHEET_ERR, element);
        throw new CompilerException(err.toString());
    }
}
 
Example 6
Source File: TemplatesImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Overrides the default readObject implementation since we decided
 *  it would be cleaner not to serialize the entire tranformer
 *  factory.  [ ref bugzilla 12317 ]
 *  We need to check if the user defined class for URIResolver also
 *  implemented Serializable
 *  if yes then we need to deserialize the URIResolver
 *  Fix for bugzilla bug 22438
 */
@SuppressWarnings("unchecked")
private void  readObject(ObjectInputStream is)
  throws IOException, ClassNotFoundException
{
    SecurityManager security = System.getSecurityManager();
    if (security != null){
        String temp = SecuritySupport.getSystemProperty(DESERIALIZE_TRANSLET);
        if (temp == null || !(temp.length()==0 || temp.equalsIgnoreCase("true"))) {
            ErrorMsg err = new ErrorMsg(ErrorMsg.DESERIALIZE_TRANSLET_ERR);
            throw new UnsupportedOperationException(err.toString());
        }
    }

    // We have to read serialized fields first.
    ObjectInputStream.GetField gf = is.readFields();
    _name = (String)gf.get("_name", null);
    _bytecodes = (byte[][])gf.get("_bytecodes", null);
    _class = (Class[])gf.get("_class", null);
    _transletIndex = gf.get("_transletIndex", -1);

    _outputProperties = (Properties)gf.get("_outputProperties", null);
    _indentNumber = gf.get("_indentNumber", 0);

    if (is.readBoolean()) {
        _uriResolver = (URIResolver) is.readObject();
    }

    _tfactory = new TransformerFactoryImpl();
}
 
Example 7
Source File: TransformerFactoryImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * javax.xml.transform.sax.TransformerFactory implementation.
 * Set the error event listener for the TransformerFactory, which is used
 * for the processing of transformation instructions, and not for the
 * transformation itself.
 *
 * @param listener The error listener to use with the TransformerFactory
 * @throws IllegalArgumentException
 */
@Override
public void setErrorListener(ErrorListener listener)
    throws IllegalArgumentException
{
    if (listener == null) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.ERROR_LISTENER_NULL_ERR,
                                    "TransformerFactory");
        throw new IllegalArgumentException(err.toString());
    }
    _errorListener = listener;
}
 
Example 8
Source File: Parser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create an instance of the <code>Stylesheet</code> class,
 * and then parse, typecheck and compile the instance.
 * Must be called after <code>parse()</code>.
 */
public Stylesheet makeStylesheet(SyntaxTreeNode element)
    throws CompilerException {
    try {
        Stylesheet stylesheet;

        if (element instanceof Stylesheet) {
            stylesheet = (Stylesheet)element;
        }
        else {
            stylesheet = new Stylesheet();
            stylesheet.setSimplified();
            stylesheet.addElement(element);
            stylesheet.setAttributes((AttributesImpl) element.getAttributes());

            // Map the default NS if not already defined
            if (element.lookupNamespace(EMPTYSTRING) == null) {
                element.addPrefixMapping(EMPTYSTRING, EMPTYSTRING);
            }
        }
        stylesheet.setParser(this);
        return stylesheet;
    }
    catch (ClassCastException e) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.NOT_STYLESHEET_ERR, element);
        throw new CompilerException(err.toString());
    }
}
 
Example 9
Source File: TransformerFactoryImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * javax.xml.transform.sax.TransformerFactory implementation.
 * Set the error event listener for the TransformerFactory, which is used
 * for the processing of transformation instructions, and not for the
 * transformation itself.
 *
 * @param listener The error listener to use with the TransformerFactory
 * @throws IllegalArgumentException
 */
@Override
public void setErrorListener(ErrorListener listener)
    throws IllegalArgumentException
{
    if (listener == null) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.ERROR_LISTENER_NULL_ERR,
                                    "TransformerFactory");
        throw new IllegalArgumentException(err.toString());
    }
    _errorListener = listener;
}
 
Example 10
Source File: Parser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create an instance of the <code>Stylesheet</code> class,
 * and then parse, typecheck and compile the instance.
 * Must be called after <code>parse()</code>.
 */
public Stylesheet makeStylesheet(SyntaxTreeNode element)
    throws CompilerException {
    try {
        Stylesheet stylesheet;

        if (element instanceof Stylesheet) {
            stylesheet = (Stylesheet)element;
        }
        else {
            stylesheet = new Stylesheet();
            stylesheet.setSimplified();
            stylesheet.addElement(element);
            stylesheet.setAttributes((AttributesImpl) element.getAttributes());

            // Map the default NS if not already defined
            if (element.lookupNamespace(EMPTYSTRING) == null) {
                element.addPrefixMapping(EMPTYSTRING, EMPTYSTRING);
            }
        }
        stylesheet.setParser(this);
        return stylesheet;
    }
    catch (ClassCastException e) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.NOT_STYLESHEET_ERR, element);
        throw new CompilerException(err.toString());
    }
}
 
Example 11
Source File: TemplatesImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * This method generates an instance of the translet class that is
 * wrapped inside this Template. The translet instance will later
 * be wrapped inside a Transformer object.
 */
private Translet getTransletInstance()
    throws TransformerConfigurationException {
    try {
        if (_name == null) return null;

        if (_class == null) defineTransletClasses();

        // The translet needs to keep a reference to all its auxiliary
        // class to prevent the GC from collecting them
        AbstractTranslet translet = (AbstractTranslet)
                _class[_transletIndex].getConstructor().newInstance();
        translet.postInitialization();
        translet.setTemplates(this);
        translet.setOverrideDefaultParser(_overrideDefaultParser);
        translet.setAllowedProtocols(_accessExternalStylesheet);
        if (_auxClasses != null) {
            translet.setAuxiliaryClasses(_auxClasses);
        }

        return translet;
    }
    catch (InstantiationException | IllegalAccessException |
            NoSuchMethodException | InvocationTargetException e) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_OBJECT_ERR, _name);
        throw new TransformerConfigurationException(err.toString(), e);
    }
}
 
Example 12
Source File: TransformerFactoryImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * javax.xml.transform.sax.TransformerFactory implementation.
 * Set the error event listener for the TransformerFactory, which is used
 * for the processing of transformation instructions, and not for the
 * transformation itself.
 *
 * @param listener The error listener to use with the TransformerFactory
 * @throws IllegalArgumentException
 */
@Override
public void setErrorListener(ErrorListener listener)
    throws IllegalArgumentException
{
    if (listener == null) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.ERROR_LISTENER_NULL_ERR,
                                    "TransformerFactory");
        throw new IllegalArgumentException(err.toString());
    }
    _errorListener = listener;
}
 
Example 13
Source File: SmartTransformerFactoryImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * javax.xml.transform.sax.TransformerFactory implementation.
 * Look up the value of a feature (to see if it is supported).
 * This method must be updated as the various methods and features of this
 * class are implemented.
 *
 * @param name The feature name
 * @return 'true' if feature is supported, 'false' if not
 */
public boolean getFeature(String name) {
    // All supported features should be listed here
    String[] features = {
        DOMSource.FEATURE,
        DOMResult.FEATURE,
        SAXSource.FEATURE,
        SAXResult.FEATURE,
        StreamSource.FEATURE,
        StreamResult.FEATURE
    };

    // feature name cannot be null
    if (name == null) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_GET_FEATURE_NULL_NAME);
        throw new NullPointerException(err.toString());
    }

    // Inefficient, but it really does not matter in a function like this
    for (int i = 0; i < features.length; i++) {
        if (name.equals(features[i]))
            return true;
    }

    // secure processing?
    if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
        return featureSecureProcessing;
    }

    // unknown feature
    return false;
}
 
Example 14
Source File: TransformerImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Implements JAXP's Transformer.setOutputProperty().
 * Get an output property that is in effect for the transformation. The
 * property specified may be a property that was set with
 * setOutputProperty(), or it may be a property specified in the stylesheet.
 *
 * @param name The name of the property to set
 * @param value The value to assign to the property
 * @throws IllegalArgumentException Never, errors are ignored
 */
@Override
public void setOutputProperty(String name, String value)
    throws IllegalArgumentException
{
    if (!validOutputProperty(name)) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNKNOWN_PROP_ERR, name);
        throw new IllegalArgumentException(err.toString());
    }
    _properties.setProperty(name, value);
}
 
Example 15
Source File: TransformerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Implements JAXP's Transformer.setErrorListener()
 * Set the error event listener in effect for the transformation.
 * Register a message handler in the translet in order to forward
 * xsl:messages to error listener.
 *
 * @param listener The error event listener to use
 * @throws IllegalArgumentException
 */
@Override
public void setErrorListener(ErrorListener listener)
    throws IllegalArgumentException {
    if (listener == null) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.ERROR_LISTENER_NULL_ERR,
                                    "Transformer");
        throw new IllegalArgumentException(err.toString());
    }
    _errorListener = listener;

    // Register a message handler to report xsl:messages
if (_translet != null)
    _translet.setMessageHandler(new MessageHandler(_errorListener));
}
 
Example 16
Source File: TransformerFactoryImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * javax.xml.transform.sax.TransformerFactory implementation.
 * Set the error event listener for the TransformerFactory, which is used
 * for the processing of transformation instructions, and not for the
 * transformation itself.
 *
 * @param listener The error listener to use with the TransformerFactory
 * @throws IllegalArgumentException
 */
@Override
public void setErrorListener(ErrorListener listener)
    throws IllegalArgumentException
{
    if (listener == null) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.ERROR_LISTENER_NULL_ERR,
                                    "TransformerFactory");
        throw new IllegalArgumentException(err.toString());
    }
    _errorListener = listener;
}
 
Example 17
Source File: TransformerImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Implements JAXP's Transformer.setOutputProperty().
 * Get an output property that is in effect for the transformation. The
 * property specified may be a property that was set with
 * setOutputProperty(), or it may be a property specified in the stylesheet.
 *
 * @param name The name of the property to set
 * @param value The value to assign to the property
 * @throws IllegalArgumentException Never, errors are ignored
 */
@Override
public void setOutputProperty(String name, String value)
    throws IllegalArgumentException
{
    if (!validOutputProperty(name)) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNKNOWN_PROP_ERR, name);
        throw new IllegalArgumentException(err.toString());
    }
    _properties.setProperty(name, value);
}
 
Example 18
Source File: FunctionCall.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute the JVM signature for the class.
 */
static final String getSignature(Class clazz) {
    if (clazz.isArray()) {
        final StringBuffer sb = new StringBuffer();
        Class cl = clazz;
        while (cl.isArray()) {
            sb.append("[");
            cl = cl.getComponentType();
        }
        sb.append(getSignature(cl));
        return sb.toString();
    }
    else if (clazz.isPrimitive()) {
        if (clazz == Integer.TYPE) {
            return "I";
        }
        else if (clazz == Byte.TYPE) {
            return "B";
        }
        else if (clazz == Long.TYPE) {
            return "J";
        }
        else if (clazz == Float.TYPE) {
            return "F";
        }
        else if (clazz == Double.TYPE) {
            return "D";
        }
        else if (clazz == Short.TYPE) {
            return "S";
        }
        else if (clazz == Character.TYPE) {
            return "C";
        }
        else if (clazz == Boolean.TYPE) {
            return "Z";
        }
        else if (clazz == Void.TYPE) {
            return "V";
        }
        else {
            final String name = clazz.toString();
            ErrorMsg err = new ErrorMsg(ErrorMsg.UNKNOWN_SIG_TYPE_ERR,name);
            throw new Error(err.toString());
        }
    }
    else {
        return "L" + clazz.getName().replace('.', '/') + ';';
    }
}
 
Example 19
Source File: TransformerFactoryImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * javax.xml.transform.sax.TransformerFactory implementation.
 * Returns the value set for a TransformerFactory attribute
 *
 * @param name The attribute name
 * @return An object representing the attribute value
 * @throws IllegalArgumentException
 */
@Override
public Object getAttribute(String name)
    throws IllegalArgumentException
{
    // Return value for attribute 'translet-name'
    if (name.equals(TRANSLET_NAME)) {
        return _transletName;
    }
    else if (name.equals(GENERATE_TRANSLET)) {
        return new Boolean(_generateTranslet);
    }
    else if (name.equals(AUTO_TRANSLET)) {
        return new Boolean(_autoTranslet);
    }
    else if (name.equals(ENABLE_INLINING)) {
        if (_enableInlining)
          return Boolean.TRUE;
        else
          return Boolean.FALSE;
    } else if (name.equals(XalanConstants.SECURITY_MANAGER)) {
        return _xmlSecurityManager;
    }

    /** Check to see if the property is managed by the security manager **/
    String propertyValue = (_xmlSecurityManager != null) ?
            _xmlSecurityManager.getLimitAsString(name) : null;
    if (propertyValue != null) {
        return propertyValue;
    } else {
        propertyValue = (_xmlSecurityPropertyMgr != null) ?
            _xmlSecurityPropertyMgr.getValue(name) : null;
        if (propertyValue != null) {
            return propertyValue;
        }
    }

    // Throw an exception for all other attributes
    ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_ERR, name);
    throw new IllegalArgumentException(err.toString());
}
 
Example 20
Source File: Parser.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * SAX2: Receive notification of the beginning of an element.
 *       The parser may re-use the attribute list that we're passed so
 *       we clone the attributes in our own Attributes implementation
 */
public void startElement(String uri, String localname,
                         String qname, Attributes attributes)
    throws SAXException {
    final int col = qname.lastIndexOf(':');
    final String prefix = (col == -1) ? null : qname.substring(0, col);

    SyntaxTreeNode element = makeInstance(uri, prefix,
                                    localname, attributes);
    if (element == null) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.ELEMENT_PARSE_ERR,
                                    prefix+':'+localname);
        throw new SAXException(err.toString());
    }

    // If this is the root element of the XML document we need to make sure
    // that it contains a definition of the XSL namespace URI
    if (_root == null) {
        if ((_prefixMapping == null) ||
            (_prefixMapping.containsValue(Constants.XSLT_URI) == false))
            _rootNamespaceDef = false;
        else
            _rootNamespaceDef = true;
        _root = element;
    }
    else {
        SyntaxTreeNode parent = _parentStack.peek();
        parent.addElement(element);
        element.setParent(parent);
    }
    element.setAttributes(new AttributesImpl(attributes));
    element.setPrefixMapping(_prefixMapping);

    if (element instanceof Stylesheet) {
        // Extension elements and excluded elements have to be
        // handled at this point in order to correctly generate
        // Fallback elements from <xsl:fallback>s.
        getSymbolTable().setCurrentNode(element);
        ((Stylesheet)element).declareExtensionPrefixes(this);
    }

    _prefixMapping = null;
    _parentStack.push(element);
}