Package com.google.caja.lexer

Examples of com.google.caja.lexer.FilePosition


            "k", new ParseTreeNodeContainer(keys),
            "v", new ParseTreeNodeContainer(values)));
  }

  public static Block generateJavascriptDefinitions(HtmlSchema schema) {
    final FilePosition unk = FilePosition.UNKNOWN;
    Map<AttribKey, HTML.Attribute.Type> atypes = attributeTypes(schema);
    Map<ElKey, EnumSet<EFlag>> eflags = elementFlags(schema);
    Map<AttribKey, UriEffect> uriEffects = uriEffects(schema);
    Map<AttribKey, LoaderType> ltypes = loaderTypes(schema);
View Full Code Here


      }
      if (attrsFile == null) {
        throw new IOException("No JSON whitelist for HTML attributes");
      }

      FilePosition elements = FilePosition.startOfFile(new InputSource(
          elementsFile.getAbsoluteFile().toURI()));
      FilePosition attrs = FilePosition.startOfFile(new InputSource(
          attrsFile.getAbsoluteFile().toURI()));

      MessageContext mc = new MessageContext();
      mc.addInputSource(elements.source());
      mc.addInputSource(attrs.source());
      MessageQueue mq = new EchoingMessageQueue(
          new PrintWriter(new OutputStreamWriter(System.err), true), mc, false);

      Set<File> inputsAndDeps = new HashSet<File>();
      for (File f : inputs) { inputsAndDeps.add(f.getAbsoluteFile()); }
      for (File f : deps) { inputsAndDeps.add(f.getAbsoluteFile()); }

      ImportResolver resolver = new AllowedFileResolver(inputsAndDeps);

      HtmlSchema schema;
      try {
        schema = new HtmlSchema(
            ConfigUtil.loadWhiteListFromJson(
                elements.source().getUri(), resolver, mq),
            ConfigUtil.loadWhiteListFromJson(
                attrs.source().getUri(), resolver, mq));
      } catch (ParseException ex) {
        ex.toMessageQueue(mq);
        throw (IOException) new IOException("Failed to parse schema")
            .initCause(ex);
      }
View Full Code Here

    do {
      parseDom(elementStack);
      skipTopLevelDocIgnorables(false);
    } while (!tokens.isEmpty());

    FilePosition endPos = checkEnd(elementStack);

    DocumentFragment root = elementStack.getRootElement();
    Node firstChild = root.getFirstChild();
    if (firstChild == null || firstChild.getNodeType() != Node.ELEMENT_NODE) {
      throw new ParseException(new Message(
View Full Code Here

    return fragment;
  }

  private FilePosition checkEnd(OpenElementStack elementStack)
      throws ParseException {
    FilePosition endPos = tokens.lastPosition();
    if (endPos != null) {
      endPos = FilePosition.endOf(endPos);
    } else // No lastPosition if the queue was empty.
      endPos = FilePosition.startOfFile(tokens.getInputSource());
    }
View Full Code Here

            // Try lower-casing the name to avoid HTML name fuzziness.
            String lQname = Strings.lower(qname);
            if (lQname != qname && (elNs = ns.forElementName(lQname)) != null) {
              qname = lQname;
            } else {
              FilePosition pos = Nodes.getFilePositionFor(el);
              ns = elNs = AbstractElementStack.unknownNamespace(
                  pos, ns, qname, mq);
            }
          }

          Element replacement;
          try {
            replacement = doc.createElementNS(elNs.uri, qname);
          } catch (DOMException e) {
            FilePosition pos = Nodes.getFilePositionFor(el);
            mq.addMessage(MessageType.INVALID_TAG_NAME, MessageLevel.WARNING,
                          FilePosition.startOf(pos),
                          MessagePart.Factory.valueOf(qname));
            if (!asXml) {
              // Try creating a non namespaced element as most likely so will
              // the browser.
              // At this point, we can be sure that createElement will not fail
              // because Html5ElementStack did not ignore this element.
              replacement = doc.createElement(qname);
            } else {
              throw new ParseException(new Message(
                  DomParserMessageType.IGNORING_TOKEN, pos,
                  MessagePart.Factory.valueOf("'" + qname + "'")), e);
            }
          }
          el.getParentNode().replaceChild(replacement, el);
          for (Node child; (child = el.getFirstChild()) != null; ) {
            replacement.appendChild(child);
          }
          NamedNodeMap attrs = el.getAttributes();
          while (attrs.getLength() != 0) {
            Attr a = (Attr) attrs.item(0);
            el.removeAttributeNode(a);
            replacement.setAttributeNodeNS(a);
          }
          if (needsDebugData) {
            Nodes.setFilePositionFor(replacement, Nodes.getFilePositionFor(el));
          }
          node = el = replacement;  // Return the replacement.
        } else {
          elNs = ns.forUri(el.getNamespaceURI());
          if (elNs == null) {
            FilePosition pos = Nodes.getFilePositionFor(el);
            ns = elNs = AbstractElementStack.unknownNamespace(
                pos, ns, el.getTagName(), mq);
          }
        }
        // And finally, namespace all the attributes.
View Full Code Here

        case DIRECTIVE:
          tokens.pop();
          final Function<DOMImplementation, DocumentType> maker
              = DoctypeMaker.parse(t.text);
          if (maker != null) {
            final FilePosition pos = t.pos;
            doctypeMaker = new Function<DOMImplementation, DocumentType>() {
              public DocumentType apply(DOMImplementation impl) {
                DocumentType t = maker.apply(impl);
                Nodes.setFilePositionFor(t, pos);
                return t;
View Full Code Here

    return parser;
  }

  CssParser makeCssParser(CharProducer cp, MessageQueue mq) {
    boolean allowSubsts = shouldAllowCssSubsts();
    FilePosition p = cp.filePositionForOffsets(cp.getOffset(), cp.getLimit());
    TokenQueue<CssTokenType> tq = CssParser.makeTokenQueue(cp, mq, allowSubsts);
    tq.setInputRange(p);
    return new CssParser(tq, mq, getCssTolerance());
  }
View Full Code Here

   */
  public ParseTreeNode parse(UriFetcher fetcher, MessageQueue mq)
      throws ParseException {
    if (type == null) { return null; // Malformed content
    CharProducer cp = getContent(fetcher);
    FilePosition p = cp.filePositionForOffsets(cp.getOffset(), cp.getLimit());
    switch (type) {
      case JS: {
        Parser parser = finder.makeJsParser(cp, mq);
        if (parser.getTokenQueue().isEmpty()) { return new Block(p); }
        return parser.parse();
View Full Code Here

            out.add(fromElementBody(el, expected, scheduling));
          } else {
            out.add(fromExternalReference(el, expected, extRef, scheduling));
          }
        } else {
          FilePosition typePos = Nodes.getFilePositionFor(el);
          Attr a = el.getAttributeNodeNS(TYPE.ns.uri, TYPE.localName);
          if (a != null) {
            typePos = Nodes.getFilePositionForValue(a);
          }
          mq.addMessage(
View Full Code Here

        },
        null, EmbeddedContent.Scheduling.NORMAL, a, t);
  }

  private EmbeddedContent fromBadContent(Element el) {
    final FilePosition pos = FilePosition.startOf(Nodes.getFilePositionFor(el));
    return new EmbeddedContent(
        this, pos,
        new Function<UriFetcher, CharProducer>() {
          public CharProducer apply(UriFetcher fetcher) {
            return CharProducer.Factory.fromString("", pos);
View Full Code Here

TOP

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

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.