public String parse(XMLElement source, String value) throws UnableToCompleteException { String[] values = value.split(","); if (values.length != 2) { logger.die(source, "Unable to parse \"%s\" as a pair of integers", value); } String left = intParser.parse(source, values[0].trim()); String right = intParser.parse(source, values[1].trim()); return String.format("%s, %s", left, right); } }
public static String wrapUnsafeStringAndWarn(MortalLogger logger, XMLElement source, String expression) { logger.warn(source, "Escaping unsafe runtime String expression " + "used for URI with UriUtils.fromString(). Use SafeUri instead"); return "UriUtils.fromString(" + expression + ")"; }
private List<URL> getExternalCss() throws UnableToCompleteException { /* * TODO(rjrjr,bobv) refactor ResourceGeneratorUtil.findResources so we can * find them the same way ClientBundle does. For now, just look relative to * this package */ String path = packageName.replace(".", "/"); List<URL> urls = new ArrayList<URL>(); for (String s : sources) { String resourcePath = path + '/' + s; // Try to find the resource relative to the package. URL found = ResourceLocatorImpl.tryFindResourceUrl(logger.getTreeLogger(), resourceOracle, resourcePath); /* * If we didn't find the resource relative to the package, assume it * is absolute. */ if (found == null) { found = ResourceLocatorImpl.tryFindResourceUrl(logger.getTreeLogger(), resourceOracle, s); } if (found == null) { logger.die("Unable to find resource: " + resourcePath); } urls.add(found); } return urls; }
/** * Post an error. Sets the {@link #hasErrors} flag */ public void error(String message, Object... params) { hasErrors = true; logger.getTreeLogger().log(TreeLogger.ERROR, String.format(message, params)); }
throws UnableToCompleteException { MortalLogger logger = new MortalLogger(treeLogger); String templatePath = deduceTemplateFile(logger, interfaceType); MessagesWriter messages = new MessagesWriter(oracle, BINDER_URI, logger,
/** * Post a warning message related to a specific XMLElement. */ public void warn(XMLElement context, String message, Object... params) { logLocation(TreeLogger.WARN, context, String.format(message, params)); } }
public void logLocation(TreeLogger.Type type, XMLElement context, String message) { message += locationOf(context); logger.log(type, message); }
private List<URL> getExternalCss() throws UnableToCompleteException { /* * TODO(rjrjr,bobv) refactor ResourceGeneratorUtil.findResources so we can * find them the same way ClientBundle does. For now, just look relative to * this package */ String path = packageName.replace(".", "/"); List<URL> urls = new ArrayList<URL>(); for (String s : sources) { String resourcePath = path + '/' + s; // Try to find the resource relative to the package. URL found = ResourceLocatorImpl.tryFindResourceUrl(logger.getTreeLogger(), resourceOracle, resourcePath); /* * If we didn't find the resource relative to the package, assume it * is absolute. */ if (found == null) { found = ResourceLocatorImpl.tryFindResourceUrl(logger.getTreeLogger(), resourceOracle, s); } if (found == null) { logger.die("Unable to find resource: " + resourcePath); } urls.add(found); } return urls; }
/** * Post an error. Sets the {@link #hasErrors} flag */ public void error(String message, Object... params) { hasErrors = true; logger.getTreeLogger().log(TreeLogger.ERROR, String.format(message, params)); }
throws UnableToCompleteException { MortalLogger logger = new MortalLogger(treeLogger); String templatePath = deduceTemplateFile(logger, interfaceType); MessagesWriter messages = new MessagesWriter(oracle, BINDER_URI, logger,
/** * Post a warning message related to a specific XMLElement. */ public void warn(XMLElement context, String message, Object... params) { logLocation(TreeLogger.WARN, context, String.format(message, params)); } }
public void logLocation(TreeLogger.Type type, XMLElement context, String message) { message += locationOf(context); logger.log(type, message); }
public String parse(XMLElement source, String lengthStr) throws UnableToCompleteException { Matcher matcher = pattern.matcher(lengthStr); if (!matcher.matches()) { logger.die(source, "Unable to parse %s as length", lengthStr); } String valueStr = matcher.group(1); String value = doubleParser.parse(source, valueStr); String unit = null; String unitStr = matcher.group(2); if (unitStr.length() > 0) { if (!unitStr.startsWith("{")) { // For non-refs, convert % => PCT, px => PX, etc. if ("%".equals(unitStr)) { unitStr = "PCT"; } unitStr = unitStr.toUpperCase(Locale.ROOT); } // Now let the default enum parser handle it. unit = enumParser.parse(source, unitStr); } else { // Use PX by default. unit = UNIT + ".PX"; } return value + ", " + unit; } }
/** * Post a warning message. */ public void warn(XMLElement context, String message, Object... params) { logger.warn(context, message, params); }
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 (SAXParseException e) { logger.die( "Error parsing XML (line " + e.getLineNumber() + "): " + e.getMessage(), e); } return doc; }
/** * Returns the set of CSS classnames in the underlying css or gss files. * * @throws UnableToCompleteException if the user has called for a css/gss file we * can't find. */ public Set<String> getCssClassNames() throws UnableToCompleteException { List<URL> urls = getExternalCss(); if (cssClassNames == null) { final File bodyFile = getGeneratedFile(); if (bodyFile != null) { try { urls.add(bodyFile.toURI().toURL()); } catch (MalformedURLException e) { throw new RuntimeException(e); } } assert urls.size() > 0; if (gss) { return getCssClassNames(bodyFile.getName(), body, imports, logger.getTreeLogger()); } else { CssStylesheet sheet = GenerateCssAst.exec(logger.getTreeLogger(), urls.toArray(new URL[urls.size()])); cssClassNames = ExtractClassNamesVisitor.exec(sheet, imports.toArray(new JClassType[imports.size()])); } } return cssClassNames; }
private void generateOnce(JClassType interfaceType, String implName, PrintWriter binderPrintWriter, TreeLogger treeLogger, TypeOracle oracle, ResourceOracle resourceOracle, PropertyOracle propertyOracle, PrintWriterManager writerManager, DesignTimeUtils designTime) throws UnableToCompleteException { MortalLogger logger = new MortalLogger(treeLogger); String templatePath = deduceTemplateFile(logger, interfaceType); MessagesWriter messages = new MessagesWriter(oracle, BINDER_URI, logger, templatePath, interfaceType.getPackage().getName(), implName); boolean useLazyWidgetBuilders = useLazyWidgetBuilders(logger, propertyOracle); FieldManager fieldManager = new FieldManager(oracle, logger, useLazyWidgetBuilders); UiBinderWriter uiBinderWriter = new CustomUiBinderWriter(interfaceType, implName, templatePath, oracle, logger, fieldManager, messages, designTime, uiBinderCtx, useSafeHtmlTemplates(logger, propertyOracle), useLazyWidgetBuilders, BINDER_URI, propertyOracle); Document doc = getW3cDoc(logger, designTime, resourceOracle, templatePath); designTime.rememberPathForElements(doc); uiBinderWriter.parseDocument(doc, binderPrintWriter); if (messages.hasMessages()) { messages.write(writerManager.makePrintWriterFor(messages.getMessagesClassName())); } ImplicitClientBundle bundleClass = uiBinderWriter.getBundleClass(); new BundleWriter(bundleClass, writerManager, oracle, logger).write(); writerManager.commit(); }
public void error(XMLElement context, String message, Object... params) { hasErrors = true; logger.logLocation(TreeLogger.ERROR, context, String.format(message, params)); }
/** * If the value holds a single field reference "{like.this}", converts it to a * Java Expression. * <p> * In any other case (e.g. more than one field reference), an * UnableToCompleteException is thrown. */ public String parse(XMLElement source, String value) throws UnableToCompleteException { if ("".equals(value.trim())) { logger.die(source, "Cannot use empty value as type %s", FieldReference.renderTypesList(types)); } try { return converter.convert(source, value, new FieldReferenceDelegate(types)); } catch (IllegalFieldReferenceException e) { logger.die(source, "Cannot parse value: \"%s\" as type %s", value, FieldReference.renderTypesList(types)); return null; // Unreachable } } }
public static String wrapUnsafeStringAndWarn(MortalLogger logger, XMLElement source, String expression) { logger.warn(source, "Escaping unsafe runtime String expression " + "used for URI with UriUtils.fromString(). Use SafeUri instead"); return "UriUtils.fromString(" + expression + ")"; }