Search in sources :

Example 1 with NonclosingInputStream

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;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) Element(org.w3c.dom.Element) ZipEntry(java.util.zip.ZipEntry) NonclosingInputStream(net.sourceforge.processdash.util.NonclosingInputStream) FileInputStream(java.io.FileInputStream) MalformedURLException(java.net.MalformedURLException) SAXException(org.xml.sax.SAXException)

Example 2 with NonclosingInputStream

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);
}
Also used : FileInputStream(java.io.FileInputStream) NonclosingInputStream(net.sourceforge.processdash.util.NonclosingInputStream) InputStream(java.io.InputStream) MessageEvent(net.sourceforge.processdash.msg.MessageEvent) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) NonclosingInputStream(net.sourceforge.processdash.util.NonclosingInputStream) Document(org.w3c.dom.Document) HashSet(java.util.HashSet)

Example 3 with NonclosingInputStream

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);
}
Also used : JarInputStream(java.util.jar.JarInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) NonclosingInputStream(net.sourceforge.processdash.util.NonclosingInputStream) IOException(java.io.IOException) Document(org.w3c.dom.Document) URL(java.net.URL) SAXException(org.xml.sax.SAXException)

Example 4 with NonclosingInputStream

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);
}
Also used : Element(org.w3c.dom.Element) DashHierarchy(net.sourceforge.processdash.hier.DashHierarchy) NonclosingInputStream(net.sourceforge.processdash.util.NonclosingInputStream) Resources(net.sourceforge.processdash.i18n.Resources) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Aggregations

NonclosingInputStream (net.sourceforge.processdash.util.NonclosingInputStream)4 Document (org.w3c.dom.Document)3 Element (org.w3c.dom.Element)3 SAXException (org.xml.sax.SAXException)3 FileInputStream (java.io.FileInputStream)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashSet (java.util.HashSet)1 JarInputStream (java.util.jar.JarInputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 DashHierarchy (net.sourceforge.processdash.hier.DashHierarchy)1 Resources (net.sourceforge.processdash.i18n.Resources)1 MessageEvent (net.sourceforge.processdash.msg.MessageEvent)1 NodeList (org.w3c.dom.NodeList)1