Ejemplo n.º 1
0
  /** Parse the contents of the variable */
  public void parseContents(Parser parser) {
    // Parse 'name' and 'select' attributes plus parameter contents
    super.parseContents(parser);

    // Add a ref to this var to its enclosing construct
    SyntaxTreeNode parent = getParent();
    if (parent instanceof Stylesheet) {
      // Mark this as a global variable
      _isLocal = false;
      // Check if a global variable with this name already exists...
      Variable var = parser.getSymbolTable().lookupVariable(_name);
      // ...and if it does we need to check import precedence
      if (var != null) {
        final int us = this.getImportPrecedence();
        final int them = var.getImportPrecedence();
        // It is an error if the two have the same import precedence
        if (us == them) {
          final String name = _name.toString();
          reportError(this, parser, ErrorMsg.VARIABLE_REDEF_ERR, name);
        }
        // Ignore this if previous definition has higher precedence
        else if (them > us) {
          _ignore = true;
          return;
        } else {
          var.disable();
        }
        // Add this variable if we have higher precedence
      }
      ((Stylesheet) parent).addVariable(this);
      parser.getSymbolTable().addVariable(this);
    } else {
      _isLocal = true;
    }
  }
Ejemplo n.º 2
0
  /** Parse all direct children of the <xsl:stylesheet/> element. */
  public final void parseOwnChildren(Parser parser) {
    final SymbolTable stable = parser.getSymbolTable();
    final String excludePrefixes = getAttribute("exclude-result-prefixes");
    final String extensionPrefixes = getAttribute("extension-element-prefixes");

    // Exclude XSLT uri
    stable.pushExcludedNamespacesContext();
    stable.excludeURI(Constants.XSLT_URI);
    stable.excludeNamespaces(excludePrefixes);
    stable.excludeNamespaces(extensionPrefixes);

    final Vector contents = getContents();
    final int count = contents.size();

    // We have to scan the stylesheet element's top-level elements for
    // variables and/or parameters before we parse the other elements
    for (int i = 0; i < count; i++) {
      SyntaxTreeNode child = (SyntaxTreeNode) contents.elementAt(i);
      if ((child instanceof VariableBase) || (child instanceof NamespaceAlias)) {
        parser.getSymbolTable().setCurrentNode(child);
        child.parseContents(parser);
      }
    }

    // Now go through all the other top-level elements...
    for (int i = 0; i < count; i++) {
      SyntaxTreeNode child = (SyntaxTreeNode) contents.elementAt(i);
      if (!(child instanceof VariableBase) && !(child instanceof NamespaceAlias)) {
        parser.getSymbolTable().setCurrentNode(child);
        child.parseContents(parser);
      }

      // All template code should be compiled as methods if the
      // <xsl:apply-imports/> element was ever used in this stylesheet
      if (!_templateInlining && (child instanceof Template)) {
        Template template = (Template) child;
        String name = "template$dot$" + template.getPosition();
        template.setName(parser.getQName(name));
      }
    }

    stable.popExcludedNamespacesContext();
  }
Ejemplo n.º 3
0
  /**
   * Parse the version and uri fields of the stylesheet and add an entry to the symbol table mapping
   * the name <tt>__stylesheet_</tt> to an instance of this class.
   */
  public void parseContents(Parser parser) {
    final SymbolTable stable = parser.getSymbolTable();

    /*
    // Make sure the XSL version set in this stylesheet
    if ((_version == null) || (_version.equals(EMPTYSTRING))) {
        reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR,"version");
    }
    // Verify that the version is 1.0 and nothing else
    else if (!_version.equals("1.0")) {
        reportError(this, parser, ErrorMsg.XSL_VERSION_ERR, _version);
    }
    */

    // Add the implicit mapping of 'xml' to the XML namespace URI
    addPrefixMapping("xml", "http://www.w3.org/XML/1998/namespace");

    // Report and error if more than one stylesheet defined
    final Stylesheet sheet = stable.addStylesheet(_name, this);
    if (sheet != null) {
      // Error: more that one stylesheet defined
      ErrorMsg err = new ErrorMsg(ErrorMsg.MULTIPLE_STYLESHEET_ERR, this);
      parser.reportError(Constants.ERROR, err);
    }

    // If this is a simplified stylesheet we must create a template that
    // grabs the root node of the input doc ( <xsl:template match="/"/> ).
    // This template needs the current element (the one passed to this
    // method) as its only child, so the Template class has a special
    // method that handles this (parseSimplified()).
    if (_simplified) {
      stable.excludeURI(XSLT_URI);
      Template template = new Template();
      template.parseSimplified(this, parser);
    }
    // Parse the children of this node
    else {
      parseOwnChildren(parser);
    }
  }
Ejemplo n.º 4
0
  /** Parse the name of the <xsl:decimal-formatting/> element */
  public void parseContents(Parser parser) {
    // Get the name of these decimal formatting symbols
    final String name = getAttribute("name");
    if (name.length() > 0) {
      if (!XML11Char.isXML11ValidQName(name)) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, name, this);
        parser.reportError(Constants.ERROR, err);
      }
    }
    _name = parser.getQNameIgnoreDefaultNs(name);
    if (_name == null) {
      _name = parser.getQNameIgnoreDefaultNs(EMPTYSTRING);
    }

    // Check if a set of symbols has already been registered under this name
    SymbolTable stable = parser.getSymbolTable();
    if (stable.getDecimalFormatting(_name) != null) {
      reportWarning(this, parser, ErrorMsg.SYMBOLS_REDEF_ERR, _name.toString());
    } else {
      stable.addDecimalFormatting(_name, this);
    }
  }
  /** Parse the attributes of the xsl:sort element */
  public void parseContents(Parser parser) {

    final SyntaxTreeNode parent = getParent();
    if (!(parent instanceof ApplyTemplates) && !(parent instanceof ForEach)) {
      reportError(this, parser, ErrorMsg.STRAY_SORT_ERR, null);
      return;
    }

    // Parse the select expression (node string value if no expression)
    _select = parser.parseExpression(this, "select", "string(.)");

    // Get the sort order; default is 'ascending'
    String val = getAttribute("order");
    if (val.length() == 0) val = "ascending";
    _order = AttributeValue.create(this, val, parser);

    // Get the sort data type; default is text
    val = getAttribute("data-type");
    if (val.length() == 0) {
      try {
        final Type type = _select.typeCheck(parser.getSymbolTable());
        if (type instanceof IntType) val = "number";
        else val = "text";
      } catch (TypeCheckError e) {
        val = "text";
      }
    }
    _dataType = AttributeValue.create(this, val, parser);

    _lang = getAttribute("lang"); // bug! see 26869
    // val =  getAttribute("lang");
    // _lang = AttributeValue.create(this, val, parser);
    // Get the case order; default is language dependant
    val = getAttribute("case-order");
    _caseOrder = AttributeValue.create(this, val, parser);
  }
Ejemplo n.º 6
0
 public void declareExtensionPrefixes(Parser parser) {
   final SymbolTable stable = parser.getSymbolTable();
   final String extensionPrefixes = getAttribute("extension-element-prefixes");
   extensionURI(extensionPrefixes, stable);
 }
Ejemplo n.º 7
0
 /*
  * The namespace alias definitions given here have an impact only on
  * literal elements and literal attributes.
  */
 public void parseContents(Parser parser) {
   sPrefix = getAttribute("stylesheet-prefix");
   rPrefix = getAttribute("result-prefix");
   parser.getSymbolTable().addPrefixAlias(sPrefix, rPrefix);
 }