Пример #1
0
  public void popTag() {

    if (this.finished) {
      return;
    }

    CompilationUnit unit = this.currentUnit();

    if (unit instanceof TextUnit) {
      TextUnit t = (TextUnit) unit;
      if (t.isClosed()) {
        this.finishUnit();
      } else {
        t.endTag();
        return;
      }
    }

    unit = this.currentUnit();
    if (unit instanceof TagUnit) {
      TagUnit t = (TagUnit) unit;
      if (t instanceof TrimmedTagUnit) {
        this.finished = true;
        return;
      }
    }

    this.finishUnit();
  }
Пример #2
0
  public void writeInstruction(String value) {
    if (this.finished) {
      return;
    }

    // don't carelessly add empty tags
    if (value.length() == 0) {
      return;
    }

    TextUnit unit;
    if (this.currentUnit() instanceof TextUnit) {
      unit = (TextUnit) this.currentUnit();
    } else {
      unit = new TextUnit(this.alias, this.nextTagId());
      this.startUnit(unit);
    }
    unit.writeInstruction(value);
  }
Пример #3
0
  public void writeComment(String text) {
    if (this.compiler.isTrimmingComments()) return;

    if (this.finished) {
      return;
    }

    // don't carelessly add empty tags
    if (text.length() == 0) {
      return;
    }

    TextUnit unit;
    if (this.currentUnit() instanceof TextUnit) {
      unit = (TextUnit) this.currentUnit();
    } else {
      unit = new TextUnit(this.alias, this.nextTagId());
      this.startUnit(unit);
    }

    unit.writeComment(text);
  }
Пример #4
0
  public void pushTag(Tag orig) {

    if (this.finished) {
      return;
    }

    if (log.isLoggable(Level.FINE)) {
      log.fine("Tag Pushed: " + orig);
    }

    Tag t = this.tagDecorator.decorate(orig);
    String[] qname = this.determineQName(t);
    t = this.trimAttributes(t);

    TagAttribute[] componentAttributes =
        t.getAttributes().getAll(JsfPassthroughElementLibrary.Namespace);
    boolean hasComponentAttributes = null != componentAttributes && 0 < componentAttributes.length;

    boolean handled = false;

    if (isTrimmed(qname[0], qname[1])) {
      if (log.isLoggable(Level.FINE)) {
        log.fine("Composition Found, Popping Parent Tags");
      }
      this.units.clear();
      NamespaceUnit nsUnit = this.namespaceManager.toNamespaceUnit(this.tagLibrary);
      this.units.push(nsUnit);
      this.startUnit(new TrimmedTagUnit(this.tagLibrary, qname[0], qname[1], t, this.nextTagId()));
      if (log.isLoggable(Level.FINE)) {
        log.fine("New Namespace and [Trimmed] TagUnit pushed");
      }
    } else if (isImplementation(qname[0], qname[1])) {
      if (log.isLoggable(Level.FINE)) {
        log.fine("Composite Component Implementation Found, Popping Parent Tags");
      }

      // save aside the InterfaceUnit
      InterfaceUnit iface = getInterfaceUnit();
      if (null == iface) {
        throw new TagException(orig, "Unable to find interface for implementation.");
      }

      // Cleare the parent tags
      this.units.clear();
      NamespaceUnit nsUnit = this.namespaceManager.toNamespaceUnit(this.tagLibrary);
      this.units.push(nsUnit);
      this.currentUnit().addChild(iface);
      this.startUnit(
          new ImplementationUnit(this.tagLibrary, qname[0], qname[1], t, this.nextTagId()));
      if (log.isLoggable(Level.FINE)) {
        log.fine("New Namespace and ImplementationUnit pushed");
      }

    } else if (isRemove(qname[0], qname[1])) {
      this.units.push(new RemoveUnit());
    } else if (this.tagLibrary.containsTagHandler(qname[0], qname[1]) || hasComponentAttributes) {
      if (isInterface(qname[0], qname[1])) {
        InterfaceUnit iface =
            new InterfaceUnit(this.tagLibrary, qname[0], qname[1], t, this.nextTagId());
        setInterfaceUnit(iface);
        this.startUnit(iface);
      } else {
        if (hasComponentAttributes) {
          String ns = t.getNamespace();
          if (0 == ns.length() || "http://www.w3.org/1999/xhtml".equals(ns)) {
            t.setNamespace(JsfPassthroughElementLibrary.Namespace);
            this.startUnit(
                new TagUnit(
                    this.tagLibrary,
                    JsfPassthroughElementLibrary.Namespace,
                    qname[1],
                    t,
                    this.nextTagId()));
          } else {
            throw new FaceletException(
                "Elements with namespace "
                    + ns
                    + " may not have attributes in namespace "
                    + JsfPassthroughElementLibrary.Namespace
                    + "."
                    + " Namespace "
                    + JsfPassthroughElementLibrary.Namespace
                    + " is intended for otherwise non-JSF-aware markup, such as <input type=\"text\" jsf:id >"
                    + " It is not valid to have <h:commandButton jsf:id=\"button\" />.");
          }
        } else {
          this.startUnit(new TagUnit(this.tagLibrary, qname[0], qname[1], t, this.nextTagId()));
        }
      }
    } else if (this.tagLibrary.containsNamespace(qname[0], t)) {
      throw new TagException(
          orig,
          "Tag Library supports namespace: "
              + qname[0]
              + ", but no tag was defined for name: "
              + qname[1]);
    } else {
      TextUnit unit;
      if (this.currentUnit() instanceof TextUnit) {
        unit = (TextUnit) this.currentUnit();
      } else {
        unit = new TextUnit(this.alias, this.nextTagId());
        this.startUnit(unit);
      }
      unit.startTag(t);
    }
  }