// Instantiate Smooks with the config... Smooks smooks = new Smooks("smooks-config.xml"); try { // Filter the input message to the outputWriter... smooks.filterSource(new StreamSource(messageIn), new StreamResult(messageOut)); } finally { smooks.close(); }
/** * Filter the content in the supplied {@link Source} instance, outputing data * to the supplied {@link Result} instances. * * @param source The filter Source. * @param results The filter Results. * @throws SmooksException Failed to filter. */ public void filterSource(Source source, Result... results) throws SmooksException { filterSource(createExecutionContext(), source, results); }
/** * Add a set of resource configurations to this Smooks instance. * <p/> * Calls {@link #addConfigurations(String, java.io.InputStream)} with a baseURI of "./", * which is the default base URI on all {@link org.milyn.resource.URIResourceLocator} * instances. * * @param resourceConfigStream The resource configuration stream. * @throws IOException Error reading resource stream. * @throws SAXException Error parsing the resource stream. */ public void addConfigurations(InputStream resourceConfigStream) throws SAXException, IOException { addConfigurations("./", resourceConfigStream); }
public FixedLengthListBinder(String fields, Class recordType) { AssertArgument.isNotNullAndNotEmpty(fields, "fields"); AssertArgument.isNotNull(recordType, "recordType"); smooks = new Smooks(); smooks.setFilterSettings(FilterSettings.DEFAULT_SAX); smooks.setReaderConfig(new FixedLengthReaderConfigurator(fields) .setBinding(new FixedLengthBinding(beanId, recordType, FixedLengthBindingType.LIST))); }
smooks = new Smooks(StandaloneApplicationContext.createNewInstance(false)); setExtentionDigestOn(); try { SmooksResourceConfigurationStore configStore = smooks.getApplicationContext().getStore(); SmooksResourceConfigurationList extConfigList = new SmooksResourceConfigurationList(baseURI); smooks.setClassLoader(classLoader);
/** * Unmarshals the fromStream to an Object. * </p> * The Camel framework will call this method from {@link UnMarshalProcessor#process(Exchange)} * and it will take care of setting the returned Object on the Out Message's body. * * @param exchange The Camel {@link Exchange}. * @param fromStream The InputStream that will be unmarshalled into an Object instance. */ public Object unmarshal(final Exchange exchange, final InputStream fromStream) throws Exception { final ExecutionContext execContext = smooks.createExecutionContext(); final Exports exports = Exports.getExports(smooks.getApplicationContext()); final Result[] results = exports.createResults(); smooks.filterSource(execContext, new StreamSource(fromStream), results); return getResult(exports, results, exchange); }
private void configure() { Smooks smooks = descriptor.getSmooks(); smooks.addVisitor(new NamespaceReaper()); //descriptor.getSmooks().addVisitor(new UnknownElementDataReaper(), "*"); smooks.setFilterSettings(FilterSettings.newDOMSettings()); ParameterAccessor.setParameter(BeanInstancePopulator.NOTIFY_POPULATE, "true", smooks); // Create the execution context so as to force resolution of the config... smooks.createExecutionContext(); }
public List bind(Reader fixedLengthStream) { AssertArgument.isNotNull(fixedLengthStream, "fixedLengthStream"); JavaResult javaResult = new JavaResult(); smooks.filterSource(new StreamSource(fixedLengthStream), javaResult); return (List) javaResult.getBean(beanId); }
public Map<Class<?>, Map<String, BeanWriter>> getBeanWriters() { return BeanWriterFactory.getBeanWriters(smooks.getApplicationContext()); }
/** * Constructor. */ protected AbstractBinding() { smooks = new Smooks(); }
/** * Create a {@link ExecutionContext} instance for use on this Smooks instance. * <p/> * The created context is profile agnostic and should be used where profile based targeting is not in use. * <p/> * The context returned from this method is used in subsequent calls to * {@link #filterSource(org.milyn.container.ExecutionContext, javax.xml.transform.Source, javax.xml.transform.Result...)} * It allows access to the execution context instance * before and after calls on this method. This means the caller has an opportunity to set and get data * {@link org.milyn.container.BoundAttributeStore bound} to the execution context (before and after the calls), providing the * caller with a mechanism for interacting with the content {@link org.milyn.delivery.dom.SmooksDOMFilter filtering} phases. * * @return Execution context instance. */ public ExecutionContext createExecutionContext() { return createExecutionContext(Profile.DEFAULT_PROFILE); }
/** * Add a visitor instance to <code>this</code> Smooks instance. * <p/> * This Visitor will be targeted at the root (#document) fragment. * * @param visitor The visitor implementation. */ public SmooksResourceConfiguration addVisitor(Visitor visitor) { return addVisitor(visitor, SmooksResourceConfiguration.DOCUMENT_FRAGMENT_SELECTOR, null); }
public void start() throws Exception { if (smooks == null) { smooks = createSmooks(configUri); if (configUri != null) { smooks.addConfigurations(configUri); } } smooks.getApplicationContext().setAttribute(CamelContext.class, camelContext); addAppenders(smooks, visitorAppenders); addVisitors(smooks, selectorVisitorMap); log.info(this + " Started"); }
public void stop() throws Exception { if (smooks != null) { smooks.close(); } }
public CSVListBinder(String fields, Class recordType) { AssertArgument.isNotNullAndNotEmpty(fields, "fields"); AssertArgument.isNotNull(recordType, "recordType"); smooks = new Smooks(); smooks.setFilterSettings(FilterSettings.DEFAULT_SAX); smooks.setReaderConfig(new CSVRecordParserConfigurator(fields) .setBinding(new Binding(beanId, recordType, BindingType.LIST))); }
smooks = new Smooks(StandaloneApplicationContext.createNewInstance(false)); setExtentionDigestOn(); try { SmooksResourceConfigurationStore configStore = smooks.getApplicationContext().getStore(); SmooksResourceConfigurationList extConfigList = new SmooksResourceConfigurationList(baseURI); smooks.setClassLoader(classLoader);
private void configure() { Smooks smooks = descriptor.getSmooks(); smooks.addVisitor(new NamespaceReaper()); //descriptor.getSmooks().addVisitor(new UnknownElementDataReaper(), "*"); smooks.setFilterSettings(FilterSettings.newDOMSettings()); ParameterAccessor.setParameter(BeanInstancePopulator.NOTIFY_POPULATE, "true", smooks); // Create the execution context so as to force resolution of the config... smooks.createExecutionContext(); }
public List bind(Reader csvStream) { AssertArgument.isNotNull(csvStream, "csvStream"); JavaResult javaResult = new JavaResult(); smooks.filterSource(new StreamSource(csvStream), javaResult); return (List) javaResult.getBean(beanId); }
/** * Register a {@link org.milyn.cdr.SmooksResourceConfiguration} on the supplied {@link Smooks} instance. * * @param resourceConfig The Resource Configuration to be registered. * @param smooks The {@link org.milyn.Smooks} instance on which to perform the configuration operation. */ public static void registerResource(SmooksResourceConfiguration resourceConfig, Smooks smooks) { if (resourceConfig == null) { throw new IllegalArgumentException("null 'resourceConfig' arg in method call."); } smooks.getApplicationContext().getStore().registerResource(resourceConfig); }
/** * Constructor. */ protected AbstractBinding() { smooks = new Smooks(); }