Package com.google.caja.util

Examples of com.google.caja.util.ContentType


  private void findEmbeddedContent(Node node, List<EmbeddedContent> out) {
    if (node instanceof Element) {
      Element el = (Element) node;
      ElKey key = ElKey.forElement(el);
      ContentType expected = null;
      ExternalReference extRef = null;
      String defaultMimeType = null;
      EmbeddedContent.Scheduling scheduling = EmbeddedContent.Scheduling.NORMAL;
      if (SCRIPT.equals(key)) {
        expected = ContentType.JS;
        extRef = externalReferenceFromAttr(el, SCRIPT_SRC);
        if (Strings.eqIgnoreCase(
            "defer",
            el.getAttributeNS(SCRIPT_DEFER.ns.uri, SCRIPT_DEFER.localName))) {
          scheduling = EmbeddedContent.Scheduling.DEFERRED;
        } else if (Strings.eqIgnoreCase(
            "async",
            el.getAttributeNS(SCRIPT_ASYNC.ns.uri, SCRIPT_ASYNC.localName))) {
          scheduling = EmbeddedContent.Scheduling.ASYNC;
        }
      } else if (STYLE.equals(key)) {
        expected = ContentType.CSS;
      } else if (LINK.equals(key)
                 && Strings.eqIgnoreCase(
                     "stylesheet",
                     el.getAttributeNS(LINK_REL.ns.uri, LINK_REL.localName))) {
        extRef = externalReferenceFromAttr(el, LINK_HREF);
        if (extRef != null) {
          expected = ContentType.CSS;
          defaultMimeType = ContentType.CSS.mimeType;
        }
      }
      if (expected != null) {
        String mimeType = getMimeTypeFromHtmlTypeAttribute(el, key);
        if (mimeType == null) { mimeType = defaultMimeType; }
        ContentType actualType = mimeType != null
            ? ContentType.fromMimeType(mimeType) : null;
        if (actualType == expected) {
          if (extRef == null) {
            out.add(fromElementBody(el, expected, scheduling));
          } else {
View Full Code Here


    File f = uriToFile.apply(uri);
    if (f == null) { throw new UriFetchException(ref, mimeType); }
    try {
      CharProducer cp = CharProducer.Factory.create(
          newReader(f), new InputSource(uri));
      ContentType ct = GuessContentType.guess(null, f.getName(), cp);
      return FetchedData.fromCharProducer(
          cp, ct != null ? ct.mimeType : "", Charsets.UTF_8.name());
    } catch (IOException ex) {
      throw new UriFetchException(ref, mimeType, ex);
    }
View Full Code Here

   * @return a known {@link ContentType} or null if none could be found.
   */
  public static ContentType guess(
      @Nullable String mimeType, @Nullable String path,
      @Nullable CharSequence code) {
    ContentType contentType = null;
    if (mimeType != null) { contentType = ContentType.fromMimeType(mimeType); }
    if (contentType == null && path != null) {
      int dot = path.lastIndexOf('.');
      if (dot >= 0) {
        String ext = path.substring(dot + 1);
View Full Code Here

  private final ParseTreeNode root;
  private final ContentType type;
  private final URI baseUri;

  public static Job job(ParseTreeNode rootNode, URI baseUri) {
    ContentType type;
    if (rootNode instanceof Statement
        || rootNode instanceof Expression
        || rootNode instanceof UncajoledModule
        || rootNode instanceof CajoledModule) {
      type = ContentType.JS;
View Full Code Here

  private void findEmbeddedContent(Node node, List<EmbeddedContent> out) {
    if (node instanceof Element) {
      Element el = (Element) node;
      ElKey key = ElKey.forElement(el);
      ContentType expected = null;
      ExternalReference extRef = null;
      String defaultMimeType = null;
      boolean deferred = false;
      if (SCRIPT.equals(key)) {
        expected = ContentType.JS;
        extRef = externalReferenceFromAttr(el, SCRIPT_SRC);
        deferred = Strings.eqIgnoreCase(
            "defer",
            el.getAttributeNS(SCRIPT_DEFER.ns.uri, SCRIPT_DEFER.localName));
      } else if (STYLE.equals(key)) {
        expected = ContentType.CSS;
      } else if (LINK.equals(key)
                 && Strings.eqIgnoreCase(
                     "stylesheet",
                     el.getAttributeNS(LINK_REL.ns.uri, LINK_REL.localName))) {
        extRef = externalReferenceFromAttr(el, LINK_HREF);
        if (extRef != null) {
          expected = ContentType.CSS;
          defaultMimeType = ContentType.CSS.mimeType;
        }
      }
      if (expected != null) {
        String mimeType = getMimeTypeFromHtmlTypeAttribute(el, key);
        if (mimeType == null) { mimeType = defaultMimeType; }
        ContentType actualType = mimeType != null
            ? ContentType.fromMimeType(mimeType) : null;
        if (actualType == expected) {
          if (extRef == null) {
            out.add(fromElementBody(el, expected, deferred));
          } else {
View Full Code Here

TOP

Related Classes of com.google.caja.util.ContentType

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.