Package com.google.caja

Examples of com.google.caja.SomethingWidgyHappenedError


    connection.connect();
    URI uri;
    try {
      uri = connection.getURL().toURI();
    } catch (URISyntaxException ex) {
      throw new SomethingWidgyHappenedError(ex);
    }
    return fromBytes(
        readStream(connection.getInputStream()),
        connection.getContentType(),
        getCharSet(connection),
View Full Code Here


                    attrSrc, ConfigUtil.RESOURCE_RESOLVER, cacheMq)),
            cacheMq.getMessages());
      // If the default schema is borked, there's not much we can do.
      } catch (IOException ex) {
        mq.getMessages().addAll(cacheMq.getMessages());
        throw new SomethingWidgyHappenedError("Default schema is borked", ex);
      } catch (ParseException ex) {
        cacheMq.getMessages().add(ex.getCajaMessage());
        mq.getMessages().addAll(cacheMq.getMessages());
        throw new SomethingWidgyHappenedError("Default schema is borked", ex);
      }
    }
    mq.getMessages().addAll(defaultSchema.b);
    return defaultSchema.a;
  }
View Full Code Here

      case Node.TEXT_NODE:
      case Node.CDATA_SECTION_NODE:
      case Node.COMMENT_NODE:
        break;
      default:
        throw new SomethingWidgyHappenedError(t.getNodeName());
    }
    for (Node child : Nodes.childrenOf(t)) {
      valid &= sanitize(child);
    }
    return valid;
View Full Code Here

    Writer out = new OutputStreamWriter(
        new FileOutputStream(output), Charsets.UTF_8.name());
    try {
      String currentDate = "" + new Date();
      if (currentDate.indexOf("*/") >= 0) {
        throw new SomethingWidgyHappenedError("Date should not contain '*/'");
      }

      out.write("/* Copyright Google Inc.\n");
      out.write(" * Licensed under the Apache Licence Version 2.0\n");
      out.write(" * Autogenerated at " + currentDate + "\n");
View Full Code Here

        } else if (jsValue.children().size() == 1) {
          // Declarations have been reduced to a single, statically known
          // StringLiteral or dynamically computed Expression
          dynamicValue = jsValue.children().get(0);
        } else {
          throw new SomethingWidgyHappenedError(
              "Rewriter thinks STYLE attribute should contain plugin ID");
        }
        break;
      case URI:
        if (attributeContent.containsKey(attr.src)) {  // A javascript: URI
          Block b = this.jsFromAttrib(attr);
          if (b == null || b.children().isEmpty()) { return noResult(attr); }

          String handlerIndexName = meta.generateUniqueName("c");
          Identifier handlerIndex = SyntheticNodes.s(new Identifier(
              FilePosition.UNKNOWN, handlerIndexName));
          Statement handler = (Statement) QuasiBuilder.substV(
              ""
              + "var @handlerIndex = IMPORTS___.handlers___.push("
              + "    ___./*@synthetic*/markFuncFreeze("
              // There is no node or event object available to code in
              // javascript: URIs.
              + "        /*@synthetic*/function () { @body*; })) - 1;",
              "handlerIndex", handlerIndex,
              "body", new ParseTreeNodeContainer(b.children()));
          handlers.add(new EventHandler(attr.env, handler));
          handlerCache.put(value, handlerIndexName);

          Operation urlAdapter = (Operation) QuasiBuilder.substV(
              ""
              + "'javascript:' + /*@synthetic*/encodeURIComponent("
              + "   'try{void ___.plugin_dispatchToHandler___('"
              + "    + ___./*@synthetic*/getId(IMPORTS___)"
              + "    + ',' + @handlerIndex + ',[{}])}catch(_){}')",
              "handlerIndex", new Reference(handlerIndex));
          urlAdapter.setFilePosition(pos);
          urlAdapter.getAttributes().set(HANDLER_NAME, handlerIndexName);
          dynamicValue = urlAdapter;
        } else {
          URI uri;
          try {
            uri = new URI(UriUtil.normalizeUri(value));
          } catch (URISyntaxException ex) {
            mq.addMessage(
                IhtmlMessageType.MALFORMED_URI, pos,
                MessagePart.Factory.valueOf(value));
            return noResult(attr);
          }
          if (meta.getUriPolicy() != null) {
            ExternalReference ref = new ExternalReference(uri, pos);
            String rewrittenUri = UriPolicyNanny.apply(
                meta.getUriPolicy(),
                ref, attr.attrInfo.getUriEffect(),
                attr.attrInfo.getLoaderType(),
                Collections.singletonMap(
                    UriPolicyHintKey.XML_ATTR.key,
                    attr.attrInfo.getKey().toString()));
            if (rewrittenUri == null) {
              mq.addMessage(
                  PluginMessageType.DISALLOWED_URI, pos,
                  MessagePart.Factory.valueOf(uri.toString()));
              return noResult(attr);
            }
            dynamicValue = StringLiteral.valueOf(
                ref.getReferencePosition(), rewrittenUri);
          } else {
            dynamicValue = (Expression) QuasiBuilder.substV(
                ""
                + "IMPORTS___./*@synthetic*/rewriteUriInAttribute___("
                + "    @value, @tagName, @attribName)",
                "value", new StringLiteral(
                    pos, uri.toString()),
                "tagName", new StringLiteral(
                    pos, attr.src.getOwnerElement().getTagName()),
                "attribName", new StringLiteral(
                    pos, attr.src.getName()));
          }
        }
        break;
      case URI_FRAGMENT:
        if (value.length() < 2 || !value.startsWith("#")) {
          mq.addMessage(
              IhtmlMessageType.BAD_ATTRIB, pos,
              attr.attrInfo.getKey().el, attr.attrInfo.getKey(),
              MessagePart.Factory.valueOf(value));
          return noResult(attr);
        }
        String id = value.substring(1);
        if (!checkValidId(id, pos)) { return noResult(attr); }
        JsConcatenator out = new JsConcatenator();
        out.append(FilePosition.startOf(pos), "#");
        rewriteIdentifiers(pos, id, out);
        dynamicValue = out.toExpression(false);
        break;
      default:
        throw new SomethingWidgyHappenedError(attr.attrInfo.getType().name());
    }
    return new SanitizedAttr(true, dynamicValue);
  }
View Full Code Here

      } else if (sig instanceof CssPropertySignature.ProgIdSignature) {
        applyProgIdSignature(
            (CssPropertySignature.ProgIdSignature) sig,
            candidate, propertyName, passed);
      } else {
        throw new SomethingWidgyHappenedError(sig.getClass().getName());
      }
    }
    for (Candidate candidate : passed) {
      if (null == best || best.exprIdx < candidate.exprIdx) {
        best = candidate;
View Full Code Here

      Candidate candidate, Name propertyName, List<Candidate> passed) {

    CssSchema.CssPropertyInfo info = cssSchema.getCssProperty(
        ssig.getPropertyName());
    if (null == info) {
      throw new SomethingWidgyHappenedError(
          "Unknown property in css property signature: " + propertyName);
    }
    check(info.sig);
    passed.addAll(applySignature(Collections.singletonList(candidate),
                                 info.name, info.sig));
View Full Code Here

        return false;
      }
      candidate.match(term, CssPropertyPartType.IDENT, propertyName);
      ++candidate.exprIdx;
    } else {
      throw new SomethingWidgyHappenedError(
          "unhandled symbol " + sig.symbolName + "\n" + dump(atom));
    }

    if (null != constraints
        // Violations of these constraints are not security problems though,
View Full Code Here

                }
                replacement.getAttributes().putAll(content.getAttributes());
                term.replaceChild(replacement, content);
              } catch (URISyntaxException ex) {
                // Should've been checked in removeUnsafeConstructs.
                throw new SomethingWidgyHappenedError(ex);
              }
            }
            return true;
          }
        });
View Full Code Here

  private Job getConsolidatedOutput(Criterion<Job> filter) {
    Job match = null;
    for (JobEnvelope env : this.jobs.getJobs()) {
      if (filter.accept(env.job)) {
        if (match != null) {
          throw new SomethingWidgyHappenedError(
              "Not consolidated.  Check your pipeline.");
        }
        match = env.job;
      }
    }
View Full Code Here

TOP

Related Classes of com.google.caja.SomethingWidgyHappenedError

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.