Example usage for javax.xml.parsers ParserConfigurationException getMessage

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

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.extensiblecatalog.ncip.v2.koha.KohaLookupItemService.java

/**
 * Handles a NCIP LookupItem service by returning data from Koha.
 *
 * @param initData//from ww  w .  ja v  a 2s.com
 *            the LookupItemInitiationData
 * @param serviceManager
 *            provides access to remote services
 * @return LookupItemResponseData
 */
@Override
public LookupItemResponseData performService(LookupItemInitiationData initData, ServiceContext serviceContext,
        RemoteServiceManager serviceManager) throws ServiceException {

    final LookupItemResponseData responseData = new LookupItemResponseData();

    boolean itemIdIsEmpty = initData.getItemId().getItemIdentifierValue().isEmpty();

    if (itemIdIsEmpty) {

        Problem p = new Problem(new ProblemType("Item id is undefined."), null, null);
        responseData.setProblems(Arrays.asList(p));

    } else {

        KohaRemoteServiceManager kohaRemoteServiceManager = (KohaRemoteServiceManager) serviceManager;

        try {
            JSONObject kohaItem = kohaRemoteServiceManager.lookupItem(initData);
            updateResponseData(initData, responseData, kohaItem);

        } catch (IOException ie) {
            Problem p = new Problem(new ProblemType("Processing IOException error."), ie.getMessage(),
                    "Are you connected to the Internet/Intranet?");
            responseData.setProblems(Arrays.asList(p));
        } catch (SAXException se) {
            Problem p = new Problem(new ProblemType("Processing SAXException error."), null, se.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (KohaException ke) {
            Problem p = new Problem(new ProblemType(ke.getShortMessage()), null, ke.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (ParserConfigurationException pce) {
            Problem p = new Problem(new ProblemType("Processing ParserConfigurationException error."), null,
                    pce.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (Exception e) {
            Problem p = new Problem(new ProblemType("Unknown processing exception error."), null,
                    StringUtils.join(e.getStackTrace(), "\n"));
            responseData.setProblems(Arrays.asList(p));
        }
    }
    return responseData;
}

From source file:org.extensiblecatalog.ncip.v2.koha.KohaRenewItemService.java

@Override
public RenewItemResponseData performService(RenewItemInitiationData initData, ServiceContext serviceContext,
        RemoteServiceManager serviceManager) throws ServiceException {

    final RenewItemResponseData responseData = new RenewItemResponseData();

    boolean itemIdIsEmpty = initData.getItemId() == null
            || initData.getItemId().getItemIdentifierValue().isEmpty();
    boolean userIdIsEmpty = initData.getUserId() == null
            || initData.getUserId().getUserIdentifierValue().isEmpty();

    if (itemIdIsEmpty || userIdIsEmpty) {

        List<Problem> problems = new ArrayList<Problem>();

        if (itemIdIsEmpty) {

            Problem p = new Problem(new ProblemType("Item id is undefined."), null, null,
                    "Cannot renew unknown item.");
            problems.add(p);//from  ww  w.ja v a2 s .co  m

        }
        if (userIdIsEmpty) {

            Problem p = new Problem(new ProblemType("User Id is undefined."), null, null,
                    "Cannot renew item for unknown user.");
            problems.add(p);

        }
        responseData.setProblems(problems);

    } else {

        KohaRemoteServiceManager kohaRemoteServiceManager = (KohaRemoteServiceManager) serviceManager;

        try {
            JSONObject renewItem = kohaRemoteServiceManager.renewItem(initData);

            updateResponseData(responseData, initData, renewItem);

        } catch (IOException ie) {
            Problem p = new Problem(new ProblemType("Processing IOException error."), ie.getMessage(),
                    "Are you connected to the Internet/Intranet?");
            responseData.setProblems(Arrays.asList(p));
        } catch (SAXException se) {
            Problem p = new Problem(new ProblemType("Processing SAXException error."), null, se.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (KohaException ke) {
            Problem p = new Problem(new ProblemType(ke.getShortMessage()), null, ke.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (ParserConfigurationException pce) {
            Problem p = new Problem(new ProblemType("Processing ParserConfigurationException error."), null,
                    pce.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (Exception e) {
            Problem p = new Problem(new ProblemType("Unknown processing exception error."), null,
                    StringUtils.join(e.getStackTrace(), "\n"));
            responseData.setProblems(Arrays.asList(p));
        }
    }
    return responseData;
}

From source file:org.fenixedu.academic.servlet.ProcessCandidacyPrintAllDocumentsFilter.java

@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
        throws IOException, ServletException {
    arg2.doFilter(arg0, arg1);/*from w  w  w.  ja va 2s .c o m*/

    HttpServletRequest request = (HttpServletRequest) arg0;

    if ("doOperation".equals(request.getParameter("method"))
            && "PRINT_ALL_DOCUMENTS".equals(request.getParameter("operationType"))) {

        try {
            ResponseWrapper response = (ResponseWrapper) arg1;
            // clean the response html and make a DOM document out of it
            String responseHtml = clean(response.getContent());
            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = builder
                    .parse(new ByteArrayInputStream(responseHtml.getBytes(StandardCharsets.UTF_8)));

            // alter paths of link/img tags so itext can use them properly
            patchLinks(doc, request);

            // structure pdf document
            ITextRenderer renderer = new ITextRenderer();
            renderer.setDocument(doc, "");
            renderer.layout();

            // create the pdf
            ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
            renderer.createPDF(pdfStream);

            // concatenate with other docs
            final Person person = (Person) request.getAttribute("person");
            final StudentCandidacy candidacy = getCandidacy(request);
            ByteArrayOutputStream finalPdfStream = concatenateDocs(pdfStream.toByteArray(), person);
            byte[] pdfByteArray = finalPdfStream.toByteArray();

            // associate the summary file to the candidacy
            associateSummaryFile(pdfByteArray, person.getStudent().getNumber().toString(), candidacy);

            // redirect user to the candidacy summary page
            response.reset();
            response.sendRedirect(buildRedirectURL(request, candidacy));

            response.flushBuffer();
        } catch (ParserConfigurationException e) {
            logger.error(e.getMessage(), e);
        } catch (SAXException e) {
            logger.error(e.getMessage(), e);
        } catch (DocumentException e) {
            logger.error(e.getMessage(), e);
        }
    }
}

From source file:org.grails.plugins.CorePluginFinder.java

@SuppressWarnings("rawtypes")
private void loadCorePluginsFromResources(Resource[] resources) throws IOException {

    LOG.debug("Attempting to load [" + resources.length + "] core plugins");
    try {//from  w  w w  .  j  a v  a  2s . c  o m
        SAXParser saxParser = SpringIOUtils.newSAXParser();
        for (Resource resource : resources) {
            InputStream input = null;

            try {
                input = resource.getInputStream();
                PluginHandler ph = new PluginHandler();
                saxParser.parse(input, ph);

                for (String pluginType : ph.pluginTypes) {
                    Class<?> pluginClass = attemptCorePluginClassLoad(pluginType);
                    if (pluginClass != null) {
                        addPlugin(pluginClass);
                        binaryDescriptors.put(pluginClass,
                                new BinaryGrailsPluginDescriptor(resource, ph.pluginClasses));
                    }
                }

            } finally {
                if (input != null) {
                    input.close();
                }
            }
        }
    } catch (ParserConfigurationException e) {
        throw new GrailsConfigurationException("XML parsing error loading core plugins: " + e.getMessage(), e);
    } catch (SAXException e) {
        throw new GrailsConfigurationException("XML parsing error loading core plugins: " + e.getMessage(), e);
    }
}

From source file:org.hyperic.hq.plugin.jboss.JBossConfig.java

private Document parse(File file) throws IOException {

    FileInputStream fis = null;//from   www  .j ava 2 s.  c o m

    try {
        fis = new FileInputStream(file);
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder parser = factory.newDocumentBuilder();
        return parser.parse(new InputSource(fis));
    } catch (ParserConfigurationException e) {
        throw new IllegalArgumentException(e.getMessage());
    } catch (SAXException e) {
        throw new IllegalArgumentException(e.getMessage());
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException e) {
            }
        }
    }
}

From source file:org.icatproject.idav.methods.AbstractMethod.java

/**
 * Return JAXP document builder instance.
 *//* ww w . java  2s .c om*/
protected DocumentBuilder getDocumentBuilder() throws ServletException {
    DocumentBuilder documentBuilder = null;
    DocumentBuilderFactory documentBuilderFactory = null;
    try {
        documentBuilderFactory = DocumentBuilderFactory.newInstance();
        documentBuilderFactory.setNamespaceAware(true);
        // disable XML External Entities to prevent XML XXE attacks as described at:
        // https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Prevention_Cheat_Sheet
        documentBuilderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
        documentBuilderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
        documentBuilderFactory.setXIncludeAware(false);
        documentBuilderFactory.setExpandEntityReferences(false);
        //
        documentBuilder = documentBuilderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        String msg = "Failed to create an XML DocumentBuilder which satisfies the configuration requested: "
                + e.getMessage();
        LOG.error(msg);
        throw new ServletException(msg);
    }
    return documentBuilder;
}

From source file:org.iterx.miru.bean.factory.XmlBeanParser.java

public void parse(StreamSource source) throws IOException {
    try {/*from  w ww .j  ava 2  s  .c o m*/
        SAXParserFactory factory;
        SAXParser parser;

        factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(true);

        parser = factory.newSAXParser();
        parser.parse(source.getInputStream(), this);
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    } catch (SAXException e) {
        if (LOGGER.isErrorEnabled())
            LOGGER.error(e, e);
        throw new IOException("Invalid xml stream [" + source + "]. " + e.getMessage());
    }
}

From source file:org.iterx.miru.dispatcher.handler.factory.XmlHandlerChainParser.java

public void parse(StreamSource source) throws IOException {
    try {//from www  .  j  av a 2  s.co  m
        SAXParserFactory factory;
        SAXParser parser;

        factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(true);

        parser = factory.newSAXParser();
        parser.parse(source.getInputStream(), this);
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    } catch (SAXException e) {
        if (LOGGER.isErrorEnabled())
            LOGGER.error(e);
        throw new IOException("Invalid xml stream [" + source + "]. " + e.getMessage());
    }
}

From source file:org.iterx.miru.handler.XmlHandlerMappingParser.java

public void parse(Resource resource) throws IOException {

    try {/*from w w w  . j a va 2s  .c om*/
        SAXParserFactory factory;
        SAXParser parser;

        factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(true);

        parser = factory.newSAXParser();
        parser.parse(resource.getInputStream(), this);
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    } catch (SAXException e) {
        throw new IOException("Invalid xml stream: " + e.getMessage());
    }
}

From source file:org.jboss.confluence.plugin.docbook_tools.docbookimport.DocbookImporter.java

/**
 * Constructor with some checks for necessary infrastructure.
 *//*from   w  w w .ja  va  2  s .  c o m*/
public DocbookImporter() {
    String name = transformerFact.getClass().getName();
    if (!name.contains(".xalan.")) {
        log.error("We need Xalan XSLT processor! But JAXP returned: " + name);
        throw new IllegalStateException("We need Xalan XSLT processor returned from JAXP!");
    }
    try {
        saxParserFactory.setFeature("http://apache.org/xml/features/xinclude/fixup-base-uris", false);
        SAXParser saxParser = saxParserFactory.newSAXParser();
        if (!saxParser.isXIncludeAware()) {
            throw new IllegalStateException("SAXParser returned by JAXP is not XInclude aware!");
        }
    } catch (ParserConfigurationException e) {
        log.error(e.getMessage());
        throw new RuntimeException(e);
    } catch (SAXException e) {
        log.error(e.getMessage());
        throw new RuntimeException(e);
    }
}