stylesheet.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,548 行 · 第 1/3 页
JAVA
1,548 行
*/ public int getVariableOrParamCount() { return (null != m_topLevelVariables) ? m_topLevelVariables.size() : 0; } /** * Set an "xsl:param" property. * @see <a href="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a> * * @param v A non-null ElemParam reference. */ public void setParam(ElemParam v) { setVariable(v); } /** * Get an "xsl:param" property. * @see <a href="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a> * * @param qname non-null reference to qualified name of the parameter. * * @return ElemParam with the given name in the list or null */ public ElemParam getParam(QName qname) { if (null != m_topLevelVariables) { int n = getVariableOrParamCount(); for (int i = 0; i < n; i++) { ElemVariable var = getVariableOrParam(i); if((var.getXSLToken() == Constants.ELEMNAME_PARAMVARIABLE) && (var.getName().equals(qname))) return (ElemParam)var; } } return null; } /** * The "xsl:template" properties. * @serial */ private Vector m_templates; /** * Set an "xsl:template" property. * @see <a href="http://www.w3.org/TR/xslt#section-Defining-Template-Rules">section-Defining-Template-Rules in XSLT Specification</a> * * @param v ElemTemplate to add to list of templates */ public void setTemplate(ElemTemplate v) { if (null == m_templates) m_templates = new Vector(); m_templates.addElement(v); v.setStylesheet(this); } /** * Get an "xsl:template" property. * @see <a href="http://www.w3.org/TR/xslt#section-Defining-Template-Rules">section-Defining-Template-Rules in XSLT Specification</a> * * @param i Index of ElemTemplate in the list to get * * @return ElemTemplate at the given index in the list * * @throws TransformerException */ public ElemTemplate getTemplate(int i) throws TransformerException { if (null == m_templates) throw new ArrayIndexOutOfBoundsException(); return (ElemTemplate) m_templates.elementAt(i); } /** * Get the number of "xsl:template" properties. * @see <a href="http://www.w3.org/TR/xslt#section-Defining-Template-Rules">section-Defining-Template-Rules in XSLT Specification</a> * * @return the number of "xsl:template" properties. */ public int getTemplateCount() { return (null != m_templates) ? m_templates.size() : 0; } /** * The "xsl:namespace-alias" properties. * @serial */ private Vector m_prefix_aliases; /** * Set the "xsl:namespace-alias" property. * @see <a href="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a> * * @param na NamespaceAlias elemeent to add to the list */ public void setNamespaceAlias(NamespaceAlias na) { if (m_prefix_aliases == null) m_prefix_aliases = new Vector(); m_prefix_aliases.addElement(na); } /** * Get an "xsl:namespace-alias" property. * @see <a href="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a> * * @param i Index of NamespaceAlias element to get from the list * * @return NamespaceAlias element at the given index in the list * * @throws ArrayIndexOutOfBoundsException */ public NamespaceAlias getNamespaceAlias(int i) throws ArrayIndexOutOfBoundsException { if (null == m_prefix_aliases) throw new ArrayIndexOutOfBoundsException(); return (NamespaceAlias) m_prefix_aliases.elementAt(i); } /** * Get the number of "xsl:namespace-alias" properties. * @see <a href="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a> * * @return the number of "xsl:namespace-alias" properties. */ public int getNamespaceAliasCount() { return (null != m_prefix_aliases) ? m_prefix_aliases.size() : 0; } /** * The "non-xsl-top-level" properties. * @serial */ private Hashtable m_NonXslTopLevel; /** * Set found a non-xslt element. * @see <a href="http://www.w3.org/TR/xslt#stylesheet-element">stylesheet-element in XSLT Specification</a> * * @param name Qualified name of the element * @param obj The element object */ public void setNonXslTopLevel(QName name, Object obj) { if (null == m_NonXslTopLevel) m_NonXslTopLevel = new Hashtable(); m_NonXslTopLevel.put(name, obj); } /** * Get a non-xslt element. * @see <a href="http://www.w3.org/TR/xslt#stylesheet-element">stylesheet-element in XSLT Specification</a> * * @param name Qualified name of the element to get * * @return The object associate with the given name */ public Object getNonXslTopLevel(QName name) { return (null != m_NonXslTopLevel) ? m_NonXslTopLevel.get(name) : null; } // =========== End top-level XSLT properties =========== /** * The base URL of the XSL document. * @serial */ private String m_href = null; /** The doctype-public element. * @serial */ private String m_publicId; /** The doctype-system element. * @serial */ private String m_systemId; /** * Get the base identifier with which this stylesheet is associated. * * @return the base identifier with which this stylesheet is associated. */ public String getHref() { return m_href; } /** * Set the base identifier with which this stylesheet is associated. * * @param baseIdent the base identifier with which this stylesheet is associated. */ public void setHref(String baseIdent) { m_href = baseIdent; } /** * Set the location information for this element. * * @param locator SourceLocator object with location information */ public void setLocaterInfo(SourceLocator locator) { if (null != locator) { m_publicId = locator.getPublicId(); m_systemId = locator.getSystemId(); if (null != m_systemId) { try { m_href = SystemIDResolver.getAbsoluteURI(m_systemId, null); } catch (TransformerException se) { // Ignore this for right now } } super.setLocaterInfo(locator); } } /** * The root of the stylesheet, where all the tables common * to all stylesheets are kept. * @serial */ private StylesheetRoot m_stylesheetRoot; /** * Get the root of the stylesheet, where all the tables common * to all stylesheets are kept. * * @return the root of the stylesheet */ public StylesheetRoot getStylesheetRoot() { return m_stylesheetRoot; } /** * Set the root of the stylesheet, where all the tables common * to all stylesheets are kept. * * @param v the root of the stylesheet */ public void setStylesheetRoot(StylesheetRoot v) { m_stylesheetRoot = v; } /** * The parent of the stylesheet. This will be null if this * is the root stylesheet. * @serial */ private Stylesheet m_stylesheetParent; /** * Get the parent of the stylesheet. This will be null if this * is the root stylesheet. * * @return the parent of the stylesheet. */ public Stylesheet getStylesheetParent() { return m_stylesheetParent; } /** * Set the parent of the stylesheet. This should be null if this * is the root stylesheet. * * @param v the parent of the stylesheet. */ public void setStylesheetParent(Stylesheet v) { m_stylesheetParent = v; } /** * Get the owning aggregated stylesheet, or this * stylesheet if it is aggregated. * * @return the owning aggregated stylesheet or itself */ public StylesheetComposed getStylesheetComposed() { Stylesheet sheet = this; while (!sheet.isAggregatedType()) { sheet = sheet.getStylesheetParent(); } return (StylesheetComposed) sheet; } /** * Get the type of the node. We'll pretend we're a Document. * * @return the type of the node: document node. */ public short getNodeType() { return DTM.DOCUMENT_NODE; } /** * Get an integer representation of the element type. * * @return An integer representation of the element, defined in the * Constants class. * @see org.apache.xalan.templates.Constants */ public int getXSLToken() { return Constants.ELEMNAME_STYLESHEET; } /** * Return the node name. * * @return The node name */ public String getNodeName() { return Constants.ELEMNAME_STYLESHEET_STRING; } /** * Replace an "xsl:template" property. * This is a hook for CompilingStylesheetHandler, to allow * us to access a template, compile it, instantiate it, * and replace the original with the compiled instance. * ADDED 9/5/2000 to support compilation experiment * * @param v Compiled template to replace with * @param i Index of template to be replaced * * @throws TransformerException */ public void replaceTemplate(ElemTemplate v, int i) throws TransformerException { if (null == m_templates) throw new ArrayIndexOutOfBoundsException(); replaceChild(v, (ElemTemplateElement)m_templates.elementAt(i)); m_templates.setElementAt(v, i); v.setStylesheet(this); } /** * Call the children visitors. * @param visitor The visitor whose appropriate method will be called. */ protected void callChildVisitors(XSLTVisitor visitor, boolean callAttrs) { int s = getImportCount(); for (int j = 0; j < s; j++) { getImport(j).callVisitors(visitor); } s = getIncludeCount(); for (int j = 0; j < s; j++) { getInclude(j).callVisitors(visitor); } s = getOutputCount(); for (int j = 0; j < s; j++) { visitor.visitTopLevelInstruction(getOutput(j)); } // Next, add in the attribute-set elements s = getAttributeSetCount(); for (int j = 0; j < s; j++) { ElemAttributeSet attrSet = getAttributeSet(j); if (visitor.visitTopLevelInstruction(attrSet)) { attrSet.callChildVisitors(visitor); } } // Now the decimal-formats s = getDecimalFormatCount(); for (int j = 0; j < s; j++) { visitor.visitTopLevelInstruction(getDecimalFormat(j)); } // Now the keys s = getKeyCount(); for (int j = 0; j < s; j++) { visitor.visitTopLevelInstruction(getKey(j)); } // And the namespace aliases s = getNamespaceAliasCount(); for (int j = 0; j < s; j++) { visitor.visitTopLevelInstruction(getNamespaceAlias(j)); } // Next comes the templates s = getTemplateCount(); for (int j = 0; j < s; j++) { try { ElemTemplate template = getTemplate(j); if (visitor.visitTopLevelInstruction(template)) { template.callChildVisitors(visitor); } } catch (TransformerException te) { throw new org.apache.xml.utils.WrappedRuntimeException(te); } } // Then, the variables s = getVariableOrParamCount(); for (int j = 0; j < s; j++) { ElemVariable var = getVariableOrParam(j); if (visitor.visitTopLevelVariableOrParamDecl(var)) { var.callChildVisitors(visitor); } } // And lastly the whitespace preserving and stripping elements s = getStripSpaceCount(); for (int j = 0; j < s; j++) { visitor.visitTopLevelInstruction(getStripSpace(j)); } s = getPreserveSpaceCount(); for (int j = 0; j < s; j++) { visitor.visitTopLevelInstruction(getPreserveSpace(j)); } if(null != m_NonXslTopLevel) { java.util.Enumeration enum = m_NonXslTopLevel.elements(); while(enum.hasMoreElements()) { ElemTemplateElement elem = (ElemTemplateElement)enum.nextElement(); if (visitor.visitTopLevelInstruction(elem)) { elem.callChildVisitors(visitor); } } } } /** * Accept a visitor and call the appropriate method * for this class. * * @param visitor The visitor whose appropriate method will be called. * @return true if the children of the object should be visited. */ protected boolean accept(XSLTVisitor visitor) { return visitor.visitStylesheet(this); } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?