Package com.google.caja.parser

Examples of com.google.caja.parser.Visitor


   * @param importRewriter to rewrite links to sanitizing proxy
   * @param imageRewriter to rewrite links to the sanitizing proxy
   */
  public void sanitize(CssTree css, final Uri linkContext, final LinkRewriter importRewriter,
      final LinkRewriter imageRewriter) {
    css.acceptPreOrder(new Visitor() {
      public boolean visit(AncestorChain<?> ancestorChain) {
        if (ancestorChain.node instanceof CssTree.Property) {
          if (!schema.isPropertyAllowed(((CssTree.Property) ancestorChain.node).
              getPropertyName())) {
            // Remove offending property
View Full Code Here


  /**
   * Get all descendants of the passed node with the specified node type
   */
  public static <T extends CssTree> List<T> descendants(CssTree node, final Class<T> nodeType) {
    final List<T> descendants = Lists.newArrayList();
    node.acceptPreOrder(new Visitor() {
      public boolean visit(AncestorChain<?> ancestorChain) {
        if (nodeType.isAssignableFrom(ancestorChain.node.getClass())) {
          descendants.add(nodeType.cast(ancestorChain.node));
        }
        return true;
View Full Code Here

   * @param importRewriter to rewrite links to sanitizing proxy
   * @param imageRewriter to rewrite links to the sanitizing proxy
   */
  public void sanitize(CssTree css, final Uri linkContext, final LinkRewriter importRewriter,
      final LinkRewriter imageRewriter) {
    css.acceptPreOrder(new Visitor() {
      public boolean visit(AncestorChain<?> ancestorChain) {
        if (ancestorChain.node instanceof CssTree.Property) {
          if (!schema.isPropertyAllowed(((CssTree.Property) ancestorChain.node).
              getPropertyName())) {
            // Remove offending property
View Full Code Here

      throw new SomethingWidgyHappenedError(msg, ex);
    }
  }

  private static Statement stripBlocks(Block b) {
    b.acceptPostOrder(new Visitor() {
      public boolean visit(AncestorChain<?> chain) {
        if (chain.node instanceof Block && chain.parent != null) {
          Block b = chain.cast(Block.class).node;
          List<? extends Statement> children = b.children();
          switch (children.size()) {
View Full Code Here

  }

  private static void optimizeWithin(FunctionConstructor fc) {
    final Map<LitVal, LitVal> uses = Maps.newLinkedHashMap();
    Block body = fc.getBody();
    body.acceptPreOrder(new Visitor() {
      public boolean visit(AncestorChain<?> chain) {
        if (chain.node instanceof Literal
            && !(chain.node instanceof RegexpLiteral)) {
          AncestorChain<Literal> litAc = chain.cast(Literal.class);
          LitVal key = new LitVal(litAc);
View Full Code Here

      propertiesAllowed.add(Name.css(k));
    }

    // Examine the property signatures and extract a list of keywords
    for (CssPropertyInfo pi : properties.values()) {
      pi.sig.acceptPreOrder(new Visitor() {
        public boolean visit(AncestorChain<?> ancestors) {
          ParseTreeNode n = ancestors.node;
          if (n instanceof CssPropertySignature.LiteralSignature) {
            String kw = ((CssPropertySignature.LiteralSignature) n).value;
            keywords.add(Name.css(kw));
          }
          return true;
        }
      }, null);
    }
    for (SymbolInfo si : symbols.values()) {
      si.sig.acceptPreOrder(new Visitor() {
        public boolean visit(AncestorChain<?> ancestors) {
          ParseTreeNode n = ancestors.node;
          if (n instanceof CssPropertySignature.LiteralSignature) {
            String kw = ((CssPropertySignature.LiteralSignature) n).value;
            keywords.add(Name.css(kw));
View Full Code Here

  private static void unvar(
      Block node, final Set<Identifier> removedIdents,
      final List<FunctionConstructor> inners) {
    final List<Pair<AncestorChain<Statement>, Statement>> changes
        = Lists.newArrayList();
    node.acceptPreOrder(new Visitor() {
      public boolean visit(AncestorChain<?> chain) {
        ParseTreeNode node = chain.node;
        if (node instanceof Declaration
            && !(node instanceof FunctionDeclaration)) {
          if (chain.parent.node instanceof CatchStmt) { return true; }
View Full Code Here

  public static List<String> rewrite(CssTree.StyleSheet styleSheet, final Uri source,
      final UriMaker uriMaker, final boolean extractImports, final GadgetContext gadgetContext) {
    final List<String> imports = Lists.newLinkedList();
    final List<CssTree.UriLiteral> skip = Lists.newLinkedList();

    styleSheet.acceptPreOrder(new Visitor() {
      public boolean visit(AncestorChain<?> chain) {
        if (chain.node instanceof CssTree.Import) {
          CssTree.Import importNode = (CssTree.Import) chain.node;
          CssTree.UriLiteral uriLiteral = importNode.getUri();
          skip.add(importNode.getUri());
View Full Code Here

   * @param importRewriter to rewrite links to sanitizing proxy
   * @param imageRewriter to rewrite links to the sanitizing proxy
   */
  public void sanitize(CssTree css, final Uri linkContext, final GadgetContext gadgetContext,
                       final ProxyUriManager importRewriter, final ProxyUriManager imageRewriter) {
    css.acceptPreOrder(new Visitor() {
      public boolean visit(AncestorChain<?> ancestorChain) {
        if (ancestorChain.node instanceof CssTree.Property) {
          if (!schema.isPropertyAllowed(((CssTree.Property) ancestorChain.node).
              getPropertyName())) {
            // Remove offending property
View Full Code Here

  /**
   * Get all descendants of the passed node with the specified node type
   */
  public static <T extends CssTree> List<T> descendants(CssTree node, final Class<T> nodeType) {
    final List<T> descendants = Lists.newArrayList();
    node.acceptPreOrder(new Visitor() {
      public boolean visit(AncestorChain<?> ancestorChain) {
        if (nodeType.isAssignableFrom(ancestorChain.node.getClass())) {
          descendants.add(nodeType.cast(ancestorChain.node));
        }
        return true;
View Full Code Here

TOP

Related Classes of com.google.caja.parser.Visitor

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.