Example usage for javax.xml.parsers ParserConfigurationException toString

List of usage examples for javax.xml.parsers ParserConfigurationException toString

Introduction

In this page you can find the example usage for javax.xml.parsers ParserConfigurationException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.example.apis.ifashion.YahooWeather.java

private Document convertStringToDocument(Context context, String src) {
    Document dest = null;//from w w w .j  a va2  s. co  m

    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser;

    try {
        parser = dbFactory.newDocumentBuilder();
        dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
    } catch (ParserConfigurationException e1) {
        e1.printStackTrace();
        Toast.makeText(context, e1.toString(), Toast.LENGTH_LONG).show();
    } catch (SAXException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    }

    return dest;
}

From source file:com.cloud.hypervisor.kvm.resource.LibvirtDomainXMLParser.java

public boolean parseDomainXML(String domXML) {
    DocumentBuilder builder;//from   w w  w . j  a v a2  s  . com
    try {
        builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();

        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(domXML));
        Document doc = builder.parse(is);

        Element rootElement = doc.getDocumentElement();

        desc = getTagValue("description", rootElement);

        Element devices = (Element) rootElement.getElementsByTagName("devices").item(0);
        NodeList disks = devices.getElementsByTagName("disk");
        for (int i = 0; i < disks.getLength(); i++) {
            Element disk = (Element) disks.item(i);
            String type = disk.getAttribute("type");
            DiskDef def = new DiskDef();
            if (type.equalsIgnoreCase("network")) {
                String diskFmtType = getAttrValue("driver", "type", disk);
                String diskCacheMode = getAttrValue("driver", "cache", disk);
                String diskPath = getAttrValue("source", "name", disk);
                String protocol = getAttrValue("source", "protocol", disk);
                String authUserName = getAttrValue("auth", "username", disk);
                String poolUuid = getAttrValue("secret", "uuid", disk);
                String host = getAttrValue("host", "name", disk);
                int port = Integer.parseInt(getAttrValue("host", "port", disk));
                String diskLabel = getAttrValue("target", "dev", disk);
                String bus = getAttrValue("target", "bus", disk);

                DiskDef.DiskFmtType fmt = null;
                if (diskFmtType != null) {
                    fmt = DiskDef.DiskFmtType.valueOf(diskFmtType.toUpperCase());
                }

                def.defNetworkBasedDisk(diskPath, host, port, authUserName, poolUuid, diskLabel,
                        DiskDef.DiskBus.valueOf(bus.toUpperCase()),
                        DiskDef.DiskProtocol.valueOf(protocol.toUpperCase()), fmt);
                def.setCacheMode(DiskDef.DiskCacheMode.valueOf(diskCacheMode.toUpperCase()));
            } else {
                String diskFmtType = getAttrValue("driver", "type", disk);
                String diskCacheMode = getAttrValue("driver", "cache", disk);
                String diskFile = getAttrValue("source", "file", disk);
                String diskDev = getAttrValue("source", "dev", disk);

                String diskLabel = getAttrValue("target", "dev", disk);
                String bus = getAttrValue("target", "bus", disk);
                String device = disk.getAttribute("device");

                if (type.equalsIgnoreCase("file")) {
                    if (device.equalsIgnoreCase("disk")) {
                        DiskDef.DiskFmtType fmt = null;
                        if (diskFmtType != null) {
                            fmt = DiskDef.DiskFmtType.valueOf(diskFmtType.toUpperCase());
                        }
                        def.defFileBasedDisk(diskFile, diskLabel, DiskDef.DiskBus.valueOf(bus.toUpperCase()),
                                fmt);
                    } else if (device.equalsIgnoreCase("cdrom")) {
                        def.defISODisk(diskFile);
                    }
                } else if (type.equalsIgnoreCase("block")) {
                    def.defBlockBasedDisk(diskDev, diskLabel, DiskDef.DiskBus.valueOf(bus.toUpperCase()));
                }
                if (diskCacheMode != null) {
                    def.setCacheMode(DiskDef.DiskCacheMode.valueOf(diskCacheMode.toUpperCase()));
                }
            }

            NodeList iotune = disk.getElementsByTagName("iotune");
            if ((iotune != null) && (iotune.getLength() != 0)) {
                String bytesReadRateStr = getTagValue("read_bytes_sec", (Element) iotune.item(0));
                if (bytesReadRateStr != null) {
                    Long bytesReadRate = Long.parseLong(bytesReadRateStr);
                    def.setBytesReadRate(bytesReadRate);
                }
                String bytesWriteRateStr = getTagValue("write_bytes_sec", (Element) iotune.item(0));
                if (bytesWriteRateStr != null) {
                    Long bytesWriteRate = Long.parseLong(bytesWriteRateStr);
                    def.setBytesWriteRate(bytesWriteRate);
                }
                String iopsReadRateStr = getTagValue("read_iops_sec", (Element) iotune.item(0));
                if (iopsReadRateStr != null) {
                    Long iopsReadRate = Long.parseLong(iopsReadRateStr);
                    def.setIopsReadRate(iopsReadRate);
                }
                String iopsWriteRateStr = getTagValue("write_iops_sec", (Element) iotune.item(0));
                if (iopsWriteRateStr != null) {
                    Long iopsWriteRate = Long.parseLong(iopsWriteRateStr);
                    def.setIopsWriteRate(iopsWriteRate);
                }
            }

            diskDefs.add(def);
        }

        NodeList nics = devices.getElementsByTagName("interface");
        for (int i = 0; i < nics.getLength(); i++) {
            Element nic = (Element) nics.item(i);

            String type = nic.getAttribute("type");
            String mac = getAttrValue("mac", "address", nic);
            String dev = getAttrValue("target", "dev", nic);
            String model = getAttrValue("model", "type", nic);
            String slot = StringUtils.removeStart(getAttrValue("address", "slot", nic), "0x");

            InterfaceDef def = new InterfaceDef();
            NodeList bandwidth = nic.getElementsByTagName("bandwidth");
            Integer networkRateKBps = 0;
            if ((bandwidth != null) && (bandwidth.getLength() != 0)) {
                Integer inbound = Integer
                        .valueOf(getAttrValue("inbound", "average", (Element) bandwidth.item(0)));
                Integer outbound = Integer
                        .valueOf(getAttrValue("outbound", "average", (Element) bandwidth.item(0)));
                if (inbound.equals(outbound)) {
                    networkRateKBps = inbound;
                }
            }
            if (type.equalsIgnoreCase("network")) {
                String network = getAttrValue("source", "network", nic);
                def.defPrivateNet(network, dev, mac, NicModel.valueOf(model.toUpperCase()), networkRateKBps);
            } else if (type.equalsIgnoreCase("bridge")) {
                String bridge = getAttrValue("source", "bridge", nic);
                def.defBridgeNet(bridge, dev, mac, NicModel.valueOf(model.toUpperCase()), networkRateKBps);
            } else if (type.equalsIgnoreCase("ethernet")) {
                String scriptPath = getAttrValue("script", "path", nic);
                def.defEthernet(dev, mac, NicModel.valueOf(model.toUpperCase()), scriptPath, networkRateKBps);
            }

            if (StringUtils.isNotBlank(slot)) {
                def.setSlot(Integer.parseInt(slot, 16));
            }

            interfaces.add(def);
        }

        NodeList ports = devices.getElementsByTagName("channel");
        for (int i = 0; i < ports.getLength(); i++) {
            Element channel = (Element) ports.item(i);

            String type = channel.getAttribute("type");
            String path = getAttrValue("source", "path", channel);
            String name = getAttrValue("target", "name", channel);
            String state = getAttrValue("target", "state", channel);

            ChannelDef def = null;
            if (!StringUtils.isNotBlank(state)) {
                def = new ChannelDef(name, ChannelDef.ChannelType.valueOf(type.toUpperCase()), new File(path));
            } else {
                def = new ChannelDef(name, ChannelDef.ChannelType.valueOf(type.toUpperCase()),
                        ChannelDef.ChannelState.valueOf(state.toUpperCase()), new File(path));
            }

            channels.add(def);
        }

        Element graphic = (Element) devices.getElementsByTagName("graphics").item(0);

        if (graphic != null) {
            String port = graphic.getAttribute("port");
            if (port != null) {
                try {
                    vncPort = Integer.parseInt(port);
                    if (vncPort != -1) {
                        vncPort = vncPort - 5900;
                    } else {
                        vncPort = null;
                    }
                } catch (NumberFormatException nfe) {
                    vncPort = null;
                }
            }
        }

        NodeList rngs = devices.getElementsByTagName("rng");
        for (int i = 0; i < rngs.getLength(); i++) {
            RngDef def = null;
            Element rng = (Element) rngs.item(i);
            String backendModel = getAttrValue("backend", "model", rng);
            String path = getTagValue("backend", rng);
            String bytes = getAttrValue("rate", "bytes", rng);
            String period = getAttrValue("rate", "period", rng);

            if (Strings.isNullOrEmpty(backendModel)) {
                def = new RngDef(path, Integer.parseInt(bytes), Integer.parseInt(period));
            } else {
                def = new RngDef(path, RngBackendModel.valueOf(backendModel.toUpperCase()),
                        Integer.parseInt(bytes), Integer.parseInt(period));
            }

            rngDefs.add(def);
        }

        NodeList watchDogs = devices.getElementsByTagName("watchdog");
        for (int i = 0; i < watchDogs.getLength(); i++) {
            WatchDogDef def = null;
            Element watchDog = (Element) watchDogs.item(i);
            String action = watchDog.getAttribute("action");
            String model = watchDog.getAttribute("model");

            if (Strings.isNullOrEmpty(model)) {
                continue;
            }

            if (Strings.isNullOrEmpty(action)) {
                def = new WatchDogDef(WatchDogModel.valueOf(model.toUpperCase()));
            } else {
                def = new WatchDogDef(WatchDogAction.valueOf(action.toUpperCase()),
                        WatchDogModel.valueOf(model.toUpperCase()));
            }

            watchDogDefs.add(def);
        }

        return true;
    } catch (ParserConfigurationException e) {
        s_logger.debug(e.toString());
    } catch (SAXException e) {
        s_logger.debug(e.toString());
    } catch (IOException e) {
        s_logger.debug(e.toString());
    }
    return false;
}

From source file:com.photon.phresco.nativeapp.eshop.activity.PhrescoActivity.java

/**
 * Read phresco-env-config.xml file to get to connect to web service
 *//* w  ww  .j a va  2 s.c  o  m*/
public void readConfigXML() {
    try {

        String protocol = "protocol";
        String host = "host";
        String port = "port";
        String context = "context";
        Resources resources = getResources();
        AssetManager assetManager = resources.getAssets();

        // Read from the /assets directory
        InputStream inputStream = assetManager.open(Constants.PHRESCO_ENV_CONFIG);

        ConfigReader confReaderObj = new ConfigReader(inputStream);

        PhrescoLogger.info(TAG + "Default ENV = " + confReaderObj.getDefaultEnvName());

        List<Configuration> configByEnv = confReaderObj.getConfigByEnv(confReaderObj.getDefaultEnvName());

        for (Configuration configuration : configByEnv) {
            properties = configuration.getProperties();
            PhrescoLogger.info(TAG + "config value = " + configuration.getProperties());
            String webServiceProtocol = properties.getProperty(protocol).endsWith("://")
                    ? properties.getProperty(protocol)
                    : properties.getProperty(protocol) + "://"; // http://

            String webServiceHost = properties.getProperty(port).equalsIgnoreCase("")
                    ? (properties.getProperty(host).endsWith("/") ? properties.getProperty(host)
                            : properties.getProperty(host) + "/")
                    : properties.getProperty(host); // localhost/
            // localhost

            String webServicePort = properties.getProperty(port).equalsIgnoreCase("") ? ""
                    : (properties.getProperty(port).startsWith(":") ? properties.getProperty(port)
                            : ":" + properties.getProperty(port)); // "" (blank)
            // :1313

            String webServiceContext = properties.getProperty(context).startsWith("/")
                    ? properties.getProperty(context)
                    : "/" + properties.getProperty(context); // /phresco

            Constants.setWebContextURL(
                    webServiceProtocol + webServiceHost + webServicePort + webServiceContext + "/");
            Constants.setRestAPI(Constants.REST_API);
            PhrescoLogger.info(
                    TAG + "Constants.webContextURL : " + Constants.getWebContextURL() + Constants.getRestAPI());
        }

    } catch (ParserConfigurationException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : ParserConfigurationException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (SAXException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : SAXException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (IOException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : IOException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (Exception ex) {
        PhrescoLogger.info(TAG + "readConfigXML : Exception: " + ex.toString());
        PhrescoLogger.warning(ex);
    }
}

From source file:com.cloudera.recordbreaker.analyzer.XMLSchemaDescriptor.java

void computeSchema() throws IOException {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser parser = null;//w  w w  .  j av a  2  s.  co  m
    // Unfortunately, validation is often not possible
    factory.setValidating(false);

    try {
        // The XMLProcessor builds up a tree of tags
        XMLProcessor xp = new XMLProcessor();
        parser = factory.newSAXParser();
        parser.parse(dd.getRawBytes(), xp);

        // Grab the root tag
        this.rootTag = xp.getRoot();

        // Once the tree is built, we:
        // a) Find the correct repetition node (and throws out 'bad' repeats)
        // b) Flatten hierarchies of subfields into a single layer, so it's suitable
        //    for relational-style handling
        // c) Build an overall schema object that can summarize every expected
        //    object, even if the objects' individual schemas differ somewhat
        this.rootTag.completeTree();
    } catch (SAXException saxe) {
        throw new IOException(saxe.toString());
    } catch (ParserConfigurationException pcee) {
        throw new IOException(pcee.toString());
    }
}

From source file:cz.muni.fi.japanesedictionary.parser.ParserService.java

/**
 * Downloads dictionaries and launches parseDictionaries()
 * /*from w  w  w. jav  a2  s.  com*/
 * @throws IOException
 */
private void downloadDictionaries() throws IOException {
    Log.i(LOG_TAG, "downloading JMDict");
    if (mDownloadingJMDict) {
        if (downloadFile(mDownloadJMDictFrom, mDownloadJMDictTo)) {
            mDownloadingJMDict = false;
            mDownloadingKanjidic = true;
        } else {
            return;
        }
    }
    Log.i(LOG_TAG, "downloading Kanjidic2");
    if (mDownloadingKanjidic) {
        mBuilder.setContentTitle(getString(R.string.dictionary_kanji_download_title)).setProgress(100, 0, false)
                .setContentText(getString(R.string.dictionary_download_in_progress) + " (2/5)")
                .setContentInfo("0%");

        mNotifyManager.notify(0, mBuilder.build());

        if (downloadFile(mDownloadKanjidicFrom, mDownloadKanjidicTo)) {
            mDownloadingKanjidic = false;
            mDownloadingTatoebaIndices = true;

            Log.i(LOG_TAG, "Downloading dictionary finished");

        } else {
            return;
        }
    }
    Log.i(LOG_TAG, "downloading Tatoeba japanese");
    if (mDownloadingTatoebaIndices) {
        mBuilder.setContentTitle(getString(R.string.dictionary_tatoeba_download_title))
                .setProgress(100, 0, false)
                .setContentText(getString(R.string.dictionary_download_in_progress) + " (3/5)")
                .setContentInfo("0%");

        mNotifyManager.notify(0, mBuilder.build());

        if (downloadFile(mDownloadTatoebaIndicesFrom, mDownloadTatoebaIndicesTo)) {
            mDownloadingTatoebaIndices = false;
            mDownloadingTatoebaSentences = true;
            Log.i(LOG_TAG, "Downloading dictionary finished");

        } else {
            return;
        }
    }
    Log.i(LOG_TAG, "downloading Tatoeba translations");
    if (mDownloadingTatoebaSentences) {
        mBuilder.setContentTitle(getString(R.string.dictionary_tatoeba_download_title))
                .setProgress(100, 0, false)
                .setContentText(getString(R.string.dictionary_download_in_progress) + " (4/5)")
                .setContentInfo("0%");

        mNotifyManager.notify(0, mBuilder.build());

        if (downloadFile(mDownloadTatoebaSentencesFrom, mDownloadTatoebaSentencesTo)) {
            mDownloadingTatoebaSentences = false;
            mDownloadingKanjiVG = true;

            Log.i(LOG_TAG, "Downloading dictionary finished");

        } else {
            return;
        }
    }
    Log.i(LOG_TAG, "downloading kanjivg strokes");
    if (mDownloadingKanjiVG) {
        mBuilder.setContentTitle(getString(R.string.dictionary_kanjivg_download_title))
                .setProgress(100, 0, false)
                .setContentText(getString(R.string.dictionary_download_in_progress) + " (5/5)")
                .setContentInfo("0%");

        mNotifyManager.notify(0, mBuilder.build());

        if (downloadFile(mDownloadKanjiVGFrom, mDownloadKanjiVGTo)) {
            mDownloadingKanjiVG = false;
            mDownloadInProgress = false;

            Log.i(LOG_TAG, "Downloading dictionary finished");

        } else {
            return;
        }
    }

    if (!mDownloadInProgress && !mParsing) {
        try {
            mParsing = true;
            parseDictionaries();
        } catch (ParserConfigurationException e) {
            Log.e(LOG_TAG, "ParserConfigurationException exception occured: " + e.toString());
            stopSelf(mStartId);
        } catch (SAXException e) {
            Log.e(LOG_TAG, "SAXException exception occured: " + e.toString());
            stopSelf(mStartId);
        }
    }
}

From source file:nlp.corpora.NUSSMSCorpus.java

/****************************************************************
 * This method is to read the file(s) from NUS SMS Corpus and extract
 * the necessary text from the specific tag.
 *//*from w w  w.  j a v  a2 s  . c  om*/
private List<String> readFile(String fileName) {

    List<String> rawData = new ArrayList<>();
    DocumentBuilder builder;
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    try {
        builder = builderFactory.newDocumentBuilder();
        Document document = builder.parse(fileName);
        document.getDocumentElement().normalize();
        NodeList posts = document.getElementsByTagName("message");
        for (int i = 0; i < posts.getLength(); i++) {
            Node nNode = posts.item(i);
            if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                Element eElement = (Element) nNode;
                rawData.add(eElement.getElementsByTagName("text").item(0).getTextContent().trim());
            }
        }
    } catch (ParserConfigurationException e) {
        System.out.println(e.toString());
        System.out.println("Warning: In method readFile(), error occurred while parsing");
    } catch (IOException e) {
        System.out.println(e.toString());
        System.out.println("Warning: In method readFile(), could not find the file");
    } catch (SAXException e) {
        System.out.println(e.toString());
        System.out.println("Warning: In method readFile(), exception with builder");
    }
    return rawData;
}

From source file:org.cytobank.acs.core.TableOfContents.java

/**
 * Parses an ACS table of contents xml from an <code>InputStream</code> and sets the <code>tableOfContentsDoc</code> and <code>element</code>
 * element variables for this instance from the xml parser.
 *
 * @param tableOfContentsXmlStream the table of contents
 * @throws InvalidIndexException If the file version could not be parsed, or does not conform to the spec.
 * @throws IOException If an input or output exception occurred
 * @throws URISyntaxException If there is a problem with any of the URIs contained within the <code>TableOfContents</code> or if the URI is a duplicate
 * @throws InvalidAssociationException if there is an invalid association
 * @throws DuplicateFileResourceIdentifierException If any of the URIs contained within the <code>TableOfContents</code> is a duplicate
 * @throws SAXException If there was a problem parsing the xml
 *//*from www.ja  v a 2 s. c  o  m*/
protected void parseXml(InputStream tableOfContentsXmlStream)
        throws InvalidIndexException, IOException, URISyntaxException, InvalidAssociationException,
        DuplicateFileResourceIdentifierException, SAXException {
    try {

        DocumentBuilder docBuilder = getDocumentBuilder();

        tableOfContentsDoc = docBuilder.parse(tableOfContentsXmlStream);
        element = tableOfContentsDoc.getDocumentElement();
        setupFileResourceIdentifiers();
        setupAdditionalInfo();

    } catch (ParserConfigurationException pce) {
        throw new InvalidIndexException(pce.toString());
    }

}

From source file:org.jenkinsci.plugins.pipeline.maven.MavenSpyLogProcessor.java

public void processMavenSpyLogs(StepContext context, FilePath mavenSpyLogFolder, List<MavenPublisher> options)
        throws IOException, InterruptedException {
    FilePath[] mavenSpyLogsList = mavenSpyLogFolder.list("maven-spy-*.log");
    LOGGER.log(Level.FINE, "Found {0} maven execution reports in {1}",
            new Object[] { mavenSpyLogsList.length, mavenSpyLogFolder });

    TaskListener listener = context.get(TaskListener.class);
    if (listener == null) {
        LOGGER.warning("TaskListener is NULL, default to stderr");
        listener = new StreamBuildListener((OutputStream) System.err);
    }/*from  ww  w .  j a  v a 2 s  . c  o  m*/
    FilePath workspace = context.get(FilePath.class);

    DocumentBuilder documentBuilder;
    try {
        documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new IllegalStateException("Failure to create a DocumentBuilder", e);
    }

    for (FilePath mavenSpyLogs : mavenSpyLogsList) {
        try {
            if (LOGGER.isLoggable(Level.FINE)) {
                listener.getLogger()
                        .println("[withMaven]  Evaluate Maven Spy logs: " + mavenSpyLogs.getRemote());
            }
            InputStream mavenSpyLogsInputStream = mavenSpyLogs.read();
            if (mavenSpyLogsInputStream == null) {
                throw new IllegalStateException("InputStream for " + mavenSpyLogs.getRemote() + " is null");
            }

            FilePath archiveJenkinsMavenEventSpyLogs = workspace.child(".archive-jenkins-maven-event-spy-logs");
            if (archiveJenkinsMavenEventSpyLogs.exists()) {
                LOGGER.log(Level.FINE, "Archive Jenkins Maven Event Spy logs {0}", mavenSpyLogs.getRemote());
                new JenkinsMavenEventSpyLogsPublisher().process(context, mavenSpyLogs);
            }

            Element mavenSpyLogsElt = documentBuilder.parse(mavenSpyLogsInputStream).getDocumentElement();

            List<MavenPublisher> mavenPublishers = MavenPublisher.buildPublishersList(options, listener);
            for (MavenPublisher mavenPublisher : mavenPublishers) {
                String skipFileName = mavenPublisher.getDescriptor().getSkipFileName();
                if (Boolean.TRUE.equals(mavenPublisher.isDisabled())) {
                    listener.getLogger().println("[withMaven] Skip '"
                            + mavenPublisher.getDescriptor().getDisplayName() + "' disabled by configuration");
                } else if (StringUtils.isNotEmpty(skipFileName) && workspace.child(skipFileName).exists()) {
                    listener.getLogger()
                            .println("[withMaven] Skip '" + mavenPublisher.getDescriptor().getDisplayName()
                                    + "' disabled by marker file '" + skipFileName + "'");
                } else {
                    if (LOGGER.isLoggable(Level.FINE)) {
                        listener.getLogger().println(
                                "[withMaven] Run '" + mavenPublisher.getDescriptor().getDisplayName() + "'...");
                    }
                    try {
                        mavenPublisher.process(context, mavenSpyLogsElt);
                    } catch (IOException | RuntimeException e) {
                        PrintWriter error = listener
                                .error("[withMaven] WARNING Exception executing Maven reporter '"
                                        + mavenPublisher.getDescriptor().getDisplayName() + "' / "
                                        + mavenPublisher.getDescriptor().getId() + "."
                                        + " Please report a bug associated for the component 'pipeline-maven-plugin' at https://issues.jenkins-ci.org ");
                        e.printStackTrace(error);

                    }
                }
            }

        } catch (SAXException e) {
            Run run = context.get(Run.class);
            if (run.getActions(InterruptedBuildAction.class).isEmpty()) {
                listener.error(
                        "[withMaven] WARNING Exception parsing the logs generated by the Jenkins Maven Event Spy "
                                + mavenSpyLogs + ", ignore file. "
                                + " Please report a bug associated for the component 'pipeline-maven-plugin' at https://issues.jenkins-ci.org ");
            } else {
                // job has been aborted (see InterruptedBuildAction)
                listener.error(
                        "[withMaven] WARNING logs generated by the Jenkins Maven Event Spy " + mavenSpyLogs
                                + " are invalid, probably due to the interruption of the job, ignore file.");
            }
            listener.error(e.toString());
        } catch (Exception e) {
            PrintWriter errorWriter = listener.error(
                    "[withMaven] WARNING Exception processing the logs generated by the Jenkins Maven Event Spy "
                            + mavenSpyLogs + ", ignore file. "
                            + " Please report a bug associated for the component 'pipeline-maven-plugin' at https://issues.jenkins-ci.org ");
            e.printStackTrace(errorWriter);
        }
    }
    FilePath[] mavenSpyLogsInterruptedList = mavenSpyLogFolder.list("maven-spy-*.log.tmp");
    if (mavenSpyLogsInterruptedList.length > 0) {
        listener.getLogger()
                .print("[withMaven] One or multiple Maven executions have been ignored by the "
                        + "Jenkins Pipeline Maven Plugin because they have been interrupted before completion "
                        + "(" + mavenSpyLogsInterruptedList.length + "). See ");
        listener.hyperlink(
                "https://wiki.jenkins.io/display/JENKINS/Pipeline+Maven+Plugin#PipelineMavenPlugin-mavenExecutionInterrupted",
                "Pipeline Maven Plugin FAQ");
        listener.getLogger().println(" for more details.");
        if (LOGGER.isLoggable(Level.FINE)) {
            for (FilePath mavenSpyLogsInterruptedLogs : mavenSpyLogsInterruptedList) {
                listener.getLogger().print("[withMaven] Ignore: " + mavenSpyLogsInterruptedLogs.getRemote());
            }
        }
    }
}

From source file:org.jts.protocolvalidator.DefinitionFinder.java

private static String getFileID(File file) throws Exception {
    Document doc = null;/*from  www  . j ava  2  s .  co  m*/
    DocumentBuilder db = null;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    String id = "";

    try {
        db = dbf.newDocumentBuilder();
    } catch (javax.xml.parsers.ParserConfigurationException pce) {
        Logger.getLogger(JTSFileWriter.class.getName()).log(Level.SEVERE,
                "Exception while configuring parser: " + pce.toString(), pce);
        throw new CodeGeneratorException("Exception while configuring parser: " + pce.getMessage());
    }
    // see if the file can be parsed
    try {
        doc = db.parse(file);
    } catch (final IOException ioe) {
        Logger.getLogger(JTSFileWriter.class.getName()).log(Level.SEVERE,
                "Unable to read file" + file.getName() + " \n " + ioe.toString(), ioe);
    } catch (final SAXException saxe) {
        Logger.getLogger(JTSFileWriter.class.getName()).log(Level.SEVERE,
                "Unable to parse file" + file.getName() + " \n " + saxe.toString(), saxe);
    }

    // getting the id from the file
    Element root = doc.getDocumentElement();

    if (root.getAttribute("xmlns").equals("urn:jaus:jsidl:1.0")) {
        id = root.getAttribute("id");
    }

    return id;
}

From source file:org.jts.protocolvalidator.DefinitionFinder.java

/**
 * Filter jsidl files and place in a Map with associated id.
 * @param fileList list of JSIDL XML files
 */// w  w  w.  ja va2  s.c om
private void populateIDMap(List<File> fileList, String schemaPath) throws Exception {

    Document doc = null;
    DocumentBuilder db = null;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    String id = "";

    try {
        db = dbf.newDocumentBuilder();
    } catch (javax.xml.parsers.ParserConfigurationException pce) {
        Logger.getLogger(JTSFileWriter.class.getName()).log(Level.SEVERE,
                "Exception while configuring parser: " + pce.toString(), pce);
        throw new CodeGeneratorException("Exception while configuring parser: " + pce.getMessage());
    }

    // store the path/id for each path in the list
    for (int ii = 0; ii < fileList.size(); ii++) {
        File file = fileList.get(ii);
        final String fileName = file.getPath();

        // see if the file can be parsed
        try {
            doc = db.parse(file);
        } catch (final IOException ioe) {
            Logger.getLogger(JTSFileWriter.class.getName()).log(Level.SEVERE,
                    "Unable to read file" + fileName + " \n " + ioe.toString(), ioe);
            continue; // weaken import to allow bad files in target dir
        } catch (final SAXException saxe) {
            Logger.getLogger(JTSFileWriter.class.getName()).log(Level.SEVERE,
                    "Unable to parse file" + fileName + " \n " + saxe.toString(), saxe);
            continue; // weaken import to allow bad files in target dir
        }

        // getting the id from the file
        Element root = doc.getDocumentElement();

        if (root.getAttribute("xmlns").equals("urn:jaus:jsidl:1.0")) {
            JSIDLReader reader = new JSIDLReader(fileName, schemaPath);
            Object rootObj = reader.getRootElement();
            if (rootObj instanceof ServiceDef) {
                serviceDefMap.put(((ServiceDef) rootObj).getId(), ((ServiceDef) rootObj));
                serviceSet.getServiceDef().add(((ServiceDef) rootObj));
            } else if (rootObj instanceof DeclaredTypeSet) {
                typeSetMap.put(((DeclaredTypeSet) rootObj).getId(), ((DeclaredTypeSet) rootObj));
                serviceSet.getDeclaredTypeSet().add(((DeclaredTypeSet) rootObj));
            } else if (rootObj instanceof DeclaredConstSet) {
                constSetMap.put(((DeclaredConstSet) rootObj).getId(), ((DeclaredConstSet) rootObj));
                serviceSet.getDeclaredConstSet().add(((DeclaredConstSet) rootObj));
            }
        }
    }

}