private static String getContentType(TreeLogger logger, Resource resource) { String name = resource.getPath().toLowerCase(); int pos = name.lastIndexOf('.'); String extension = pos == -1 ? "" : name.substring(pos); String contentType = EXTENSION_MAP.get(extension); if (contentType == null) { logger.log( TreeLogger.WARN, "No Content Type mapping for files with '" + extension + "' extension. Please add a mapping to the " + AutoClientBundleGenerator.class.getCanonicalName() + " class."); contentType = "application/octet-stream"; } return contentType; }
private static String getContentType(TreeLogger logger, Resource resource) { String name = resource.getPath().toLowerCase(); int pos = name.lastIndexOf('.'); String extension = pos == -1 ? "" : name.substring(pos); String contentType = EXTENSION_MAP.get(extension); if (contentType == null) { logger.log( TreeLogger.WARN, "No Content Type mapping for files with '" + extension + "' extension. Please add a mapping to the " + AutoClientBundleGenerator.class.getCanonicalName() + " class."); contentType = "application/octet-stream"; } return contentType; }
private static String getContentType(TreeLogger logger, Resource resource) { String name = resource.getPath().toLowerCase(); int pos = name.lastIndexOf('.'); String extension = pos == -1 ? "" : name.substring(pos); String contentType = EXTENSION_MAP.get(extension); if (contentType == null) { logger.log( TreeLogger.WARN, "No Content Type mapping for files with '" + extension + "' extension. Please add a mapping to the " + AutoClientBundleGenerator.class.getCanonicalName() + " class."); contentType = "application/octet-stream"; } return contentType; }
/** * Filter file set, preferring *.mp3 files where alternatives exist. */ private HashSet<Resource> preferMp3(HashSet<Resource> files) { HashMap<String, Resource> map = new HashMap<String, Resource>(); for (Resource file : files) { String path = stripExtension(file.getPath()); if (file.getPath().endsWith(".mp3") || !map.containsKey(path)) { map.put(path, file); } } return new HashSet<Resource>(map.values()); }
/** * Filter file set, preferring *.mp3 files where alternatives exist. */ private HashSet<Resource> preferMp3(HashSet<Resource> files) { HashMap<String, Resource> map = new HashMap<String, Resource>(); for (Resource file : files) { String path = stripExtension(file.getPath()); if (file.getPath().endsWith(".mp3") || !map.containsKey(path)) { map.put(path, file); } } return new HashSet<Resource>(map.values()); }
/** * Filter file set, preferring *.mp3 files where alternatives exist. */ private HashSet<Resource> preferMp3(HashSet<Resource> files) { HashMap<String, Resource> map = new HashMap<String, Resource>(); for (Resource file : files) { String path = stripExtension(file.getPath()); if (file.getPath().endsWith(".mp3") || !map.containsKey(path)) { map.put(path, file); } } return new HashSet<Resource>(map.values()); }
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); } 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; }
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); } 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; }
private StorageSerialization parseXmlResource(Resource resource) throws UnableToCompleteException { InputStream input = null; 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 } } }
@Override public InputSource resolveEntity(String publicId, String systemId) { String matchingPrefix = findMatchingPrefix(systemId); Resource resource = null; if (matchingPrefix != null) { resource = resourceOracle.getResource(RESOURCES + systemId.substring(matchingPrefix.length())); } if (resource == null) { resource = resourceOracle.getResource(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; }
@Override public InputSource resolveEntity(String publicId, String systemId) { String matchingPrefix = findMatchingPrefix(systemId); Resource resource = null; if (matchingPrefix != null) { resource = resourceOracle.getResource(RESOURCES + systemId.substring(matchingPrefix.length())); } if (resource == null) { resource = resourceOracle.getResource(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; }
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; }
private Document getW3cDoc(MortalLogger logger, DesignTimeUtils designTime, ResourceOracle resourceOracle, String templatePath, Resource resource) throws UnableToCompleteException { 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; }
private Document getW3cDoc(MortalLogger logger, DesignTimeUtils designTime, ResourceOracle resourceOracle, String templatePath, Resource resource) throws UnableToCompleteException { 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; }