generator.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 2,537 行 · 第 1/5 页

JAVA
2,537
字号
    }    else if (level.equals("any")) {    }    else      throw error(L.l("xsl:number can't understand level=`{0}'",                      level));    XslNumberFormat xslFormat;    xslFormat = new XslNumberFormat(format, lang, isAlphabetic,                                    separator, size);    if (! value.equals(""))      printNumber(parseExpr(value), xslFormat);    else      printNumber(level, countPattern, fromPattern, xslFormat);  }  void printNumber(Expr expr, XslNumberFormat format)    throws Exception  {      }  void printNumber(String level,                   AbstractPattern countPattern,                   AbstractPattern fromPattern,		   XslNumberFormat format)    throws Exception  {      }  /**   * Sets location code for the node.   */  void setLocation(Node node)    throws Exception  {    if (node instanceof QAbstractNode) {      setLocation(((QAbstractNode) node).getBaseURI(),		  ((QAbstractNode) node).getFilename(),                  ((QAbstractNode) node).getLine());    }  }  public void setLocation(String systemId, String filename, int line)    throws XslParseException, IOException  {    if (filename != null) {      _systemId = systemId;      _filename = filename;      _line = line;      // _lineMap.add(filename, line, getOut().getDestLine());    }  }  int getTextLength()  {    return _text.length();  }  protected void printHeader()    throws XslParseException, IOException  {  }    abstract protected void startDisableEscaping()    throws Exception;     abstract protected void endDisableEscaping()    throws Exception;  abstract protected void writeText(String text)    throws Exception;  abstract protected void printTemplate(Element node,					String name, String pattern,					String mode, double priority)    throws Exception;  /**   * Prints location code for the node.   */  void printLocation(Node node)    throws Exception  {    if (node instanceof QAbstractNode) {      printLocation(((QAbstractNode) node).getBaseURI(),		    ((QAbstractNode) node).getFilename(),                    ((QAbstractNode) node).getLine());    }  }  abstract protected void printLocation(String systemId, String filename, int line)    throws Exception;    abstract protected void printElement(Node node)    throws Exception;  abstract protected void    printApplyTemplates(AbstractPattern select, String mode, Sort []sort)    throws Exception;  abstract protected void    printApplyImports(String mode, int min, int max)    throws Exception;    abstract protected void    printCallTemplate(String name, String mode)    throws Exception;    abstract protected void pushCall()    throws Exception;    abstract protected void popCall()    throws Exception;    abstract protected void printParam(String name, Object value)    throws Exception;  abstract protected void printParam(String name, String value, Element elt)    throws Exception;      abstract protected void printParamVariable(String name, Expr expr)    throws Exception;    abstract protected void printParamVariable(String name, Element elt)    throws Exception;    abstract protected void printVariable(String name, Object value)    throws Exception;    protected void printAssign(String name, Object value)    throws Exception  {    printVariable(name, value);  }    abstract protected void printPopScope(int count)    throws Exception;    abstract protected void printCopyOf(String select, Element element)    throws Exception;  abstract protected void printSelectValue(String select, Element element)    throws Exception;  abstract protected void printForEach(Element element, String select)    throws Exception;  abstract protected void printForEach(Element element, String select,				       Sort []sort)    throws Exception;  protected void printIf(Element element, Expr expr)    throws Exception  {  }  protected void printChoose(Element element, Expr expr, boolean first)    throws Exception  {  }  protected void printOtherwise(Element element, boolean first)    throws Exception  {  }  protected void printCopy(Element element)    throws Exception  {  }  protected void printCopyElement(Element element)    throws Exception  {  }  protected void printElement(Element element, String name)    throws Exception  {  }  protected void printElement(Element element, String name, String namespace)    throws Exception  {  }  protected void printAttribute(Element node, String name)    throws Exception  {  }  protected void printAttribute(Element node, String name, String namespace)    throws Exception  {  }  protected void printPi(Element node)    throws Exception  {  }  protected void printComment(Element node)    throws Exception  {  }  protected void printError(String msg)    throws Exception  {  }  protected void printMessage(Element node)    throws Exception  {  }  // extension  protected void printExpression(Element node)    throws Exception  {  }  protected void printScriptlet(Element node)    throws Exception  {  }  protected void printDeclaration(Element node)    throws Exception  {  }  protected void printCacheDepends(String path)    throws Exception  {  }  protected void printWhile(Element element, Expr expr)    throws Exception  {  }  protected void printResultDocument(Element element, String href,                                     String format)    throws Exception  {  }  public int getImportance()  {    return _importance;  }  public void setMinImportance(int importance)  {    _minImportance = importance;  }    public void incrementImportance()  {    _importance++;  }  /**   * Adds a new template pattern.   *   * @param pattern the match pattern.   * @param mode the template mode.   * @param priority the template priority.   * @param function the associated function name.   * @param funId the function id.   */  Template addPattern(AbstractPattern pattern, String mode, double priority,                      String function, int funId)  {    if (pattern instanceof UnionPattern) {      UnionPattern union = (UnionPattern) pattern;      addPattern(union.getLeft(), mode, priority, function, funId);      return addPattern(union.getRight(), mode, priority, function, funId);    }    if (Double.isNaN(priority))      priority = pattern.getPriority();    if (log.isLoggable(Level.FINER))      log.finer("add " + pattern.getNodeName() + " " + pattern + " fun:" +                function + " mode:" + mode + " priority:" + priority);    Template template = new Template(pattern, mode,				     _minImportance, _importance,				     priority, _templateCount++,                                     function, funId);    addTemplate(pattern.getNodeName(), template);    return template;  }    private void addTemplate(String nodeName, Template template)  {    ArrayList<Template> templateList = _templates.get(nodeName);        if (templateList == null) {      templateList = new ArrayList<Template>();      _templates.put(nodeName, templateList);    }    for (int i = templateList.size() - 1; i >= 0; i--) {      Template item = templateList.get(i);      if (template.compareTo(item) <= 0) {	templateList.add(i + 1, template);	return;      }    }    templateList.add(0, template);  }  public AbstractPattern parseMatch(String pattern)    throws XslParseException, IOException  {    if (true)      throw new RuntimeException();    try {      return XPath.parseMatch(pattern, _namespace).getPattern();    } catch (Exception e) {      throw error(L.l("{0} in pattern `{1}'",                      e.toString(), pattern));    }  }  public AbstractPattern parseSelect(String pattern)    throws IOException, XslParseException  {    if (true)      throw new RuntimeException();        try {      return XPath.parseSelect(pattern, _namespace).getPattern();    } catch (Exception e) {      throw error(e);    }  }  protected AbstractPattern parseSelect(String pattern, Node node)    throws IOException, XslParseException  {    if (true)      throw new UnsupportedOperationException();    try {      return XPath.parseSelect(pattern, _namespace).getPattern();    } catch (Exception e) {      throw error(node, e);    }  }  public Expr parseExpr(String pattern)    throws XslParseException  {    if (true)      throw new UnsupportedOperationException();    try {      return XPath.parseExpr(pattern, _namespace, _nodeListContext);    } catch (Exception e) {      throw error(e);    }  }  XslParseException error(Exception e)  {    if (e.getMessage() != null)      return error(e.getMessage());    else {      log.log(Level.WARNING, e.toString(), e);            return error(e.toString());    }  }  XslParseException error(Node node, Exception e)  {    if (e.getMessage() != null)      return error(node, e.getMessage());    else {      log.log(Level.WARNING, e.toString(), e);      return error(e.toString());    }  }    XslParseException error(String message)  {    return new XslParseException(_filename + ":" + _line + ": " + message);  }  /**   * Creates an error message with filename and line number based on   * the source node.   *   * @param node XML node of the source XSL.   * @param message the error message.   */  XslParseException error(Node node, String message)  {    if (! (node instanceof QAbstractNode))      return error(message);        QAbstractNode qnode = (QAbstractNode) node;    String filename = qnode.getFilename();    int line = qnode.getLine();        if (filename != null)      return new XslParseException(filename + ":" +				   line + ": " +				   message);    else      return error(message);  }  /**   * Returns the local name of an XSL element.  Non-XSL elements return   * null.  So xsl:copy will return "copy", while "foo:bar" returns null.   *   * @param node the XSL source node   * @return the local part of the XSL name.   */  protected String getXslLocal(Node node)  {    if (! (node instanceof Element))      return null;    QElement elt = (QElement) node;    String ns = elt.getNamespaceURI();    String prefix = elt.getPrefix();    if (ns == null || ns.equals("")) {      return (elt.getNodeName().startsWith("xsl:") ?	      elt.getNodeName().substring(4) :	      null);    }    else if (ns.startsWith(XSLNS) &&             (ns.length() == XSLNS.length() || ns.charAt(XSLNS.length()) == '/'))      return elt.getLocalName();    else      return null;  }  protected String getXtpLocal(Node node)  {    if (! (node instanceof Element))      return null;    QElement elt = (QElement) node;    String ns = elt.getNamespaceURI();    String prefix = elt.getPrefix();    if (ns == null || ns.equals("")) {      return (elt.getNodeName().startsWith("xtp:") ?	      elt.getNodeName().substring(4) :	      null);    }    else if (ns.startsWith(XTPNS))      return elt.getLocalName();    else      return null;  }  /**   * Parses an expression in a context   */  private Expr parseExpr(Node node, String expr)    throws Exception  {    try {      return XPath.parseExpr(expr, _namespace, _nodeListContext);    } catch (Exception e) {      throw error(node, e.getMessage());    }  }  /**   * Adds the namespaces in the element to the current NamespaceContext.   * The XPath pattern parsing uses NamespaceContext to associate the right   * context with element patterns.   *   * @param elt the XSL element being processed.   *   * @return the old namespace context   */  protected NamespaceContext addNamespace(Element elt)  {    NamespaceContext oldNamespace = _namespace;    Node attr = ((QElement) elt).getFirstAttribute();    for (; attr != null; attr = attr.getNextSibling()) {      String name =

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?