Package com.google.caja.parser.html

Examples of com.google.caja.parser.html.ElKey


      }
    });
  }

  private static Map<ElKey, EnumSet<EFlag>> elementFlags(HtmlSchema schema) {
    final ElKey SCRIPT = ElKey.forHtmlElement("script");
    final ElKey STYLE = ElKey.forHtmlElement("style");
    Map<ElKey, EnumSet<EFlag>> elementFlags = Maps.newTreeMap();
    for (ElKey elementName : schema.getElementNames()) {
      HTML.Element el = schema.lookupElement(elementName);
      EnumSet<EFlag> flags = EnumSet.noneOf(EFlag.class);
      if (el.isEndTagOptional()) { flags.add(EFlag.OPTIONAL_ENDTAG); }
      if (el.isEmpty()) { flags.add(EFlag.EMPTY); }
      if (elementName.isHtml()) {
        switch (HtmlTextEscapingMode.getModeForTag(elementName.localName)) {
          case CDATA:
            flags.add(EFlag.CDATA);
            break;
          case RCDATA:
            flags.add(EFlag.RCDATA);
            break;
          default: break;
        }
      }
      if (!schema.isElementAllowed(elementName)) {
        flags.add(EFlag.UNSAFE);
        if (SCRIPT.equals(elementName)) {
          flags.add(EFlag.SCRIPT);
        } else if (STYLE.equals(elementName)) {
          flags.add(EFlag.STYLE);
        }
      }
      if (HtmlSchema.isElementFoldable(elementName)) {
        flags.add(EFlag.FOLDABLE);
View Full Code Here


        = Multimaps.newListHashMultimap();
    for (WhiteList.TypeDefinition def : attribList.typeDefinitions().values()) {
      String key = Strings.lower((String) def.get("key", null));
      AttribKey elAndAttrib = attribKey(key);
      if (elAndAttrib == null) { throw new NullPointerException(key); }
      ElKey element = elAndAttrib.el;
      HTML.Attribute.Type type = HTML.Attribute.Type.NONE;
      String typeName = (String) def.get("type", null);
      if (typeName != null) {
        // TODO(mikesamuel): divert IllegalArgumentExceptions to MessageQueue
        type = HTML.Attribute.Type.valueOf(typeName);
      }
      String loaderTypeStr = (String) def.get("loaderType", null);
      // TODO(mikesamuel): divert IllegalArgumentExceptions to MessageQueue
      LoaderType loaderType = loaderTypeStr != null
          ? LoaderType.valueOf(loaderTypeStr) : null;
      String uriEffectStr = (String) def.get("uriEffect", null);
      // TODO(mikesamuel): divert IllegalArgumentExceptions to MessageQueue
      UriEffect uriEffect = uriEffectStr != null
          ? UriEffect.valueOf(uriEffectStr) : null;
      RegularCriterion elCriterion = criteria.get(elAndAttrib);
      RegularCriterion wcCriterion = criteria.get(elAndAttrib.onAnyElement());
      RegularCriterion criterion = conjunction(elCriterion, wcCriterion);
      String defaultValue = (String) def.get("default", null);
      boolean optional = Boolean.TRUE.equals(def.get("optional", true));
      String safeValue = (String) def.get("safeValue", null);
      if (safeValue == null) {
        String candidate = defaultValue != null ? defaultValue : "";
        if (criterion.accept(candidate)) {
          safeValue = candidate;
        } else {
          String values = (String) def.get("values", null);
          if (values != null) {
            safeValue = values.split(",")[0];
          }
        }
      }
      boolean valueless = Boolean.TRUE.equals(def.get("valueless", false));
      // For valueless attributes, like checked, we allow the blank value.
      if (valueless && !criterion.accept("")) {
        criterion = RegularCriterion.Factory.or(
            criterion,
            RegularCriterion.Factory.fromValueSet(Collections.singleton("")));
      }

      HTML.Attribute a = new HTML.Attribute(
          elAndAttrib, type, defaultValue, safeValue, valueless, optional,
          loaderType, uriEffect, criterion);
      attributeDetails.put(elAndAttrib, a);
      attributeDetailsByElement.put(element, a);
    }

    this.attributesForUnknownHTMLElement = Collections.unmodifiableList(
        Lists.newArrayList(attributeDetailsByElement.get(ElKey.HTML_WILDCARD)));

    this.allowedElements = Sets.newHashSet();
    for (String qualifiedName : tagList.allowedItems()) {
      allowedElements.add(
          ElKey.forElement(Namespaces.HTML_DEFAULT, qualifiedName));
    }
    this.elementDetails = Maps.newHashMap();
    for (WhiteList.TypeDefinition def : tagList.typeDefinitions().values()) {
      String qualifiedTagName = (String) def.get("key", null);
      ElKey key = ElKey.forElement(Namespaces.HTML_DEFAULT, qualifiedTagName);
      Collection<HTML.Attribute> specific = attributeDetailsByElement.get(key);
      ElKey wc = ElKey.wildcard(key.ns);
      Collection<HTML.Attribute> general = attributeDetailsByElement.get(wc);
      List<HTML.Attribute> attrs = Lists.newArrayList(specific);
      if (!general.isEmpty()) {
        Set<AttribKey> present = Sets.newHashSet();
        for (HTML.Attribute a : attrs) {
View Full Code Here

    if (separator == -1) {
      throw new IllegalArgumentException("no :: in: " + key);
    }
    String elQName = key.substring(0, separator);
    String attrQName = key.substring(separator + 2);
    ElKey el = ElKey.forElement(Namespaces.HTML_DEFAULT, elQName);
    if (el == null) { throw new NullPointerException(elQName); }
    AttribKey a = AttribKey.forAttribute(
        Namespaces.HTML_DEFAULT, el, attrQName);
    if (a == null) { throw new NullPointerException(attrQName); }
    return a;
View Full Code Here

        = Multimaps.newListHashMultimap();
    for (WhiteList.TypeDefinition def : attribList.typeDefinitions().values()) {
      String key = Strings.lower((String) def.get("key", null));
      AttribKey elAndAttrib = attribKey(key);
      if (elAndAttrib == null) { throw new NullPointerException(key); }
      ElKey element = elAndAttrib.el;
      HTML.Attribute.Type type = HTML.Attribute.Type.NONE;
      String typeName = (String) def.get("type", null);
      if (typeName != null) {
        // TODO(mikesamuel): divert IllegalArgumentExceptions to MessageQueue
        type = HTML.Attribute.Type.valueOf(typeName);
      }
      String loaderTypeStr = (String) def.get("loaderType", null);
      // TODO(mikesamuel): divert IllegalArgumentExceptions to MessageQueue
      LoaderType loaderType = loaderTypeStr != null
          ? LoaderType.valueOf(loaderTypeStr) : null;
      String uriEffectStr = (String) def.get("uriEffect", null);
      // TODO(mikesamuel): divert IllegalArgumentExceptions to MessageQueue
      UriEffect uriEffect = uriEffectStr != null
          ? UriEffect.valueOf(uriEffectStr) : null;
      RegularCriterion elCriterion = criteria.get(elAndAttrib);
      RegularCriterion wcCriterion = criteria.get(elAndAttrib.onAnyElement());
      RegularCriterion criterion = conjunction(elCriterion, wcCriterion);
      String defaultValue = (String) def.get("default", null);
      boolean optional = Boolean.TRUE.equals(def.get("optional", true));
      String safeValue = (String) def.get("safeValue", null);
      if (safeValue == null) {
        String candidate = defaultValue != null ? defaultValue : "";
        if (criterion.accept(candidate)) {
          safeValue = candidate;
        } else {
          String values = (String) def.get("values", null);
          if (values != null) {
            safeValue = values.split(",")[0];
          }
        }
      }
      boolean valueless = Boolean.TRUE.equals(def.get("valueless", false));
      // For valueless attributes, like checked, we allow the blank value.
      if (valueless && !criterion.accept("")) {
        criterion = RegularCriterion.Factory.or(
            criterion,
            RegularCriterion.Factory.fromValueSet(Collections.singleton("")));
      }

      HTML.Attribute a = new HTML.Attribute(
          elAndAttrib, type, defaultValue, safeValue, valueless, optional,
          loaderType, uriEffect, criterion);
      attributeDetails.put(elAndAttrib, a);
      attributeDetailsByElement.put(element, a);
    }

    this.attributesForUnknownHTMLElement = Collections.unmodifiableList(
        Lists.newArrayList(attributeDetailsByElement.get(ElKey.HTML_WILDCARD)));

    this.allowedElements = Sets.newHashSet();
    for (String qualifiedName : tagList.allowedItems()) {
      allowedElements.add(
          ElKey.forElement(Namespaces.HTML_DEFAULT, qualifiedName));
    }
    this.elementDetails = Maps.newHashMap();
    for (WhiteList.TypeDefinition def : tagList.typeDefinitions().values()) {
      String qualifiedTagName = (String) def.get("key", null);
      ElKey key = ElKey.forElement(Namespaces.HTML_DEFAULT, qualifiedTagName);
      Collection<HTML.Attribute> specific = attributeDetailsByElement.get(key);
      ElKey wc = ElKey.wildcard(key.ns);
      Collection<HTML.Attribute> general = attributeDetailsByElement.get(wc);
      List<HTML.Attribute> attrs = Lists.newArrayList(specific);
      if (!general.isEmpty()) {
        Set<AttribKey> present = Sets.newHashSet();
        for (HTML.Attribute a : attrs) {
View Full Code Here

    if (separator == -1) {
      throw new IllegalArgumentException("no :: in: " + key);
    }
    String elQName = key.substring(0, separator);
    String attrQName = key.substring(separator + 2);
    ElKey el = ElKey.forElement(Namespaces.HTML_DEFAULT, elQName);
    if (el == null) { throw new NullPointerException(elQName); }
    AttribKey a = AttribKey.forAttribute(
        Namespaces.HTML_DEFAULT, el, attrQName);
    if (a == null) { throw new NullPointerException(attrQName); }
    return a;
View Full Code Here

    boolean valid = true;
    switch (t.getNodeType()) {
      case Node.ELEMENT_NODE:
      {
        Element el = (Element) t;
        ElKey elKey = ElKey.forElement(el);

        if (isElementIgnorable(elKey)) {
          return removeElement(el);

        } else if (schema.isElementVirtualized(elKey)) {
View Full Code Here

    return "noscript".equals(lcName) || "noembed".equals(lcName)
        || "noframes".equals(lcName);
  }

  private boolean removeElement(Element el) {
    ElKey elKey = ElKey.forElement(el);
    Node p = el.getParentNode();
    if (p != null) {
      mq.getMessages().add(new Message(IhtmlMessageType.IGNORED_TAG,
          Nodes.getFilePositionFor(el), elKey));
      p.removeChild(el);
View Full Code Here

   */
  private boolean validateSimpleSelector(CssTree.SimpleSelector sel) {
    boolean valid = true;
    if (null != sel.getElementName()) {
      String elName = sel.getElementName();
      ElKey elKey = ElKey.forElement(Namespaces.HTML_DEFAULT, elName);
      if (null != htmlSchema.lookupElement(elKey)) {
        if (!htmlSchema.isElementVirtualized(elKey) &&
            !htmlSchema.isElementAllowed(elKey)) {
          mq.addMessage(
              PluginMessageType.UNSAFE_TAG, invalidNodeMessageLevel,
View Full Code Here

    return valid;
  }

  private boolean validateAllAttribs(CssTree.SimpleSelector sel) {
    String qname = sel.getElementName();
    ElKey el;
    if (qname == null) {
      el = ElKey.HTML_WILDCARD;
    } else {
      el = ElKey.forElement(Namespaces.HTML_DEFAULT, qname);
    }
View Full Code Here

  }

  private static boolean containsOnlyText(Node n) {
    if (!(n instanceof Element)) { return false; }
    Element el = (Element) n;
    ElKey schemaKey = ElKey.forElement(el);
    if (schemaKey.isHtml()) {
      HtmlTextEscapingMode mode = HtmlTextEscapingMode.getModeForTag(
          schemaKey.localName);
      return mode != HtmlTextEscapingMode.PCDATA;
    } else {
      return false;
View Full Code Here

TOP

Related Classes of com.google.caja.parser.html.ElKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.