transformeridentityimpl.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,425 行 · 第 1/4 页
JAVA
1,425 行
if (null != xmlSource.getSystemId()) m_systemID = xmlSource.getSystemId(); try { XMLReader reader = null; if (source instanceof SAXSource) reader = ((SAXSource) source).getXMLReader(); boolean isUserReader = (reader != null); if (null == reader) { // Use JAXP1.1 ( if possible ) try { javax.xml.parsers.SAXParserFactory factory = javax.xml.parsers.SAXParserFactory.newInstance(); factory.setNamespaceAware(true); javax.xml.parsers.SAXParser jaxpParser = factory.newSAXParser(); reader = jaxpParser.getXMLReader(); } catch (javax.xml.parsers.ParserConfigurationException ex) { throw new org.xml.sax.SAXException(ex); } catch (javax.xml.parsers.FactoryConfigurationError ex1) { throw new org.xml.sax.SAXException(ex1.toString()); } catch (NoSuchMethodError ex2){} catch (AbstractMethodError ame){} } if (null == reader) { reader = XMLReaderFactory.createXMLReader(); } try { reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); // Commented out as per discussion with Thomas2.Maesing@bgs-ag.de // about bug 2124.// if(!isUserReader)// reader.setFeature("http://apache.org/xml/features/validation/dynamic",// true); } catch (org.xml.sax.SAXException se) { // We don't care. } // Get the input content handler, which will handle the // parse events and create the source tree. ContentHandler inputHandler = this; reader.setContentHandler(inputHandler); if (inputHandler instanceof org.xml.sax.DTDHandler) reader.setDTDHandler((org.xml.sax.DTDHandler) inputHandler); try { if (inputHandler instanceof org.xml.sax.ext.LexicalHandler) reader.setProperty("http://xml.org/sax/properties/lexical-handler", inputHandler); if (inputHandler instanceof org.xml.sax.ext.DeclHandler) reader.setProperty( "http://xml.org/sax/properties/declaration-handler", inputHandler); } catch (org.xml.sax.SAXException se){} try { if (inputHandler instanceof org.xml.sax.ext.LexicalHandler) reader.setProperty("http://xml.org/sax/handlers/LexicalHandler", inputHandler); if (inputHandler instanceof org.xml.sax.ext.DeclHandler) reader.setProperty("http://xml.org/sax/handlers/DeclHandler", inputHandler); } catch (org.xml.sax.SAXNotRecognizedException snre){} reader.parse(xmlSource); } catch (org.apache.xml.utils.WrappedRuntimeException wre) { Throwable throwable = wre.getException(); while (throwable instanceof org.apache.xml.utils.WrappedRuntimeException) { throwable = ((org.apache.xml.utils.WrappedRuntimeException) throwable).getException(); } throw new TransformerException(wre.getException()); } catch (org.xml.sax.SAXException se) { throw new TransformerException(se); } catch (IOException ioe) { throw new TransformerException(ioe); } } finally { if(null != m_outputStream) { try { m_outputStream.close(); } catch(IOException ioe){} m_outputStream = null; } } } /** * Add a parameter for the transformation. * * <p>Pass a qualified name as a two-part string, the namespace URI * enclosed in curly braces ({}), followed by the local name. If the * name has a null URL, the String only contain the local name. An * application can safely check for a non-null URI by testing to see if the first * character of the name is a '{' character.</p> * <p>For example, if a URI and local name were obtained from an element * defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, * then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that * no prefix is used.</p> * * @param name The name of the parameter, which may begin with a namespace URI * in curly braces ({}). * @param value The value object. This can be any valid Java object. It is * up to the processor to provide the proper object coersion or to simply * pass the object on for use in an extension. */ public void setParameter(String name, Object value) { if (null == m_params) { m_params = new Hashtable(); } m_params.put(name, value); } /** * Get a parameter that was explicitly set with setParameter * or setParameters. * * <p>This method does not return a default parameter value, which * cannot be determined until the node context is evaluated during * the transformation process. * * * @param name Name of the parameter. * @return A parameter that has been set with setParameter. */ public Object getParameter(String name) { if (null == m_params) return null; return m_params.get(name); } /** * Clear all parameters set with setParameter. */ public void clearParameters() { if (null == m_params) return; m_params.clear(); } /** * Set an object that will be used to resolve URIs used in * document(). * * <p>If the resolver argument is null, the URIResolver value will * be cleared, and the default behavior will be used.</p> * * @param resolver An object that implements the URIResolver interface, * or null. */ public void setURIResolver(URIResolver resolver) { m_URIResolver = resolver; } /** * Get an object that will be used to resolve URIs used in * document(), etc. * * @return An object that implements the URIResolver interface, * or null. */ public URIResolver getURIResolver() { return m_URIResolver; } /** * Set the output properties for the transformation. These * properties will override properties set in the Templates * with xsl:output. * * <p>If argument to this function is null, any properties * previously set are removed, and the value will revert to the value * defined in the templates object.</p> * * <p>Pass a qualified property key name as a two-part string, the namespace URI * enclosed in curly braces ({}), followed by the local name. If the * name has a null URL, the String only contain the local name. An * application can safely check for a non-null URI by testing to see if the first * character of the name is a '{' character.</p> * <p>For example, if a URI and local name were obtained from an element * defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, * then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that * no prefix is used.</p> * * @param oformat A set of output properties that will be * used to override any of the same properties in affect * for the transformation. * * @see javax.xml.transform.OutputKeys * @see java.util.Properties * * @throws IllegalArgumentException if any of the argument keys are not * recognized and are not namespace qualified. */ public void setOutputProperties(Properties oformat) throws IllegalArgumentException { if (null != oformat) { // See if an *explicit* method was set. String method = (String) oformat.get(OutputKeys.METHOD); if (null != method) m_outputFormat = new OutputProperties(method); else m_outputFormat = new OutputProperties(); } if (null != oformat) { m_outputFormat.copyFrom(oformat); } } /** * Get a copy of the output properties for the transformation. * * <p>The properties returned should contain properties set by the user, * and properties set by the stylesheet, and these properties * are "defaulted" by default properties specified by <a href="http://www.w3.org/TR/xslt#output">section 16 of the * XSL Transformations (XSLT) W3C Recommendation</a>. The properties that * were specifically set by the user or the stylesheet should be in the base * Properties list, while the XSLT default properties that were not * specifically set should be the default Properties list. Thus, * getOutputProperties().getProperty(String key) will obtain any * property in that was set by {@link #setOutputProperty}, * {@link #setOutputProperties}, in the stylesheet, <em>or</em> the default * properties, while * getOutputProperties().get(String key) will only retrieve properties * that were explicitly set by {@link #setOutputProperty}, * {@link #setOutputProperties}, or in the stylesheet.</p> * * <p>Note that mutation of the Properties object returned will not * effect the properties that the transformation contains.</p> * * <p>If any of the argument keys are not recognized and are not * namespace qualified, the property will be ignored. In other words the * behaviour is not orthogonal with setOutputProperties.</p> * * @return A copy of the set of output properties in effect * for the next transformation. * * @see javax.xml.transform.OutputKeys * @see java.util.Properties */ public Properties getOutputProperties() { return (Properties) m_outputFormat.getProperties().clone(); } /** * Set an output property that will be in effect for the * transformation. * * <p>Pass a qualified property name as a two-part string, the namespace URI * enclosed in curly braces ({}), followed by the local name. If the * name has a null URL, the String only contain the local name. An * application can safely check for a non-null URI by testing to see if the first * character of the name is a '{' character.</p> * <p>For example, if a URI and local name were obtained from an element * defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, * then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that * no prefix is used.</p> * * <p>The Properties object that was passed to {@link #setOutputProperties} won't * be effected by calling this method.</p> * * @param name A non-null String that specifies an output * property name, which may be namespace qualified. * @param value The non-null string value of the output property. * * @throws IllegalArgumentException If the property is not supported, and is * not qualified with a namespace. * * @see javax.xml.transform.OutputKeys */ public void setOutputProperty(String name, String value) throws IllegalArgumentException { if (!m_outputFormat.isLegalPropertyKey(name)) throw new IllegalArgumentException(XSLMessages.createMessage(XSLTErrorResources.ER_OUTPUT_PROPERTY_NOT_RECOGNIZED, new Object[]{name})); //"output property not recognized: " //+ name); m_outputFormat.setProperty(name, value); } /** * 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 specifies an output * property name, which may be namespace qualified. * * @return The string value of the output property, or null * if no property was found.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?