/*
     * Appends the page directive with the given attributes to the XML
     * view.
     *
     * Since the import attribute of the page directive is the only page
     * attribute that is allowed to appear multiple times within the same
     * document, and since XML allows only single-value attributes,
     * the values of multiple import attributes must be combined into one,
     * separated by comma.
     *
     * If the given page directive contains just 'contentType' and/or
     * 'pageEncoding' attributes, we ignore it, as we've already appended
     * a page directive containing just these two attributes.
     */
    private void appendPageDirective(Node.PageDirective n) {
      boolean append = false;
      Attributes attrs = n.getAttributes();
      int len = (attrs == null) ? 0 : attrs.getLength();
      for (int i = 0; i < len; i++) {
        @SuppressWarnings("null") // If attrs==null, len == 0
        String attrName = attrs.getQName(i);
        if (!"pageEncoding".equals(attrName) && !"contentType".equals(attrName)) {
          append = true;
          break;
        }
      }
      if (!append) {
        return;
      }

      buf.append("<").append(n.getQName());
      buf.append("\n");

      // append jsp:id
      buf.append("  ").append(jspIdPrefix).append(":id").append("=\"");
      buf.append(jspId++).append("\"\n");

      // append remaining attributes
      for (int i = 0; i < len; i++) {
        @SuppressWarnings("null") // If attrs==null, len == 0
        String attrName = attrs.getQName(i);
        if ("import".equals(attrName)
            || "contentType".equals(attrName)
            || "pageEncoding".equals(attrName)) {
          /*
           * Page directive's 'import' attribute is considered
           * further down, and its 'pageEncoding' and 'contentType'
           * attributes are ignored, since we've already appended
           * a new page directive containing just these two
           * attributes
           */
          continue;
        }
        String value = attrs.getValue(i);
        buf.append("  ").append(attrName).append("=\"");
        buf.append(JspUtil.getExprInXml(value)).append("\"\n");
      }
      if (n.getImports().size() > 0) {
        // Concatenate names of imported classes/packages
        boolean first = true;
        ListIterator<String> iter = n.getImports().listIterator();
        while (iter.hasNext()) {
          if (first) {
            first = false;
            buf.append("  import=\"");
          } else {
            buf.append(",");
          }
          buf.append(JspUtil.getExprInXml(iter.next()));
        }
        buf.append("\"\n");
      }
      buf.append("/>\n");
    }
Esempio n. 2
0
  /*
   * extends
   */
  public void setExtends(String value, Node.PageDirective n) {

    xtends = value;

    /*
     * If page superclass is top level class (i.e. not in a package)
     * explicitly import it. If this is not done, the compiler will assume
     * the extended class is in the same pkg as the generated servlet.
     */
    if (value.indexOf('.') < 0) n.addImport(value);
  }