コード例 #1
0
  /**
   * Look up the index of an attribute by Namespace name.
   *
   * @param uri The Namespace URI, or the empty string if the name has no Namespace URI.
   * @param localName The attribute's local name.
   * @return The index of the attribute, or -1 if it does not appear in the list.
   */
  public int getIndex(String uri, String localName) {
    Vector attributes;
    int size;
    Attribute attribute;
    String string;
    int ret;

    ret = -1;

    attributes = mTag.getAttributesEx();
    if (null != attributes) {
      size = attributes.size();
      for (int i = 1; i < size; i++) {
        attribute = (Attribute) attributes.elementAt(i);
        string = attribute.getName();
        if (null != string) // not whitespace
        {
          mSupport.processName(string, mParts, true);
          if (uri.equals(mParts[0]) & localName.equalsIgnoreCase(mParts[1])) {
            ret = i;
            i = size; // exit fast
          }
        }
      }
    }

    return (ret);
  }
コード例 #2
0
  /**
   * Look up an attribute's value by index.
   *
   * <p>If the attribute value is a list of tokens (IDREFS, ENTITIES, or NMTOKENS), the tokens will
   * be concatenated into a single string with each token separated by a single space.
   *
   * @param index The attribute index (zero-based).
   * @return The attribute's value as a string, or null if the index is out of range.
   * @see #getLength
   */
  public String getValue(int index) {
    Attribute attribute;
    String ret;

    attribute = (Attribute) (mTag.getAttributesEx().elementAt(index + 1));
    ret = attribute.getValue();
    if (null == ret) ret = "";

    return (ret);
  }
コード例 #3
0
  /**
   * Look up an attribute's XML qualified (prefixed) name by index.
   *
   * @param index The attribute index (zero-based).
   * @return The XML qualified name, or the empty string if none is available, or null if the index
   *     is out of range.
   * @see #getLength
   */
  public String getQName(int index) {
    Attribute attribute;
    String ret;

    attribute = (Attribute) (mTag.getAttributesEx().elementAt(index + 1));
    if (attribute.isWhitespace()) ret = "#text";
    else ret = attribute.getName();

    return (ret);
  }
コード例 #4
0
 @Override
 public void visitTag(Tag tag) {
   Element e = Document.get().createElement(tag.getTagName());
   map.put(tag, e);
   for (Object o : tag.getAttributesEx()) {
     Attribute a = (Attribute) o;
     if ("id".equalsIgnoreCase(a.getName())) {
       e.setId(a.getValue());
     } else if ("style".equalsIgnoreCase(a.getName())) {
       processStyle(e, a.getValue());
     } else if ("class".equalsIgnoreCase(a.getName())) {
       e.setClassName(a.getValue());
     } else if (!a.isEmpty() && !a.isWhitespace() && a.isValued()) {
       e.setAttribute(a.getName(), a.getValue());
     }
   }
   Element parent = getParent(tag.getParent());
   parent.appendChild(e);
 }
コード例 #5
0
ファイル: SafeHtml.java プロジェクト: 3mtee/jforum
  /**
   * Given a tag, check its attributes, removing those unwanted or not secure
   *
   * @param tag The tag to analyze
   * @param checkIfAttributeIsWelcome true if the attribute name should be matched against the list
   *     of welcome attributes, set in the main configuration file.
   */
  private void checkAndValidateAttributes(Tag tag, boolean checkIfAttributeIsWelcome) {
    Vector<Attribute> newAttributes = new Vector<Attribute>();

    for (Iterator<?> iter = tag.getAttributesEx().iterator(); iter.hasNext(); ) {
      Attribute a = (Attribute) iter.next();

      String name = a.getName();

      if (name == null) {
        newAttributes.add(a);
      } else {
        name = name.toUpperCase();

        if (a.getValue() == null) {
          newAttributes.add(a);
          continue;
        }

        String value = a.getValue().toLowerCase();

        if (checkIfAttributeIsWelcome && !this.isAttributeWelcome(name)) {
          continue;
        }

        if (!this.isAttributeSafe(name, value)) {
          continue;
        }

        if (a.getValue().indexOf("&#") > -1) {
          a.setValue(a.getValue().replaceAll("&#", "&amp;#"));
        }

        newAttributes.add(a);
      }
    }

    tag.setAttributesEx(newAttributes);
  }
コード例 #6
0
 /**
  * Return the number of attributes in the list.
  *
  * <p>Once you know the number of attributes, you can iterate through the list.
  *
  * @return The number of attributes in the list.
  * @see #getURI(int)
  * @see #getLocalName(int)
  * @see #getQName(int)
  * @see #getType(int)
  * @see #getValue(int)
  */
 public int getLength() {
   return (mTag.getAttributesEx().size() - 1);
 }