@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 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 } } }
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; }
InputStream resourceStream = null; try { resourceStream = resource.openContents(); } catch (IOException ex) { logger.log(TreeLogger.ERROR, "Error opening resource: " + resource.getLocation());
InputStream resourceStream = null; try { resourceStream = resource.openContents(); } catch (IOException ex) { logger.log(TreeLogger.ERROR, "Error opening resource: " + resource.getLocation());
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; }