use of javax.xml.transform.TransformerConfigurationException in project adempiere by adempiere.
the class PackInHandler method init.
private void init() throws SAXException {
if (packIn == null)
packIn = new PackIn();
packageDirectory = PackIn.m_Package_Dir;
m_UpdateMode = PackIn.m_UpdateMode;
m_DatabaseType = PackIn.m_Database;
SimpleDateFormat formatter_file = new SimpleDateFormat("yyMMddHHmmssZ");
SimpleDateFormat formatter_log = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
Date today = new Date();
String fileDate = formatter_file.format(today);
logDate = formatter_log.format(today);
String file_document = packageDirectory + File.separator + "doc" + File.separator + "Importlog_" + fileDate + ".xml";
log.info("file_document=" + file_document);
try {
fw_document = new FileOutputStream(file_document, false);
} catch (FileNotFoundException e1) {
log.warning("Failed to create log file:" + e1);
}
streamResult_document = new StreamResult(fw_document);
tf_document = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
try {
logDocument = tf_document.newTransformerHandler();
} catch (TransformerConfigurationException e2) {
log.info("startElement:" + e2);
}
serializer_document = logDocument.getTransformer();
serializer_document.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
serializer_document.setOutputProperty(OutputKeys.INDENT, "yes");
logDocument.setResult(streamResult_document);
logDocument.startDocument();
logDocument.processingInstruction("xml-stylesheet", "type=\"text/css\" href=\"adempiereDocument.css\"");
Properties tmp = new Properties();
if (m_ctx != null)
tmp.putAll(m_ctx);
else
tmp.putAll(Env.getCtx());
m_ctx = tmp;
if (m_trxName == null)
m_trxName = Trx.createTrxName("PackIn");
m_AD_Client_ID = Env.getContextAsInt(m_ctx, "AD_Client_ID");
Start_Doc = 1;
}
use of javax.xml.transform.TransformerConfigurationException in project GDSC-SMLM by aherbert.
the class BatchPeakFit method setParameters.
/**
* Modify the XML document using the specified values for the given parameter. For each value
* call the method recursively for the next parameter. If there are no more parameters
* then add the XML document to the xmlSettings.
*
* @param parameters
* The list of parameters
* @param i
* Parameter to process
* @param doc
* The XML document containing all the current parameters
* @param xmlSettings
* A list of XML parameter settings
*/
private void setParameters(ArrayList<ParameterSettings> parameters, int i, Document doc, ArrayList<String> xmlSettings) {
if (i < parameters.size()) {
ParameterSettings param = parameters.get(i);
NodeList nodes = doc.getElementsByTagName(param.name);
if (nodes.getLength() == 1) {
// For each value, set the parameter and move to the next
String[] values = param.value.split(",");
for (String value : values) {
Node node = nodes.item(0);
node.setTextContent(value);
setParameters(parameters, i + 1, doc, xmlSettings);
}
} else {
// Just move to the next parameter
setParameters(parameters, i + 1, doc, xmlSettings);
}
} else {
// Add the final XML to the parameters to run
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer;
try {
transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
StringWriter writer = new StringWriter();
transformer.transform(new DOMSource(doc), new StreamResult(writer));
xmlSettings.add(writer.getBuffer().toString());
} catch (TransformerConfigurationException e) {
e.printStackTrace();
} catch (TransformerException e) {
e.printStackTrace();
}
}
}
use of javax.xml.transform.TransformerConfigurationException in project jackrabbit by apache.
the class ClientSession method exportDocumentView.
/**
* Exports the XML document view of the specified repository location
* to the given XML content handler. This method first requests the
* raw XML data from the remote session, and then uses an identity
* transformation to feed the data to the given XML content handler.
* Possible IO and transformer exceptions are thrown as SAXExceptions.
*
* {@inheritDoc}
*/
public void exportDocumentView(String path, ContentHandler handler, boolean binaryAsLink, boolean noRecurse) throws SAXException, RepositoryException {
try {
byte[] xml = remote.exportDocumentView(path, binaryAsLink, noRecurse);
Source source = new StreamSource(new ByteArrayInputStream(xml));
Result result = new SAXResult(handler);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.transform(source, result);
} catch (RemoteException ex) {
throw new RemoteRepositoryException(ex);
} catch (IOException ex) {
throw new SAXException(ex);
} catch (TransformerConfigurationException ex) {
throw new SAXException(ex);
} catch (TransformerException ex) {
throw new SAXException(ex);
}
}
use of javax.xml.transform.TransformerConfigurationException in project jackrabbit by apache.
the class SerializingContentHandler method getSerializer.
/**
* Creates a serializing content handler that writes to the given result.
*
* @param result serialization target
* @return serializing content handler
* @throws SAXException if the content handler could not be initialized
*/
public static DefaultHandler getSerializer(Result result) throws SAXException {
try {
TransformerHandler handler = FACTORY.newTransformerHandler();
handler.setResult(result);
// Specify the output properties to avoid surprises especially in
// character encoding or the output method (might be html for some
// documents!)
Transformer transformer = handler.getTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.ENCODING, ENCODING);
transformer.setOutputProperty(OutputKeys.INDENT, "no");
if (NEEDS_XMLNS_ATTRIBUTES) {
// so we need to do it explicitly with this wrapper
return new SerializingContentHandler(handler);
} else {
return new DefaultContentHandler(handler);
}
} catch (TransformerConfigurationException e) {
throw new SAXException("Failed to initialize XML serializer", e);
}
}
use of javax.xml.transform.TransformerConfigurationException in project jackrabbit by apache.
the class RepositoryConfig method internalCreateWorkspaceConfig.
/**
* Creates a new workspace configuration with the specified name and the
* specified workspace <code>template</.
* <p>
* This method creates a workspace configuration subdirectory,
* copies the workspace configuration template into it, and finally
* adds the created workspace configuration to the repository.
* The initialized workspace configuration object is returned to
* the caller.
*
* @param name workspace name
* @param template the workspace template
* @param configContent optional stringbuffer that will have the content
* of workspace configuration file written in
* @return created workspace configuration
* @throws ConfigurationException if creating the workspace configuration
* failed
*/
private synchronized WorkspaceConfig internalCreateWorkspaceConfig(String name, Element template, StringBuffer configContent) throws ConfigurationException {
// The physical workspace home directory on disk (TODO encode name?)
File directory = new File(workspaceDirectory, name);
// or cannot be created
if (!directory.mkdir()) {
if (directory.exists()) {
throw new ConfigurationException("Workspace directory already exists: " + name);
} else {
throw new ConfigurationException("Failed to create workspace directory: " + name);
}
}
FileSystem virtualFS;
if (workspaceConfigDirectory != null) {
// virtual repository file system
try {
virtualFS = fsf.getFileSystem();
} catch (RepositoryException e) {
throw new ConfigurationException("File system configuration error", e);
}
} else {
// workspace configurations are maintained on disk
virtualFS = null;
}
try {
Writer configWriter;
// get a writer for the workspace configuration file
if (virtualFS != null) {
// a configuration directoy had been specified; create workspace
// configuration in virtual repository file system rather than
// on disk
String configDir = workspaceConfigDirectory + FileSystem.SEPARATOR + name;
String configFile = configDir + FileSystem.SEPARATOR + WORKSPACE_XML;
try {
// Create the directory
virtualFS.createFolder(configDir);
configWriter = new OutputStreamWriter(virtualFS.getOutputStream(configFile));
} catch (FileSystemException e) {
throw new ConfigurationException("failed to create workspace configuration at path " + configFile, e);
}
} else {
File file = new File(directory, WORKSPACE_XML);
try {
configWriter = new FileWriter(file);
} catch (IOException e) {
throw new ConfigurationException("failed to create workspace configuration at path " + file.getPath(), e);
}
}
// the configuration writer.
try {
template.setAttribute("name", name);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
if (configContent == null) {
transformer.transform(new DOMSource(template), new StreamResult(configWriter));
} else {
StringWriter writer = new StringWriter();
transformer.transform(new DOMSource(template), new StreamResult(writer));
String s = writer.getBuffer().toString();
configWriter.write(s);
configContent.append(s);
}
} catch (IOException e) {
throw new ConfigurationException("Cannot create a workspace configuration file", e);
} catch (TransformerConfigurationException e) {
throw new ConfigurationException("Cannot create a workspace configuration writer", e);
} catch (TransformerException e) {
throw new ConfigurationException("Cannot create a workspace configuration file", e);
} finally {
IOUtils.closeQuietly(configWriter);
}
// Load the created workspace configuration.
WorkspaceConfig wc;
if (virtualFS != null) {
String configDir = workspaceConfigDirectory + FileSystem.SEPARATOR + name;
wc = loadWorkspaceConfig(virtualFS, configDir);
} else {
wc = loadWorkspaceConfig(directory);
}
if (wc != null) {
addWorkspaceConfig(wc);
return wc;
} else {
throw new ConfigurationException("Failed to load the created configuration for workspace " + name + ".");
}
} finally {
try {
if (virtualFS != null) {
virtualFS.close();
}
} catch (FileSystemException ignore) {
}
}
}
Aggregations