List of usage examples for com.google.gwt.dev.resource Resource getPath
public abstract String getPath();
From source file:com.google.gwt.dev.javac.testing.impl.MockResourceOracle.java
License:Apache License
public void add(Resource... resources) { Map<String, Resource> newMap = new HashMap<String, Resource>(exportedMap); for (Resource resource : resources) { String path = resource.getPath(); if (newMap.containsKey(path)) { throw new IllegalArgumentException( String.format("Encountered two resources with the same path [%s]", path)); }/* w w w. j a v a 2 s . co m*/ newMap.put(path, resource); } export(newMap); }
From source file:com.google.gwt.dev.javac.testing.impl.MockResourceOracle.java
License:Apache License
public void addOrReplace(Resource... resources) { Map<String, Resource> newMap = new HashMap<String, Resource>(exportedMap); for (Resource resource : resources) { newMap.put(resource.getPath(), resource); }/*from w w w. j a v a2s.c o m*/ export(newMap); }
From source file:com.google.gwt.dev.javac.testing.impl.MockResourceOracle.java
License:Apache License
public void replace(Resource... resources) { Map<String, Resource> newMap = new HashMap<String, Resource>(exportedMap); for (Resource resource : resources) { String path = resource.getPath(); if (!newMap.containsKey(path)) { throw new IllegalArgumentException( String.format("Attempted to replace non-existing resource with path [%s]", path)); }/*from w w w .j a v a2 s.c o m*/ newMap.put(path, resource); } export(newMap); }
From source file:com.seanchenxi.gwt.storage.rebind.TypeXmlFinder.java
License:Apache License
private StorageSerialization parseXmlResource(Resource resource) throws UnableToCompleteException { InputStream input = null;//from w ww . j a v a 2 s .co m try { JAXBContext jaxbContext = JAXBContext.newInstance(StorageSerialization.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Source source = createSAXSource(input = resource.openContents()); StorageSerialization storageSerialization = (StorageSerialization) unmarshaller.unmarshal(source); storageSerialization.setPath(resource.getPath()); return storageSerialization; } catch (Exception e) { logger.branch(TreeLogger.Type.WARN, "Error while parsing xml resource at " + resource.getPath(), e); throw new UnableToCompleteException(); } finally { try { if (input != null) input.close(); } catch (Exception e) { //To ignore } } }
From source file:fr.onevu.gwt.uibinder.rebind.GwtResourceEntityResolver.java
License:Apache License
@Override public InputSource resolveEntity(String publicId, String systemId) { String matchingPrefix = findMatchingPrefix(systemId); Resource resource = null; Map<String, Resource> map = resourceOracle.getResourceMap(); if (matchingPrefix != null) { resource = map.get(RESOURCES + systemId.substring(matchingPrefix.length())); }/*from ww w . ja v a2 s . c o m*/ if (resource == null) { resource = map.get(pathBase + systemId); } if (resource != null) { String content; try { InputStream resourceStream = resource.openContents(); content = Util.readStreamAsString(resourceStream); } catch (IOException ex) { logger.log(TreeLogger.ERROR, "Error reading resource: " + resource.getLocation()); throw new RuntimeException(ex); } InputSource inputSource = new InputSource(new StringReader(content)); inputSource.setPublicId(publicId); inputSource.setSystemId(resource.getPath()); return inputSource; } /* * Let Sax find it on the interweb. */ return null; }
From source file:fr.onevu.gwt.uibinder.rebind.UiBinderGenerator.java
License:Apache License
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); }// w w w .j av a 2s.co m 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; }
From source file:fr.putnami.pwt.core.widget.rebind.UiBinderLocalizedCreator.java
License:Open Source License
private Resource getTemplateResource(GeneratorContext context) { String packageResourcePath = this.targetType.getPackage().getName().replace('.', '/') + "/"; ResourceOracle resourceOracle = context.getResourcesOracle(); Map<String, Resource> reourceMap = new HashMap<>(); for (Resource resource : resourceOracle.getResources()) { reourceMap.put(resource.getPath(), resource); }//ww w. j a va 2s.co m String templatePath = packageResourcePath + this.templateName + "_" + this.locale + UiBinderLocalizedCreator.TEMPLATE_SUFFIX; Resource templateResource = reourceMap.get(templatePath); if (templateResource == null) { this.locale = null; templatePath = packageResourcePath + this.templateName + UiBinderLocalizedCreator.TEMPLATE_SUFFIX; templateResource = reourceMap.get(templatePath); } if (templateResource != null) { this.templateName = templatePath.replace(packageResourcePath, ""); } return templateResource; }