private Source getNamespaceSource(URI namespace) throws SAXException { String resourcePath = "/META-INF" + namespace.getPath(); InputStream xsdStream = ClassUtil.getResourceAsStream(resourcePath, getClass()); if(xsdStream == null) { throw new SAXException("Failed to locate XSD resource '" + resourcePath + "' on classpath. Namespace: '" + namespace + "'."); } return new StreamSource(xsdStream); }
public InputStream getResource(String uri) throws IllegalArgumentException { if (uri == null) { throw new IllegalArgumentException("null 'uri' arg in method call."); } else if (uri.charAt(0) != '/') { throw new IllegalArgumentException( "classpath 'uri' must be a valid classpath with a leading '/' char on the path i.e. specified relative to the root of the classpath."); } return ClassUtil.getResourceAsStream(uri, getClass()); }
public InputStream getResource(String uri) throws IllegalArgumentException { if (uri == null) { throw new IllegalArgumentException("null 'uri' arg in method call."); } else if (uri.charAt(0) != '/') { throw new IllegalArgumentException( "classpath 'uri' must be a valid classpath with a leading '/' char on the path i.e. specified relative to the root of the classpath."); } return ClassUtil.getResourceAsStream(uri, getClass()); }
public InputStream getResource(String uri) throws IllegalArgumentException { if (uri == null) { throw new IllegalArgumentException("null 'uri' arg in method call."); } else if (uri.charAt(0) != '/') { throw new IllegalArgumentException( "classpath 'uri' must be a valid classpath with a leading '/' char on the path i.e. specified relative to the root of the classpath."); } return ClassUtil.getResourceAsStream(uri, getClass()); }
private Source getNamespaceSource(URI namespace) throws SAXException { String resourcePath = "/META-INF" + namespace.getPath(); InputStream xsdStream = ClassUtil.getResourceAsStream(resourcePath, getClass()); if(xsdStream == null) { throw new SAXException("Failed to locate XSD resource '" + resourcePath + "' on classpath. Namespace: '" + namespace + "'."); } return new StreamSource(xsdStream); }
private Source getNamespaceSource(URI namespace) throws SAXException { String resourcePath = "/META-INF" + namespace.getPath(); InputStream xsdStream = ClassUtil.getResourceAsStream(resourcePath, getClass()); if(xsdStream == null) { throw new SAXException("Failed to locate XSD resource '" + resourcePath + "' on classpath. Namespace: '" + namespace + "'."); } return new StreamSource(xsdStream); }
/** * Get the specified resource as a stream. * * @param resourceName * The name of the class to load. * @param caller * The class of the caller. * @return The input stream for the resource or null if not found. */ public static InputStream getResourceAsStream(final String resourceName, final Class caller) { final String resource; if (!resourceName.startsWith("/")) { final Package callerPackage = caller.getPackage(); if (callerPackage != null) { resource = callerPackage.getName().replace('.', '/') + '/' + resourceName; } else { resource = resourceName; } return getResourceAsStream(resource, caller.getClassLoader()); } else { return getResourceAsStream(resourceName, caller.getClassLoader()); } }
protected InputSource resolveSchemaLocation(String systemId) throws SAXException { String namespaceId = Descriptor.getNamespaceId(systemId, descriptors); if(namespaceId != null) { String schemaLocation = Descriptor.getSchemaLocation(namespaceId, descriptors); if(schemaLocation == null) { throw new SAXException("Failed to resolve schemaLocation for namespace '" + systemId + "'."); } InputStream stream = ClassUtil.getResourceAsStream(schemaLocation, classLoader); if(stream == null) { throw new SAXException("schemaLocation '" + schemaLocation + "' for namespace '" + systemId + "' does not resolve to a Classpath resource."); } return new InputSource(stream); } else { return null; } }
protected InputSource resolveSchemaLocation(String systemId) throws SAXException { String namespaceId = Descriptor.getNamespaceId(systemId, descriptors); if(namespaceId != null) { String schemaLocation = Descriptor.getSchemaLocation(namespaceId, descriptors); if(schemaLocation == null) { throw new SAXException("Failed to resolve schemaLocation for namespace '" + systemId + "'."); } InputStream stream = ClassUtil.getResourceAsStream(schemaLocation, classLoader); if(stream == null) { throw new SAXException("schemaLocation '" + schemaLocation + "' for namespace '" + systemId + "' does not resolve to a Classpath resource."); } return new InputSource(stream); } else { return null; } }
protected InputSource resolveBindingConfigLocation(String systemId) throws SAXException { String namespaceId = Descriptor.getNamespaceId(systemId, descriptors); if(namespaceId != null) { String bindingConfigLocation = Descriptor.getBindingConfigLocation(namespaceId, descriptors); if(bindingConfigLocation == null) { throw new SAXException("Failed to resolve bindingConfigLocation for namespace '" + systemId + "'."); } InputStream stream = ClassUtil.getResourceAsStream(bindingConfigLocation, classLoader); if(stream == null) { throw new SAXException("bindingConfigLocation '" + bindingConfigLocation + "' for namespace '" + systemId + "' does not resolve to a Classpath resource."); } return new InputSource(stream); } else { return null; } } }
protected InputSource resolveBindingConfigLocation(String systemId) throws SAXException { String namespaceId = Descriptor.getNamespaceId(systemId, descriptors); if(namespaceId != null) { String bindingConfigLocation = Descriptor.getBindingConfigLocation(namespaceId, descriptors); if(bindingConfigLocation == null) { throw new SAXException("Failed to resolve bindingConfigLocation for namespace '" + systemId + "'."); } InputStream stream = ClassUtil.getResourceAsStream(bindingConfigLocation, classLoader); if(stream == null) { throw new SAXException("bindingConfigLocation '" + bindingConfigLocation + "' for namespace '" + systemId + "' does not resolve to a Classpath resource."); } return new InputSource(stream); } else { return null; } } }
protected InputSource resolveSchemaLocation(String systemId) throws SAXException { String namespaceId = Descriptor.getNamespaceId(systemId, descriptors); if(namespaceId != null) { String schemaLocation = Descriptor.getSchemaLocation(namespaceId, descriptors); if(schemaLocation == null) { throw new SAXException("Failed to resolve schemaLocation for namespace '" + systemId + "'."); } InputStream stream = ClassUtil.getResourceAsStream(schemaLocation, classLoader); if(stream == null) { throw new SAXException("schemaLocation '" + schemaLocation + "' for namespace '" + systemId + "' does not resolve to a Classpath resource."); } return new InputSource(stream); } else { return null; } }
protected InputSource resolveBindingConfigLocation(String systemId) throws SAXException { String namespaceId = Descriptor.getNamespaceId(systemId, descriptors); if(namespaceId != null) { String bindingConfigLocation = Descriptor.getBindingConfigLocation(namespaceId, descriptors); if(bindingConfigLocation == null) { throw new SAXException("Failed to resolve bindingConfigLocation for namespace '" + systemId + "'."); } InputStream stream = ClassUtil.getResourceAsStream(bindingConfigLocation, classLoader); if(stream == null) { throw new SAXException("bindingConfigLocation '" + bindingConfigLocation + "' for namespace '" + systemId + "' does not resolve to a Classpath resource."); } return new InputSource(stream); } else { return null; } } }
@Override protected void loadTemplate(SmooksResourceConfiguration resourceConfig) throws IOException, TransformerConfigurationException { TransformerFactory transformerFactory = TransformerFactory.newInstance(); StreamSource xslStreamSource; boolean isInlineXSL = resourceConfig.isInline(); byte[] xslBytes = resourceConfig.getBytes(); xslString = new String(xslBytes, getEncoding().name()); // If it's not a full XSL template, we need to make it so by wrapping it... isTemplatelet = isTemplatelet(isInlineXSL, new String(xslBytes)); if (isTemplatelet) { String templateletWrapper = new String(StreamUtils.readStream(ClassUtil.getResourceAsStream("doc-files/templatelet.xsl", getClass()))); String templatelet = new String(xslBytes); templateletWrapper = StringUtils.replace(templateletWrapper, "@@@templatelet@@@", templatelet); xslBytes = templateletWrapper.getBytes(); xslString = new String(xslBytes, getEncoding().name()); } boolean failOnWarning = resourceConfig.getBoolParameter("failOnWarning", true); xslStreamSource = new StreamSource(new StringReader(xslString)); transformerFactory.setErrorListener(new XslErrorListener(failOnWarning)); xslTemplate = transformerFactory.newTemplates(xslStreamSource); }
@Override protected void loadTemplate(SmooksResourceConfiguration resourceConfig) throws IOException, TransformerConfigurationException { TransformerFactory transformerFactory = TransformerFactory.newInstance(); StreamSource xslStreamSource; boolean isInlineXSL = resourceConfig.isInline(); byte[] xslBytes = resourceConfig.getBytes(); xslString = new String(xslBytes, getEncoding().name()); // If it's not a full XSL template, we need to make it so by wrapping it... isTemplatelet = isTemplatelet(isInlineXSL, new String(xslBytes)); if (isTemplatelet) { String templateletWrapper = new String(StreamUtils.readStream(ClassUtil.getResourceAsStream("doc-files/templatelet.xsl", getClass()))); String templatelet = new String(xslBytes); templateletWrapper = StringUtils.replace(templateletWrapper, "@@@templatelet@@@", templatelet); xslBytes = templateletWrapper.getBytes(); xslString = new String(xslBytes, getEncoding().name()); } boolean failOnWarning = resourceConfig.getBoolParameter("failOnWarning", true); xslStreamSource = new StreamSource(new StringReader(xslString)); transformerFactory.setErrorListener(new XslErrorListener(failOnWarning)); xslTemplate = transformerFactory.newTemplates(xslStreamSource); }
/** * Register the pre-installed CDU Creator classes. * @param resourceFile Installed (internal) resource config file. */ private void registerInstalledResources(String resourceFile) { InputStream resource = ClassUtil.getResourceAsStream(resourceFile, getClass()); if(resource == null) { throw new IllegalStateException("Failed to load " + resourceFile + ". Expected to be in the same package as " + getClass().getName()); } try { SmooksResourceConfigurationList resourceList = registerResources(resourceFile, resource); for(int i = 0; i < resourceList.size(); i++) { resourceList.get(i).setDefaultResource(true); } resourceList.setSystemConfigList(true); } catch (Exception e) { throw new IllegalStateException("Error processing resource file '" + resourceFile + "'.", e); } }
/** * Register the pre-installed CDU Creator classes. * @param resourceFile Installed (internal) resource config file. */ private void registerInstalledResources(String resourceFile) { InputStream resource = ClassUtil.getResourceAsStream(resourceFile, getClass()); if(resource == null) { throw new IllegalStateException("Failed to load " + resourceFile + ". Expected to be in the same package as " + getClass().getName()); } try { SmooksResourceConfigurationList resourceList = registerResources(resourceFile, resource); for(int i = 0; i < resourceList.size(); i++) { resourceList.get(i).setDefaultResource(true); } resourceList.setSystemConfigList(true); } catch (Exception e) { throw new IllegalStateException("Error processing resource file '" + resourceFile + "'.", e); } }
/** * Register the pre-installed CDU Creator classes. * @param resourceFile Installed (internal) resource config file. */ private void registerInstalledResources(String resourceFile) { InputStream resource = ClassUtil.getResourceAsStream(resourceFile, getClass()); if(resource == null) { throw new IllegalStateException("Failed to load " + resourceFile + ". Expected to be in the same package as " + getClass().getName()); } try { SmooksResourceConfigurationList resourceList = registerResources(resourceFile, resource); for(int i = 0; i < resourceList.size(); i++) { resourceList.get(i).setDefaultResource(true); } resourceList.setSystemConfigList(true); } catch (Exception e) { throw new IllegalStateException("Error processing resource file '" + resourceFile + "'.", e); } }
/** * Register the pre-installed CDU Creator classes. * @param resourceFile Installed (internal) resource config file. */ private void registerInstalledResources(String resourceFile) { InputStream resource = ClassUtil.getResourceAsStream(resourceFile, getClass()); if(resource == null) { throw new IllegalStateException("Failed to load " + resourceFile + ". Expected to be in the same package as " + getClass().getName()); } try { SmooksResourceConfigurationList resourceList = registerResources(resourceFile, resource); for(int i = 0; i < resourceList.size(); i++) { resourceList.get(i).setDefaultResource(true); } resourceList.setSystemConfigList(true); } catch (Exception e) { throw new IllegalStateException("Error processing resource file '" + resourceFile + "'.", e); } }
private void assertExtendedConfigOK(String configNamespace, String resourcePath) { InputStream resourceStream = ClassUtil.getResourceAsStream(resourcePath, classLoader); if (resourceStream == null) { throw new SmooksConfigurationException("Unable to locate Smooks digest configuration '" + resourcePath + "' for extended resource configuration namespace '" + configNamespace + "'. This resource must be available on the classpath."); } Document configDoc; try { configDoc = XmlUtil.parseStream(resourceStream); } catch (Exception e) { throw new SmooksConfigurationException("Unable to parse namespace URI '" + configNamespace + "'.", e); } XsdDOMValidator validator; try { validator = new XsdDOMValidator(configDoc); } catch (SAXException e) { throw new SmooksConfigurationException("Unable to create XsdDOMValidator instance for extended resource config '" + resourcePath + "'.", e); } String defaultNS = validator.getDefaultNamespace().toString(); if (!XSD_V10.equals(defaultNS) && !XSD_V11.equals(defaultNS)) { throw new SmooksConfigurationException("Extended resource configuration '" + resourcePath + "' default namespace must be a valid Smooks configuration namespace."); } if(validator.getNamespaces().size() > 1) { throw new SmooksConfigurationException("Extended resource configuration '" + resourcePath + "' defines configurations from multiple namespaces. This is not permitted. Only use configurations from the base Smooks config namespaces e.g. '" + XSD_V11 + "'."); } }