/** * Public constructor. * @param resourceConfig Configuration. */ public void setConfiguration(SmooksResourceConfiguration resourceConfig) { delims = resourceConfig.getStringParameter("delims", ","); returnDelims = resourceConfig.getBoolParameter("returnDelims", false); trimTokens = resourceConfig.getBoolParameter("trimTokens", true); String paramType = resourceConfig.getStringParameter(Parameter.PARAM_TYPE_PREFIX, "string-list"); if(paramType.equals("string-list")) { returnType = Vector.class; } else if(paramType.equals("string-hashset")) { returnType = LinkedHashSet.class; } else { throw new ParameterDecodeException("Unsupported decoded return type [" + paramType + "]"); } }
/** * Public constructor. * @param resourceConfig Configuration. */ public void setConfiguration(SmooksResourceConfiguration resourceConfig) { delims = resourceConfig.getStringParameter("delims", ","); returnDelims = resourceConfig.getBoolParameter("returnDelims", false); trimTokens = resourceConfig.getBoolParameter("trimTokens", true); String paramType = resourceConfig.getStringParameter(Parameter.PARAM_TYPE_PREFIX, "string-list"); if(paramType.equals("string-list")) { returnType = Vector.class; } else if(paramType.equals("string-hashset")) { returnType = LinkedHashSet.class; } else { throw new ParameterDecodeException("Unsupported decoded return type [" + paramType + "]"); } }
/** * Public constructor. * @param resourceConfig Configuration. */ public void setConfiguration(SmooksResourceConfiguration resourceConfig) { delims = resourceConfig.getStringParameter("delims", ","); returnDelims = resourceConfig.getBoolParameter("returnDelims", false); trimTokens = resourceConfig.getBoolParameter("trimTokens", true); String paramType = resourceConfig.getStringParameter(Parameter.PARAM_TYPE_PREFIX, "string-list"); if(paramType.equals("string-list")) { returnType = Vector.class; } else if(paramType.equals("string-hashset")) { returnType = LinkedHashSet.class; } else { throw new ParameterDecodeException("Unsupported decoded return type [" + paramType + "]"); } }
/** * Public constructor. * @param resourceConfig Configuration. */ public void setConfiguration(SmooksResourceConfiguration resourceConfig) { delims = resourceConfig.getStringParameter("delims", ","); returnDelims = resourceConfig.getBoolParameter("returnDelims", false); trimTokens = resourceConfig.getBoolParameter("trimTokens", true); String paramType = resourceConfig.getStringParameter(Parameter.PARAM_TYPE_PREFIX, "string-list"); if(paramType.equals("string-list")) { returnType = Vector.class; } else if(paramType.equals("string-hashset")) { returnType = LinkedHashSet.class; } else { throw new ParameterDecodeException("Unsupported decoded return type [" + paramType + "]"); } }
@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); }
private Object createFromTemplate(String groovyScript, SmooksResourceConfiguration configuration) throws InstantiationException, IllegalAccessException { GroovyClassLoader groovyClassLoader = new GroovyClassLoader(getClass().getClassLoader()); Map<String, Object> templateVars = new HashMap<String, Object>(); String imports = configuration.getStringParameter("imports", ""); templateVars.put("imports", cleanImportsConfig(imports)); templateVars.put("visitorName", createClassName()); templateVars.put("elementName", getElementName(configuration)); templateVars.put("visitBefore", configuration.getBoolParameter("executeBefore", false)); templateVars.put("visitorScript", groovyScript); String templatedClass = classTemplate.apply(templateVars); if(groovyScript.contains("writeFragment")) { configuration.setParameter("writeFragment", "true"); } try { Class groovyClass = groovyClassLoader.parseClass(templatedClass); return groovyClass.newInstance(); } catch(CompilationFailedException e) { throw new SmooksConfigurationException("Failed to compile Groovy scripted Visitor class:\n==========================\n" + templatedClass + "\n==========================\n", e); } }
private Object createFromTemplate(String groovyScript, SmooksResourceConfiguration configuration) throws InstantiationException, IllegalAccessException { GroovyClassLoader groovyClassLoader = new GroovyClassLoader(getClass().getClassLoader()); Map<String, Object> templateVars = new HashMap<String, Object>(); String imports = configuration.getStringParameter("imports", ""); templateVars.put("imports", cleanImportsConfig(imports)); templateVars.put("visitorName", createClassName()); templateVars.put("elementName", getElementName(configuration)); templateVars.put("visitBefore", configuration.getBoolParameter("executeBefore", false)); templateVars.put("visitorScript", groovyScript); String templatedClass = classTemplate.apply(templateVars); if(groovyScript.contains("writeFragment")) { configuration.setParameter("writeFragment", "true"); } try { Class groovyClass = groovyClassLoader.parseClass(templatedClass); return groovyClass.newInstance(); } catch(CompilationFailedException e) { throw new SmooksConfigurationException("Failed to compile Groovy scripted Visitor class:\n==========================\n" + templatedClass + "\n==========================\n", e); } }
private Object createFromTemplate(String groovyScript, SmooksResourceConfiguration configuration) throws InstantiationException, IllegalAccessException { GroovyClassLoader groovyClassLoader = new GroovyClassLoader(getClass().getClassLoader()); Map templateVars = new HashMap(); String imports = configuration.getStringParameter("imports", ""); templateVars.put("imports", cleanImportsConfig(imports)); templateVars.put("visitorName", createClassName()); templateVars.put("elementName", getElementName(configuration)); templateVars.put("visitBefore", configuration.getBoolParameter("executeBefore", false)); templateVars.put("visitorScript", groovyScript); String templatedClass = classTemplate.apply(templateVars); if(groovyScript.indexOf("writeFragment") != -1) { configuration.setParameter("writeFragment", "true"); } try { Class groovyClass = groovyClassLoader.parseClass(templatedClass); return groovyClass.newInstance(); } catch(CompilationFailedException e) { throw new SmooksConfigurationException("Failed to compile Groovy scripted Visitor class:\n==========================\n" + templatedClass + "\n==========================\n", e); } }
public static DocumentTypeData getDocType(ExecutionContext executionContext) { List<SmooksResourceConfiguration> docTypeUDs = executionContext.getDeliveryConfig().getSmooksResourceConfigurations("doctype"); SmooksResourceConfiguration docTypeSmooksResourceConfiguration = null; if(docTypeUDs != null && docTypeUDs.size() > 0) { docTypeSmooksResourceConfiguration = docTypeUDs.get(0); } // Only use the cdrdef if the override flag is set. The override flag will // cause this DOCTYPE to override any DOCYTPE decl from the source doc. if(docTypeSmooksResourceConfiguration != null && docTypeSmooksResourceConfiguration.getBoolParameter("override", true)) { String name = docTypeSmooksResourceConfiguration.getStringParameter("name", "!!DOCTYPE name undefined - fix smooks-resource!!"); String publicId = docTypeSmooksResourceConfiguration.getStringParameter("publicId", "!!DOCTYPE publicId undefined - fix smooks-resource!!"); String systemId = docTypeSmooksResourceConfiguration.getStringParameter("systemId", "!!DOCTYPE systemId undefined - fix smooks-resource!!"); String xmlns = docTypeSmooksResourceConfiguration.getStringParameter("xmlns"); boolean omit = docTypeSmooksResourceConfiguration.getBoolParameter("omit", false); return new DocumentTypeData(name, publicId, systemId, xmlns, omit); } return (DocumentTypeData) executionContext.getAttribute(DOCTYPE_KEY); }
public static DocumentTypeData getDocType(ExecutionContext executionContext) { List<SmooksResourceConfiguration> docTypeUDs = executionContext.getDeliveryConfig().getSmooksResourceConfigurations("doctype"); SmooksResourceConfiguration docTypeSmooksResourceConfiguration = null; if(docTypeUDs != null && docTypeUDs.size() > 0) { docTypeSmooksResourceConfiguration = docTypeUDs.get(0); } // Only use the cdrdef if the override flag is set. The override flag will // cause this DOCTYPE to override any DOCYTPE decl from the source doc. if(docTypeSmooksResourceConfiguration != null && docTypeSmooksResourceConfiguration.getBoolParameter("override", true)) { String name = docTypeSmooksResourceConfiguration.getStringParameter("name", "!!DOCTYPE name undefined - fix smooks-resource!!"); String publicId = docTypeSmooksResourceConfiguration.getStringParameter("publicId", "!!DOCTYPE publicId undefined - fix smooks-resource!!"); String systemId = docTypeSmooksResourceConfiguration.getStringParameter("systemId", "!!DOCTYPE systemId undefined - fix smooks-resource!!"); String xmlns = docTypeSmooksResourceConfiguration.getStringParameter("xmlns"); boolean omit = docTypeSmooksResourceConfiguration.getBoolParameter("omit", false); return new DocumentTypeData(name, publicId, systemId, xmlns, omit); } return (DocumentTypeData) executionContext.getAttribute(DOCTYPE_KEY); }
public static DocumentTypeData getDocType(ExecutionContext executionContext) { List<SmooksResourceConfiguration> docTypeUDs = executionContext.getDeliveryConfig().getSmooksResourceConfigurations("doctype"); SmooksResourceConfiguration docTypeSmooksResourceConfiguration = null; if(docTypeUDs != null && docTypeUDs.size() > 0) { docTypeSmooksResourceConfiguration = docTypeUDs.get(0); } // Only use the cdrdef if the override flag is set. The override flag will // cause this DOCTYPE to override any DOCYTPE decl from the source doc. if(docTypeSmooksResourceConfiguration != null && docTypeSmooksResourceConfiguration.getBoolParameter("override", true)) { String name = docTypeSmooksResourceConfiguration.getStringParameter("name", "!!DOCTYPE name undefined - fix smooks-resource!!"); String publicId = docTypeSmooksResourceConfiguration.getStringParameter("publicId", "!!DOCTYPE publicId undefined - fix smooks-resource!!"); String systemId = docTypeSmooksResourceConfiguration.getStringParameter("systemId", "!!DOCTYPE systemId undefined - fix smooks-resource!!"); String xmlns = docTypeSmooksResourceConfiguration.getStringParameter("xmlns"); boolean omit = docTypeSmooksResourceConfiguration.getBoolParameter("omit", false); return new DocumentTypeData(name, publicId, systemId, xmlns, omit); } return (DocumentTypeData) executionContext.getAttribute(DOCTYPE_KEY); }
public static DocumentTypeData getDocType(ExecutionContext executionContext) { List<SmooksResourceConfiguration> docTypeUDs = executionContext.getDeliveryConfig().getSmooksResourceConfigurations("doctype"); SmooksResourceConfiguration docTypeSmooksResourceConfiguration = null; if(docTypeUDs != null && docTypeUDs.size() > 0) { docTypeSmooksResourceConfiguration = docTypeUDs.get(0); } // Only use the cdrdef if the override flag is set. The override flag will // cause this DOCTYPE to override any DOCYTPE decl from the source doc. if(docTypeSmooksResourceConfiguration != null && docTypeSmooksResourceConfiguration.getBoolParameter("override", true)) { String name = docTypeSmooksResourceConfiguration.getStringParameter("name", "!!DOCTYPE name undefined - fix smooks-resource!!"); String publicId = docTypeSmooksResourceConfiguration.getStringParameter("publicId", "!!DOCTYPE publicId undefined - fix smooks-resource!!"); String systemId = docTypeSmooksResourceConfiguration.getStringParameter("systemId", "!!DOCTYPE systemId undefined - fix smooks-resource!!"); String xmlns = docTypeSmooksResourceConfiguration.getStringParameter("xmlns"); boolean omit = docTypeSmooksResourceConfiguration.getBoolParameter("omit", false); return new DocumentTypeData(name, publicId, systemId, xmlns, omit); } return (DocumentTypeData) executionContext.getAttribute(DOCTYPE_KEY); }
private static <U> void processStreamResultWriterAnnotations(U instance, SmooksResourceConfiguration config) { if(!(instance instanceof SAXVisitor)) { return; } List<Field> streamResFields = ClassUtil.getAnnotatedFields(instance.getClass(), StreamResultWriter.class); boolean encodeSpecialCharacters = config.getBoolParameter(Filter.ENTITIES_REWRITE, true); for(Field streamResField : streamResFields) { // If already initialized, ignore... try { if(ClassUtil.getField(streamResField, instance) != null) { continue; } } catch (IllegalAccessException e) { throw new SmooksConfigurationException("Unable to get property field value for '" + getLongMemberName(streamResField) + "'.", e); } Class<?> type = streamResField.getType(); if(type == SAXToXMLWriter.class) { SAXToXMLWriter xmlWriter = new SAXToXMLWriter((SAXVisitor) instance, encodeSpecialCharacters); try { ClassUtil.setField(streamResField, instance, xmlWriter); } catch (IllegalAccessException e) { throw new SmooksConfigurationException("Unable to inject SAXToXMLWriter property field value for '" + getLongMemberName(streamResField) + "'.", e); } } } }
private static <U> void processStreamResultWriterAnnotations(U instance, SmooksResourceConfiguration config) { if(!(instance instanceof SAXVisitor)) { return; } List<Field> streamResFields = ClassUtil.getAnnotatedFields(instance.getClass(), StreamResultWriter.class); boolean encodeSpecialCharacters = config.getBoolParameter(Filter.ENTITIES_REWRITE, true); for(Field streamResField : streamResFields) { // If already initialized, ignore... try { if(ClassUtil.getField(streamResField, instance) != null) { continue; } } catch (IllegalAccessException e) { throw new SmooksConfigurationException("Unable to get property field value for '" + getLongMemberName(streamResField) + "'.", e); } Class<?> type = streamResField.getType(); if(type == SAXToXMLWriter.class) { SAXToXMLWriter xmlWriter = new SAXToXMLWriter((SAXVisitor) instance, encodeSpecialCharacters); try { ClassUtil.setField(streamResField, instance, xmlWriter); } catch (IllegalAccessException e) { throw new SmooksConfigurationException("Unable to inject SAXToXMLWriter property field value for '" + getLongMemberName(streamResField) + "'.", e); } } } }
private static <U> void processStreamResultWriterAnnotations(U instance, SmooksResourceConfiguration config) { if(!(instance instanceof SAXVisitor)) { return; } List<Field> streamResFields = ClassUtil.getAnnotatedFields(instance.getClass(), StreamResultWriter.class); boolean encodeSpecialCharacters = config.getBoolParameter(Filter.ENTITIES_REWRITE, true); for(Field streamResField : streamResFields) { // If already initialized, ignore... try { if(ClassUtil.getField(streamResField, instance) != null) { continue; } } catch (IllegalAccessException e) { throw new SmooksConfigurationException("Unable to get property field value for '" + getLongMemberName(streamResField) + "'.", e); } Class<?> type = streamResField.getType(); if(type == SAXToXMLWriter.class) { SAXToXMLWriter xmlWriter = new SAXToXMLWriter((SAXVisitor) instance, encodeSpecialCharacters); try { ClassUtil.setField(streamResField, instance, xmlWriter); } catch (IllegalAccessException e) { throw new SmooksConfigurationException("Unable to inject SAXToXMLWriter property field value for '" + getLongMemberName(streamResField) + "'.", e); } } } }
private static <U> void processStreamResultWriterAnnotations(U instance, SmooksResourceConfiguration config) { if(!(instance instanceof SAXVisitor)) { return; } List<Field> streamResFields = ClassUtil.getAnnotatedFields(instance.getClass(), StreamResultWriter.class); boolean encodeSpecialCharacters = config.getBoolParameter(Filter.ENTITIES_REWRITE, true); for(Field streamResField : streamResFields) { // If already initialized, ignore... try { if(ClassUtil.getField(streamResField, instance) != null) { continue; } } catch (IllegalAccessException e) { throw new SmooksConfigurationException("Unable to get property field value for '" + getLongMemberName(streamResField) + "'.", e); } Class<?> type = streamResField.getType(); if(type == SAXToXMLWriter.class) { SAXToXMLWriter xmlWriter = new SAXToXMLWriter((SAXVisitor) instance, encodeSpecialCharacters); try { ClassUtil.setField(streamResField, instance, xmlWriter); } catch (IllegalAccessException e) { throw new SmooksConfigurationException("Unable to inject SAXToXMLWriter property field value for '" + getLongMemberName(streamResField) + "'.", e); } } } }