Ejemplo n.º 1
0
 /**
  * Compiles an XSL stylesheet pointed to by a URL
  *
  * @param url An URL containing the input XSL stylesheet
  * @param name The name to assign to the translet class
  */
 public boolean compile(URL url, String name) {
   try {
     // Open input stream from URL and wrap inside InputSource
     final InputStream stream = url.openStream();
     final InputSource input = new InputSource(stream);
     input.setSystemId(url.toString());
     return compile(input, name);
   } catch (IOException e) {
     _parser.reportError(Constants.FATAL, new ErrorMsg(e));
     return false;
   }
 }
  public void parseContents(Parser parser) {
    final String name = getAttribute("name");

    if (name.length() > 0) {
      _isLiteral = Util.isLiteral(name);
      if (_isLiteral) {
        if (!XML11Char.isXML11ValidNCName(name)) {
          ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_NCNAME_ERR, name, this);
          parser.reportError(Constants.ERROR, err);
        }
      }
      _name = AttributeValue.create(this, name, parser);
    } else reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "name");

    if (name.equals("xml")) {
      reportError(this, parser, ErrorMsg.ILLEGAL_PI_ERR, "xml");
    }
    parseChildren(parser);
  }
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);
    }
  }
Ejemplo n.º 5
0
  /**
   * Compiles an XSL stylesheet passed in through an InputStream
   *
   * @param input An InputSource that will pass in the stylesheet contents
   * @param name The name of the translet class to generate - can be null
   * @return 'true' if the compilation was successful
   */
  public boolean compile(InputSource input, String name) {
    try {
      // Reset globals in case we're called by compile(Vector v);
      reset();

      // The systemId may not be set, so we'll have to check the URL
      String systemId = null;
      if (input != null) {
        systemId = input.getSystemId();
      }

      // Set the translet class name if not already set
      if (_className == null) {
        if (name != null) {
          setClassName(name);
        } else if (systemId != null && !systemId.equals("")) {
          setClassName(Util.baseName(systemId));
        }

        // Ensure we have a non-empty class name at this point
        if (_className == null || _className.length() == 0) {
          setClassName("GregorSamsa"); // default translet name
        }
      }

      // Get the root node of the abstract syntax tree
      SyntaxTreeNode element = null;
      if (_reader == null) {
        element = _parser.parse(input);
      } else {
        element = _parser.parse(_reader, input);
      }

      // Compile the translet - this is where the work is done!
      if ((!_parser.errorsFound()) && (element != null)) {
        // Create a Stylesheet element from the root node
        _stylesheet = _parser.makeStylesheet(element);
        _stylesheet.setSourceLoader(_loader);
        _stylesheet.setSystemId(systemId);
        _stylesheet.setParentStylesheet(null);
        _stylesheet.setTemplateInlining(_templateInlining);
        _parser.setCurrentStylesheet(_stylesheet);

        // Create AST under the Stylesheet element (parse & type-check)
        _parser.createAST(_stylesheet);
      }
      // Generate the bytecodes and output the translet class(es)
      if ((!_parser.errorsFound()) && (_stylesheet != null)) {
        _stylesheet.setCallsNodeset(_callsNodeset);
        _stylesheet.setMultiDocument(_multiDocument);
        _stylesheet.setHasIdCall(_hasIdCall);

        // Class synchronization is needed for BCEL
        synchronized (getClass()) {
          _stylesheet.translate();
        }
      }
    } catch (Exception e) {
      /*if (_debug)*/ e.printStackTrace();
      _parser.reportError(Constants.FATAL, new ErrorMsg(e));
    } catch (Error e) {
      if (_debug) e.printStackTrace();
      _parser.reportError(Constants.FATAL, new ErrorMsg(e));
    } finally {
      _reader = null; // reset this here to be sure it is not re-used
    }
    return !_parser.errorsFound();
  }