예제 #1
0
 private Tag trimJSFCAttribute(Tag tag) {
   TagAttribute attr = tag.getAttributes().get("jsfc");
   if (attr != null) {
     TagAttribute[] oa = tag.getAttributes().getAll();
     TagAttribute[] na = new TagAttribute[oa.length - 1];
     int p = 0;
     for (int i = 0; i < oa.length; i++) {
       if (!"jsfc".equals(oa[i].getLocalName())) {
         na[p++] = oa[i];
       }
     }
     return new Tag(tag, new TagAttributesImpl(na));
   }
   return tag;
 }
예제 #2
0
 private Tag trimNSAttributes(Tag tag) {
   TagAttribute[] attr = (TagAttribute[]) tag.getAttributes().getAll();
   int remove = 0;
   for (int i = 0; i < attr.length; i++) {
     if (attr[i].getQName().startsWith("xmlns")
         && this.tagLibrary.containsNamespace(attr[i].getValue(), null)) {
       remove |= 1 << i;
       if (log.isLoggable(Level.FINE)) {
         log.fine(attr[i] + " Namespace Bound to TagLibrary");
       }
     }
   }
   if (remove == 0) {
     return tag;
   } else {
     List attrList = new ArrayList(attr.length);
     int p = 0;
     for (int i = 0; i < attr.length; i++) {
       p = 1 << i;
       if ((p & remove) == p) {
         continue;
       }
       attrList.add(attr[i]);
     }
     attr = (TagAttribute[]) attrList.toArray(new TagAttribute[attrList.size()]);
     return new Tag(
         tag.getLocation(),
         tag.getNamespace(),
         tag.getLocalName(),
         tag.getQName(),
         new TagAttributesImpl(attr));
   }
 }
예제 #3
0
 private String[] determineQName(Tag tag) {
   TagAttribute attr = tag.getAttributes().get("jsfc");
   if (attr != null) {
     if (log.isLoggable(Level.FINE)) {
       log.fine(attr + " JSF Facelet Compile Directive Found");
     }
     String value = attr.getValue();
     String namespace, localName;
     int c = value.indexOf(':');
     if (c == -1) {
       namespace = this.namespaceManager.getNamespace("");
       localName = value;
     } else {
       String prefix = value.substring(0, c);
       namespace = this.namespaceManager.getNamespace(prefix);
       if (namespace == null) {
         throw new TagAttributeException(tag, attr, "No Namespace matched for: " + prefix);
       }
       localName = value.substring(c + 1);
     }
     return new String[] {namespace, localName};
   } else {
     return new String[] {tag.getNamespace(), tag.getLocalName()};
   }
 }
예제 #4
0
 /*
  * (non-Javadoc)
  *
  * @see com.sun.facelets.tag.TagDecorator#decorate(com.sun.facelets.tag.Tag)
  */
 @Override
 public Tag decorate(Tag tag) {
   if (XhtmlNamespace.equals(tag.getNamespace())) {
     String n = tag.getLocalName();
     if ("a".equals(n)) {
       return new Tag(
           tag.getLocation(),
           HtmlLibrary.Namespace,
           "commandLink",
           tag.getQName(),
           tag.getAttributes());
     }
     if ("form".equals(n)) {
       return new Tag(
           tag.getLocation(), HtmlLibrary.Namespace, "form", tag.getQName(), tag.getAttributes());
     }
     if ("input".equals(n)) {
       TagAttribute attr = tag.getAttributes().get("type");
       if (attr != null) {
         String t = attr.getValue();
         TagAttributes na = removeType(tag.getAttributes());
         if ("text".equals(t)) {
           return new Tag(
               tag.getLocation(), HtmlLibrary.Namespace, "inputText", tag.getQName(), na);
         }
         if ("password".equals(t)) {
           return new Tag(
               tag.getLocation(), HtmlLibrary.Namespace, "inputSecret", tag.getQName(), na);
         }
         if ("hidden".equals(t)) {
           return new Tag(
               tag.getLocation(), HtmlLibrary.Namespace, "inputHidden", tag.getQName(), na);
         }
         if ("submit".equals(t)) {
           return new Tag(
               tag.getLocation(), HtmlLibrary.Namespace, "commandButton", tag.getQName(), na);
         }
         if ("file".equals(t)) {
           return new Tag(
               tag.getLocation(), HtmlLibrary.Namespace, "inputFile", tag.getQName(), na);
         }
       }
     }
   }
   return null;
 }
예제 #5
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);
    }
  }