Ejemplo n.º 1
0
 public void setCallsNodeset(boolean flag) {
   if (flag) setMultiDocument(flag);
   _callsNodeset = flag;
 }
Ejemplo n.º 2
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();
  }