示例#1
0
  // BEGIN MODIFICATION
  private FieldManager getFieldManager(
      TypeOracle oracle,
      MortalLogger logger,
      PropertyOracle propertyOracle,
      boolean useLazyWidgetBuilder)
      throws UnableToCompleteException {

    // Find ginjector
    FieldManager fieldManager;
    try {
      String ginjectorClassName =
          propertyOracle.getConfigurationProperty("gin.ginjector").getValues().get(0);

      JClassType ginjectorClass = oracle.findType(ginjectorClassName);
      if (ginjectorClass == null
          || !ginjectorClass.isAssignableTo(oracle.findType(Ginjector.class.getCanonicalName()))) {
        logger.die(
            "The configuration property 'gin.ginjector' is '%s' "
                + " which doesn't identify a type inheriting from 'Ginjector'.",
            ginjectorClassName);
      }
      fieldManager = new GinFieldManager(oracle, logger, ginjectorClass, useLazyWidgetBuilder);

    } catch (BadPropertyValueException e) {
      logger.warn(
          "The configuration property 'gin.ginjector' was not found, it is required to use "
              + "gin injection for UiBinder fields. If you don't need this consider using "
              + "UiBinder.gwt.xml instead of GinUiBinder.gwt.xml in your module.");
      fieldManager = new FieldManager(oracle, logger, useLazyWidgetBuilder);
    }

    return fieldManager;
  }
示例#2
0
  private Document getW3cDoc(
      MortalLogger logger,
      DesignTimeUtils designTime,
      ResourceOracle resourceOracle,
      String templatePath)
      throws UnableToCompleteException {

    Resource resource = resourceOracle.getResourceMap().get(templatePath);
    if (null == resource) {
      logger.die("Unable to find resource: " + templatePath);
    }

    Document doc = null;
    try {
      String content = designTime.getTemplateContent(templatePath);
      if (content == null) {
        content = Util.readStreamAsString(resource.openContents());
      }
      doc =
          new W3cDomHelper(logger.getTreeLogger(), resourceOracle)
              .documentFor(content, resource.getPath());
    } catch (IOException iex) {
      logger.die("Error opening resource:" + resource.getLocation(), iex);
    } catch (SAXParseException e) {
      logger.die("Error parsing XML (line " + e.getLineNumber() + "): " + e.getMessage(), e);
    }
    return doc;
  }
示例#3
0
  /**
   * Given a UiBinder interface, return the path to its ui.xml file, suitable for any classloader to
   * find it as a resource.
   */
  private static String deduceTemplateFile(MortalLogger logger, JClassType interfaceType)
      throws UnableToCompleteException {
    String templateName = null;
    UiTemplate annotation = interfaceType.getAnnotation(UiTemplate.class);
    if (annotation == null) {
      // if the interface is defined as a nested class, use the name of the
      // enclosing type
      if (interfaceType.getEnclosingType() != null) {
        interfaceType = interfaceType.getEnclosingType();
      }
      return slashify(interfaceType.getQualifiedBinaryName()) + TEMPLATE_SUFFIX;
    } else {
      templateName = annotation.value();
      if (!templateName.endsWith(TEMPLATE_SUFFIX)) {
        logger.die("Template file name must end with " + TEMPLATE_SUFFIX);
      }

      /*
       * If the template file name (minus suffix) has no dots, make it relative
       * to the binder's package, otherwise slashify the dots
       */
      String unsuffixed = templateName.substring(0, templateName.lastIndexOf(TEMPLATE_SUFFIX));
      if (!unsuffixed.contains(".")) {
        templateName = slashify(interfaceType.getPackage().getName()) + "/" + templateName;
      } else {
        templateName = slashify(unsuffixed) + TEMPLATE_SUFFIX;
      }
    }
    return templateName;
  }
示例#4
0
 private Boolean useLazyWidgetBuilders(MortalLogger logger, PropertyOracle propertyOracle) {
   Boolean rtn =
       extractConfigProperty(logger, propertyOracle, LAZY_WIDGET_BUILDERS_PROPERTY, true);
   if (!gaveLazyBuildersWarning && !rtn) {
     logger.warn(
         "Configuration property %s is false. Deprecated code generation is in play. "
             + "This property will soon become a no-op.",
         LAZY_WIDGET_BUILDERS_PROPERTY);
     gaveLazyBuildersWarning = true;
   }
   return rtn;
 }
示例#5
0
  private Boolean useSafeHtmlTemplates(MortalLogger logger, PropertyOracle propertyOracle) {
    Boolean rtn = extractConfigProperty(logger, propertyOracle, XSS_SAFE_CONFIG_PROPERTY, true);

    if (!gaveSafeHtmlWarning && !rtn) {
      logger.warn(
          "Configuration property %s is false! UiBinder SafeHtml integration is off, "
              + "leaving your users more vulnerable to cross-site scripting attacks. This property "
              + "will soon become a no-op, and SafeHtml integration will always be on.",
          XSS_SAFE_CONFIG_PROPERTY);
      gaveSafeHtmlWarning = true;
    }
    return rtn;
  }
示例#6
0
  private Boolean extractConfigProperty(
      MortalLogger logger,
      PropertyOracle propertyOracle,
      String configProperty,
      boolean defaultValue) {
    List<String> values;
    try {
      values = propertyOracle.getConfigurationProperty(configProperty).getValues();
    } catch (BadPropertyValueException e) {
      logger.warn("No value found for configuration property %s.", configProperty);
      return defaultValue;
    }

    String value = values.get(0);
    if (!value.equals(Boolean.FALSE.toString()) && !value.equals(Boolean.TRUE.toString())) {
      logger.warn(
          "Unparseable value \"%s\" found for configuration property %s", value, configProperty);
      return defaultValue;
    }

    return Boolean.valueOf(value);
  }