use of net.sourceforge.processdash.util.NonclosingInputStream in project processdash by dtuma.
the class WBSSynchronizer method getUserDumpData.
private Element getUserDumpData(File f) {
FileInputStream fileInputStream = null;
Element result = null;
String datasetID = null;
try {
fileInputStream = new FileInputStream(f);
ZipInputStream zipIn = new ZipInputStream(new BufferedInputStream(fileInputStream));
NonclosingInputStream nis = new NonclosingInputStream(zipIn);
ZipEntry e;
while ((e = zipIn.getNextEntry()) != null) {
if (e.getName().equals(USER_DUMP_ENTRY_NAME)) {
result = XMLUtils.parse(nis).getDocumentElement();
if (result.hasAttribute(DATASET_ID_ATTR))
break;
} else if (e.getName().equals(MANIFEST_ENTRY_NAME)) {
datasetID = getDatasetIdFromManifest(nis);
}
}
} catch (Exception e) {
logger.severe("Unable to read user dump data from file " + f);
e.printStackTrace();
}
FileUtils.safelyClose(fileInputStream);
if (result == null) {
// the user's exported pdash file did not contain a dump file.
logger.fine("No " + USER_DUMP_ENTRY_NAME + " file found in " + f);
} else if (XMLUtils.hasValue(datasetID)) {
result.setAttribute(DATASET_ID_ATTR, datasetID);
}
return result;
}
use of net.sourceforge.processdash.util.NonclosingInputStream in project processdash by dtuma.
the class MessageImporterXMLv1 method doImport.
private static void doImport(ArchiveMetricsFileImporter caller, InputStream in, boolean serverMode) throws Exception {
// read the XML document from the input stream.
InputStream xmlIn = new NonclosingInputStream(in);
Document doc = XMLUtils.parse(xmlIn);
Set<String> serverIDs = new HashSet();
// Now, find all of the messages in the document
NodeList messages = doc.getElementsByTagName(MESSAGE_TAG);
if (messages != null) {
for (int i = 0; i < messages.getLength(); i++) {
Element msg = (Element) messages.item(i);
MessageEvent msgEvent = new MessageEvent(msg);
if (serverMode) {
// handle server messages immediately, and keep track of
// the server message IDs we've seen.
MessageDispatcher.getInstance().dispatch(msgEvent, false);
serverIDs.add(msgEvent.getServerId());
} else {
// Register a task to dispatch each message later on the
// background thread. (Message handling logic is defined
// by third parties, and we have no guarantee that it will
// finish in a timely manner. We can't risk hanging the
// import operation indefinitely.)
BackgroundTaskManager.getInstance().addTask(new MessageDispatchTask(msgEvent));
}
}
}
NodeList nl = doc.getElementsByTagName(DELETE_TAG);
if (nl != null && nl.getLength() > 0 && caller != null)
caller.deleteArchiveFileOnCompletion();
if (serverMode)
MessageDispatcher.getInstance().setKnownServerMessagesIDs(serverIDs);
}
use of net.sourceforge.processdash.util.NonclosingInputStream in project processdash by dtuma.
the class MCFManager method registerMcf.
public InputStream registerMcf(String baseURL, InputStream processXml, String knownVersion, boolean extFileAllowed) throws IOException {
// parse the XML doc from the jar file input stream
Document settings;
try {
NonclosingInputStream in = new NonclosingInputStream(processXml);
settings = XMLUtils.parse(in);
} catch (SAXException e) {
throw new IOException("Error parsing settings.xml in " + baseURL, e);
}
// ensure this is the XML file for a custom process
String rootTag = settings.getDocumentElement().getTagName();
if (!CustomProcess.ROOT_TAG.equals(rootTag))
return null;
// create and initialize a publisher for this custom process
CustomProcess process = new CustomProcess(settings);
URL extBase = new URL(baseURL);
CustomProcessPublisher publisher = new CustomProcessPublisher(contentSource, extBase);
publisher.setHeadless(true);
publisher.setExtFileAllowed(extFileAllowed);
publisher.loadTimestampFromVersion(knownVersion);
if (processXml instanceof JarInputStream)
publisher.loadInfoFromManifest(((JarInputStream) processXml).getManifest());
publisher.publish(process, null);
// record the publisher in our data structures for later use
String processID = process.getProcessID();
mcfPublishers.put(processID, publisher);
// return an input stream with the contents of the template.xml file
String templateFilename = "/Templates/" + processID + "-template.xml";
byte[] templateXmlData = publisher.getGeneratedFileContents(templateFilename);
return new ByteArrayInputStream(templateXmlData);
}
use of net.sourceforge.processdash.util.NonclosingInputStream in project processdash by dtuma.
the class TemplateLoader method loadXMLProcessTemplate.
private static void loadXMLProcessTemplate(DashHierarchy templates, DataRepository data, String filename, URL baseUrl, long modTime, InputStream in, boolean close) throws IOException {
Element root = null;
try {
if (!close)
in = new NonclosingInputStream(in);
// this closes the file without our permission.
Document doc = XMLUtils.parse(in);
ExtensionManager.addXmlDoc(doc, filename, baseUrl, modTime);
root = doc.getDocumentElement();
} catch (SAXException se) {
String message = XMLUtils.exceptionMessage(se);
Resources r = Resources.getDashBundle("Templates");
if (message == null)
message = r.format("Error_FMT", filename);
else
message = r.format("Error_Message_FMT", filename, message);
logTemplateError(message);
return;
}
AutoData.registerTemplates(root, data);
createScriptMaps(root);
try {
DashHierarchy template = new DashHierarchy(null);
template.loadXMLTemplate(root);
template.premove(PropertyKey.ROOT);
createScriptMaps(template);
templates.putAll(template);
} catch (SAXException se) {
// Can this happen?
}
generateDefaultScriptMaps(root);
}
Aggregations