public Vector getAllValidTemplates() {
    // Return templates if no imported/included stylesheets
    if (_includedStylesheets == null) {
      return _templates;
    }

    // Is returned value cached?
    if (_allValidTemplates == null) {
      Vector templates = new Vector();
      templates.addAll(_templates);
      int size = _includedStylesheets.size();
      for (int i = 0; i < size; i++) {
        Stylesheet included = (Stylesheet) _includedStylesheets.elementAt(i);
        templates.addAll(included.getAllValidTemplates());
      }
      // templates.addAll(_templates);

      // Cache results in top-level stylesheet only
      if (_parentStylesheet != null) {
        return templates;
      }
      _allValidTemplates = templates;
    }

    return _allValidTemplates;
  }
 public void numberFormattingUsed() {
   _numberFormattingUsed = true;
   /*
    * Fix for bug 23046, if the stylesheet is included, set the
    * numberFormattingUsed flag to the parent stylesheet too.
    * AbstractTranslet.addDecimalFormat() will be inlined once for the
    * outer most stylesheet.
    */
   Stylesheet parent = getParentStylesheet();
   if (null != parent) parent.numberFormattingUsed();
 }
 public boolean checkForLoop(String systemId) {
   // Return true if this stylesheet includes/imports itself
   if (_systemId != null && _systemId.equals(systemId)) {
     return true;
   }
   // Then check with any stylesheets that included/imported this one
   if (_parentStylesheet != null) return _parentStylesheet.checkForLoop(systemId);
   // Otherwise OK
   return false;
 }
  public void setImportPrecedence(final int precedence) {
    // Set import precedence for this stylesheet
    _importPrecedence = precedence;

    // Set import precedence for all included stylesheets
    final Enumeration elements = elements();
    while (elements.hasMoreElements()) {
      SyntaxTreeNode child = (SyntaxTreeNode) elements.nextElement();
      if (child instanceof Include) {
        Stylesheet included = ((Include) child).getIncludedStylesheet();
        if (included != null && included._includedFrom == this) {
          included.setImportPrecedence(precedence);
        }
      }
    }

    // Set import precedence for the stylesheet that imported this one
    if (_importedFrom != null) {
      if (_importedFrom.getImportPrecedence() < precedence) {
        final Parser parser = getParser();
        final int nextPrecedence = parser.getNextImportPrecedence();
        _importedFrom.setImportPrecedence(nextPrecedence);
      }
    }
    // Set import precedence for the stylesheet that included this one
    else if (_includedFrom != null) {
      if (_includedFrom.getImportPrecedence() != precedence)
        _includedFrom.setImportPrecedence(precedence);
    }
  }
Exemple #5
0
 private String getFileName(SyntaxTreeNode node) {
   Stylesheet stylesheet = node.getStylesheet();
   if (stylesheet != null) return stylesheet.getSystemId();
   else return null;
 }
 public void setIncludingStylesheet(Stylesheet parent) {
   _includedFrom = parent;
   parent.addIncludedStylesheet(this);
 }
Exemple #7
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();
  }