Package com.google.caja.lexer

Examples of com.google.caja.lexer.InputSource


  }

  public static ParseTreeNode parse(String src) throws Exception {
    MessageContext mc = new MessageContext();
    MessageQueue mq = TestUtil.createTestMessageQueue(mc);
    InputSource is = new InputSource(new URI("file:///no/input/source"));
    CharProducer cp = CharProducer.Factory.create(new StringReader(src), is);
    JsLexer lexer = new JsLexer(cp);
    JsTokenQueue tq = new JsTokenQueue(lexer, is, JsTokenQueue.NO_COMMENT);
    Parser p = new Parser(tq, mq);
    Statement stmt = p.parse();
View Full Code Here


        throws UriFetchException {
      try {
        URI uri = ref.getReferencePosition().source().getUri()
            .resolve(ref.getUri());
        if ("resource".equals(uri.getScheme())) {
          return dataFromResource(uri.getPath(), new InputSource(uri));
        } else {
          throw new UriFetchException(ref, mimeType);
        }
      } catch (IOException ex) {
        throw new UriFetchException(ref, mimeType, ex);
View Full Code Here

        throws UriFetchException {
      try {
        URI uri = ref.getReferencePosition().source().getUri()
            .resolve(ref.getUri());
        if ("resource".equals(uri.getScheme())) {
          return dataFromResource(uri.getPath(), new InputSource(uri));
        } else {
          throw new UriFetchException(ref, mimeType);
        }
      } catch (IOException ex) {
        throw new UriFetchException(ref, mimeType, ex);
View Full Code Here

                          boolean pretty, MessageQueue mq) {
    PluginCompiler compiler = null;
    boolean okToContinue = true;

    try {
      InputSource is = new InputSource (inputUri);
      compiler = new PluginCompiler(buildInfo, meta, mq);

      if (htmlInline) {
        compiler.setGoals(
            compiler.getGoals().without(PipelineMaker.HTML_SAFE_STATIC));
View Full Code Here

          return null;
        }
      } else {
        try {
          inputFetchedData = FetchedData.fromReader(new StringReader(content),
              new InputSource(inputUri), expectedInputContentType,
              Charsets.UTF_8.displayName());
        } catch (IOException e) {
          return null;
        }
      }
    }

    if (!typeCheck.check(
            expectedInputContentType,
            inputFetchedData.getContentType())) {
      mq.addMessage(
          ServiceMessageType.UNEXPECTED_INPUT_MIME_TYPE,
          MessagePart.Factory.valueOf(expectedInputContentType),
          MessagePart.Factory.valueOf(inputFetchedData.getContentType()));
      return null;
    }

    String transformName = CajaArguments.TRANSFORM.get(args);
    Transform transform = null;
    if (transformName != null) {
      try {
        transform = Transform.valueOf(transformName);
      } catch (Exception e) {
        mq.addMessage(
            ServiceMessageType.INVALID_ARGUMENT,
            MessagePart.Factory.valueOf(transformName),
            MessagePart.Factory.valueOf(CajaArguments.TRANSFORM.toString()));
        return null;
      }
    }

    // TODO(jasvir): Change CajaArguments to handle >1 occurrence of arg
    String directiveName = CajaArguments.DIRECTIVE.get(args);
    List<Directive> directive = Lists.newArrayList();
    if (directiveName != null) {
      try {
        directive.add(Directive.valueOf(directiveName));
      } catch (Exception e) {
        mq.addMessage(
            ServiceMessageType.INVALID_ARGUMENT,
            MessagePart.Factory.valueOf(directiveName),
            MessagePart.Factory.valueOf(CajaArguments.DIRECTIVE.toString()));
        return null;
      }
    }

    ByteArrayOutputStream intermediateResponse = new ByteArrayOutputStream();
    Pair<String, String> contentInfo;
    try {
      contentInfo = applyHandler(
          inputUri,
          transform,
          directive,
          args,
          inputFetchedData.getContentType(),
          inputFetchedData,
          intermediateResponse,
          mq);
    } catch (UnsupportedContentTypeException e) {
      mq.addMessage(ServiceMessageType.UNSUPPORTED_CONTENT_TYPES);
      return null;
    } catch (RuntimeException e) {
      mq.addMessage(
          ServiceMessageType.EXCEPTION_IN_SERVICE,
          MessagePart.Factory.valueOf(e.toString()));
      return null;
    }

    return FetchedData.fromBytes(
        intermediateResponse.toByteArray(),
        contentInfo.a,
        contentInfo.b,
        new InputSource(inputUri));
  }
View Full Code Here

    return snippet.toString();
  }

  public final void appendSnippet(FilePosition pos, Appendable out)
      throws IOException {
    InputSource src = pos.source();
    CharSequence sourceCode = originalSource.get(src);
    if (sourceCode == null) { return; // Can't write.

    // Pick a representative line from pos.
    int lineNo = pos.startLineNo();
View Full Code Here

    URI uri = ref.getUri();
    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

    OutputStreamWriter writer;
    try {
      writer = new OutputStreamWriter(response, Charsets.UTF_8);
      FetchedData result = uriFetcher.fetch(
        new ExternalReference(uri, uri, uri,
          FilePosition.startOfFile(new InputSource(uri))), "*/*");
      if (checker.check("text/css", result.getContentType()) ||
          checker.check("text/javascript", result.getContentType())) {
        renderAsJSON(
          result.getTextualContent().toString(),
          null,
View Full Code Here

                        boolean pretty,
                        MessageQueue mq) {
    CajoledModule cajoledModule = null;
    try {
      Block input = (Block) new ParserContext(mq)
          .withInput(new InputSource(inputUri))
          .withInput(ContentType.JS)
          .withInput(cp)
          .build();

      UncajoledModule ucm = new UncajoledModule(input);
View Full Code Here

      PluginCompiler pluginc) {
    boolean parsePassed = true;
    for (URI input : inputs) {
      try {
        ParseTreeNode parseTree = new ParserContext(mq)
            .withInput(new InputSource(input))
            .withConfig(meta)
            .withConfig(mc)
            .withSourceMap(originalSources)
            .build();
        if (null != parseTree) { pluginc.addInput(parseTree, input); }
View Full Code Here

TOP

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

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.