Package com.google.caja.lexer

Examples of com.google.caja.lexer.ExternalReference


      CssTree.Import importNode, URI baseUri, int depth, UriFetcher fetcher,
      MessageQueue mq, MutableParseTreeNode.Mutation mut)
      throws ParseException {
    CssTree.UriLiteral uriNode = importNode.getUri();
    // Compute the URI to import
    ExternalReference importUrl = null;
    URI absUri = null;
    URI relUri = null;
    try {
      relUri = new URI(uriNode.getValue());
      absUri = UriUtil.resolve(baseUri, uriNode.getValue());
    } catch (URISyntaxException ex) {
      // handled below.
    }
    if (absUri != null) {
      importUrl = new ExternalReference(
          absUri, baseUri, relUri, uriNode.getFilePosition());
    }
    if (importUrl == null) {
      mq.addMessage(
          PluginMessageType.MALFORMED_URL,
          uriNode.getFilePosition(),
          MessagePart.Factory.valueOf(uriNode.getValue()));
      return;
    }
    assert absUri != null// because absUri == null  ->  importUrl == null

    // Import it and recursively import its imports
    CharProducer cp;
    try {
      cp = fetcher.fetch(importUrl, "text/css").getTextualContent();
    } catch (UriFetcher.UriFetchException ex) {
      mq.addMessage(PluginMessageType.FAILED_TO_LOAD_EXTERNAL_URL,
                    MessageLevel.ERROR, ex.ref.getReferencePosition(),
                    MessagePart.Factory.valueOf(ex.ref.getUri().toString()));
      return;
    } catch (UnsupportedEncodingException ex) {
      mq.addMessage(PluginMessageType.FAILED_TO_LOAD_EXTERNAL_URL,
          MessageLevel.ERROR, importUrl.getReferencePosition(),
          MessagePart.Factory.valueOf(absUri.toString()));
      return;
    }
    CssTree.StyleSheet importedSs = parseCss(cp, mq);
    inlineImports(importedSs, importUrl.getUri(), depth - 1, fetcher, mq);

    // Create a set of blocks to import by taking the union of media types on
    // the import block and the media blocks in the style-sheet.
    List<CssTree.Medium> media = importNode.getMedia();
    if (!media.isEmpty()) {
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);
View Full Code Here

          boolean loaded;
          CharProducer cp = null;
          public CharProducer apply(UriFetcher fetcher) {
            if (!loaded) {
              URI uri = extRef.getUri();
              ExternalReference toLoad = extRef;
              if (!uri.isAbsolute() && baseUri != null) {
                toLoad = new ExternalReference(
                    baseUri.resolve(uri),
                    extRef.getReferencePosition());
              }
              try {
                cp = fetcher.fetch(toLoad, t.mimeType).getTextualContent();
              } catch (UriFetcher.UriFetchException ex) {
                cp = null// Handled below.
              } catch (UnsupportedEncodingException ex) {
                cp = null// Handled below.
              }
              mc.addInputSource(new InputSource(toLoad.getUri()));
              loaded = true;
            }
            if (cp == null) {
              URI srcUri = extRef.getUri();
              String errUri = srcUri.isAbsolute()
View Full Code Here

      mq.getMessages().add(
          new Message(PluginMessageType.MALFORMED_URL, MessageLevel.ERROR,
                      Nodes.getFilePositionFor(attr), a));
      return null;
    }
    return new ExternalReference(uri, Nodes.getFilePositionForValue(attr));
  }
View Full Code Here

            String uriStr = content.getValue();
            try {
              URI baseUri = content.getFilePosition().source().getUri();
              URI relUri = new URI(uriStr);
              URI uri = baseUri.resolve(relUri);
              ExternalReference ref = new ExternalReference(
                  uri, baseUri, relUri, content.getFilePosition());
              Name propertyPart = propertyPart(node)// TODO
              if (uriPolicy != null) {
                String rewritten = UriPolicyNanny.apply(
                    uriPolicy,
View Full Code Here

                URI relUri = new URI(uriStr);
                URI uri = baseUri.resolve(relUri);
                // Rewrite the URI.
                // TODO(mikesamuel): for content: and other URI types, use
                // mime-type of text/*.
                ExternalReference ref = new ExternalReference(
                    uri, baseUri, relUri, content.getFilePosition());
                CssTree.UriLiteral replacement;
                if (uriPolicy != null) {
                  String rewrittenUri = UriPolicyNanny.apply(
                      uriPolicy,
View Full Code Here

      URI relUri = new URI(uri);
      URI absUri = null;
      URI baseAddress = new URI(base);
      absUri = relUri.isAbsolute() ? relUri : baseAddress.resolve(relUri);
      return fetcher.fetch(
          new ExternalReference(absUri, baseAddress, relUri,
              FilePosition.UNKNOWN), "*/*").getTextualContent().toString();
    } catch (URISyntaxException ex) {
      return null;
    } catch (UnsupportedEncodingException ex) {
      return null;
View Full Code Here

TOP

Related Classes of com.google.caja.lexer.ExternalReference

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.