⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transformerimpl.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                ((SAXSource)source).getInputSource()==null &&                ((SAXSource)source).getXMLReader()==null )||                (source instanceof DOMSource &&                 ((DOMSource)source).getNode()==null)){                        DocumentBuilderFactory builderF =                                 DocumentBuilderFactory.newInstance();                        DocumentBuilder builder =                                 builderF.newDocumentBuilder();                        String systemID = source.getSystemId();                        source = new DOMSource(builder.newDocument());                        // Copy system ID from original, empty Source to new                        if (systemID != null) {                          source.setSystemId(systemID);                        }            }           	    if (_isIdentity) {		transformIdentity(source, handler);	    } else {		_translet.transform(getDOM(source), handler);	    }	} catch (TransletException e) {	    if (_errorListener != null)	postErrorToListener(e.getMessage());	    throw new TransformerException(e);	} catch (RuntimeException e) {	    if (_errorListener != null)	postErrorToListener(e.getMessage());	    throw new TransformerException(e);	} catch (Exception e) {	    if (_errorListener != null)	postErrorToListener(e.getMessage());	    throw new TransformerException(e);	} finally {            _dtmManager = null;        }	// If we create an output stream for the Result, we need to close it after the transformation.	if (_ostream != null) {	    try {	        _ostream.close();	    }	    catch (IOException e) {}	    _ostream = null;	}    }    /**     * Implements JAXP's Transformer.getErrorListener()     * Get the error event handler in effect for the transformation.     *     * @return The error event handler currently in effect     */    public ErrorListener getErrorListener() {  	return _errorListener;     }    /**     * 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     */    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));    }    /**     * Inform TrAX error listener of an error     */    private void postErrorToListener(String message) {        try {            _errorListener.error(new TransformerException(message));	}	catch (TransformerException e) {            // ignored - transformation cannot be continued        }    }    /**     * Inform TrAX error listener of a warning     */    private void postWarningToListener(String message) {        try {            _errorListener.warning(new TransformerException(message));        }	catch (TransformerException e) {            // ignored - transformation cannot be continued        }    }    /**     * The translet stores all CDATA sections set in the <xsl:output> element     * in a Hashtable. This method will re-construct the whitespace separated     * list of elements given in the <xsl:output> element.     */    private String makeCDATAString(Hashtable cdata) {	// Return a 'null' string if no CDATA section elements were specified	if (cdata == null) return null;	StringBuffer result = new StringBuffer();	// Get an enumeration of all the elements in the hashtable	Enumeration elements = cdata.keys();	if (elements.hasMoreElements()) {	    result.append((String)elements.nextElement());	    while (elements.hasMoreElements()) {		String element = (String)elements.nextElement();		result.append(' ');		result.append(element);	    }	}		return(result.toString());    }    /**     * Implements JAXP's Transformer.getOutputProperties().     * Returns a copy of the output properties for the transformation. This is     * a set of layered properties. The first layer contains properties set by     * calls to setOutputProperty() and setOutputProperties() on this class,     * and the output settings defined in the stylesheet's <xsl:output>     * element makes up the second level, while the default XSLT output     * settings are returned on the third level.     *     * @return Properties in effect for this Transformer     */    public Properties getOutputProperties() { 	return (Properties) _properties.clone();    }    /**     * Implements JAXP's Transformer.getOutputProperty().     * 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 A non-null string that contains the name of the property     * @throws IllegalArgumentException if the property name is not known     */    public String getOutputProperty(String name)	throws IllegalArgumentException     {	if (!validOutputProperty(name)) {	    ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNKNOWN_PROP_ERR, name);	    throw new IllegalArgumentException(err.toString());	}	return _properties.getProperty(name);    }    /**     * 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     */    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;	}    }    /**     * 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     */    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);    }    /**     * Internal method to pass any properties to the translet prior to     * initiating the transformation     */    private void transferOutputProperties(AbstractTranslet translet)    {	// Return right now if no properties are set	if (_properties == null) return;	// Get a list of all the defined properties	Enumeration names = _properties.propertyNames();	while (names.hasMoreElements()) {	    // Note the use of get() instead of getProperty()	    String name  = (String) names.nextElement();	    String value = (String) _properties.get(name);	    // Ignore default properties	    if (value == null) continue;	    // Pass property value to translet - override previous setting	    if (name.equals(OutputKeys.ENCODING)) {		translet._encoding = value;	    }	    else if (name.equals(OutputKeys.METHOD)) {		translet._method = value;	    }	    else if (name.equals(OutputKeys.DOCTYPE_PUBLIC)) {		translet._doctypePublic = value;	    }	    else if (name.equals(OutputKeys.DOCTYPE_SYSTEM)) {		translet._doctypeSystem = value;	    }	    else if (name.equals(OutputKeys.MEDIA_TYPE)) {		translet._mediaType = value;	    }	    else if (name.equals(OutputKeys.STANDALONE)) {		translet._standalone = value;	    }	    else if (name.equals(OutputKeys.VERSION)) {		translet._version = value;	    }	    else if (name.equals(OutputKeys.OMIT_XML_DECLARATION)) {		translet._omitHeader = 		    (value != null && value.toLowerCase().equals("yes"));	    }	    else if (name.equals(OutputKeys.INDENT)) {		translet._indent = 		    (value != null && value.toLowerCase().equals("yes"));	    }            else if (name.equals(OutputPropertiesFactory.S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL +"indent-amount")) {                 if (value != null) {                     translet._indentamount = Integer.parseInt(value);                 }            }            else if (name.equals(OutputPropertiesFactory.S_BUILTIN_EXTENSIONS_UNIVERSAL +"indent-amount")) {                 if (value != null) {                     translet._indentamount = Integer.parseInt(value);                 }            }	    else if (name.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) {		if (value != null) {		    translet._cdata = null; // clear previous setting		    StringTokenizer e = new StringTokenizer(value);		    while (e.hasMoreTokens()) {			translet.addCdataElement(e.nextToken());		    }		}	    }	}    }    /**     * This method is used to pass any properties to the output handler     * when running the identity transform.     */    public void transferOutputProperties(SerializationHandler handler)    {	// Return right now if no properties are set	if (_properties == null) return;	String doctypePublic = null;	String doctypeSystem = null;	// Get a list of all the defined properties	Enumeration names = _properties.propertyNames();	while (names.hasMoreElements()) {	    // Note the use of get() instead of getProperty()	    String name  = (String) names.nextElement();	    String value = (String) _properties.get(name);	    // Ignore default properties	    if (value == null) continue;	    // Pass property value to translet - override previous setting	    if (name.equals(OutputKeys.DOCTYPE_PUBLIC)) {		doctypePublic = value;	    }	    else if (name.equals(OutputKeys.DOCTYPE_SYSTEM)) {		doctypeSystem = value;	    }	    else if (name.equals(OutputKeys.MEDIA_TYPE)) {		handler.setMediaType(value);	    }	    else if (name.equals(OutputKeys.STANDALONE)) {		handler.setStandalone(value);	    }	    else if (name.equals(OutputKeys.VERSION)) {		handler.setVersion(value);	    }	    else if (name.equals(OutputKeys.OMIT_XML_DECLARATION)) {		handler.setOmitXMLDeclaration(		    value != null && value.toLowerCase().equals("yes"));	    }	    else if (name.equals(OutputKeys.INDENT)) {		handler.setIndent( 		    value != null && value.toLowerCase().equals("yes"));	    }            else if (name.equals(OutputPropertiesFactory.S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL +"indent-amount")) {                if (value != null) {                    handler.setIndentAmount(Integer.parseInt(value));                }            }            else if (name.equals(OutputPropertiesFactory.S_BUILTIN_EXTENSIONS_UNIVERSAL +"indent-amount")) {                if (value != null) {                    handler.setIndentAmount(Integer.parseInt(value));                }            } 	    else if (name.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) {		if (value != null) {		    StringTokenizer e = new StringTokenizer(value);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -