public static void write(Edimap edimap, Writer writer) throws IOException { try { EdimapWriter edimapWriter = new EdimapWriter(); edimapWriter.write(edimap); XmlUtil.serialize(edimapWriter.doc, true, writer); writer.flush(); } catch (ParserConfigurationException e) { IOException ioE = new IOException("Error constructing EDI Mapping Model"); ioE.initCause(e); throw ioE; } }
private void digestImport(Element importElement, URI baseURI) throws SAXException, URISyntaxException, SmooksConfigurationException { String file = DomUtils.getAttributeValue(importElement, "file"); URIResourceLocator resourceLocator; InputStream resourceStream; if (file == null) { throw new IllegalStateException( "Invalid resource import. 'file' attribute must be specified."); } resourceLocator = new URIResourceLocator(); resourceLocator.setBaseURI(baseURI); try { URI fileURI = resourceLocator.resolveURI(file); // Add the resource URI to the list. Will fail if it was already loaded pushConfig(file, fileURI); try { if (logger.isDebugEnabled()) { logger.debug( "Importing resource configuration '" + file + "' from inside '" + configStack.peek().configFile + "'."); } resourceStream = resourceLocator.getResource(file); try { List<Element> importParams = DomUtils.getElements(importElement, "param", null); if (!importParams.isEmpty()) { // Inject parameters into import config... String importConfig = StreamUtils.readStreamAsString(resourceStream); for (Element importParam : importParams) { String paramName = DomUtils.getAttributeValue(importParam, "name"); String paramValue = XmlUtil.serialize(importParam.getChildNodes()); importConfig = importConfig.replaceAll("@" + paramName + "@", paramValue); } digestConfigRecursively( new StringReader(importConfig), URIUtil.getParent(fileURI) .toString()); // the file's parent URI becomes the new base URI. } else { digestConfigRecursively( new InputStreamReader(resourceStream), URIUtil.getParent(fileURI) .toString()); // the file's parent URI becomes the new base URI. } } finally { resourceStream.close(); } } finally { popConfig(); } } catch (IOException e) { throw new SmooksConfigurationException( "Failed to load Smooks configuration resource <import> '" + file + "': " + e.getMessage(), e); } }