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:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.ClinicalDateObscurer.java

/**
 * For the given file parameter, removes all elements with names dayOfPrefix/monthOfPrefix/yearOfPrefix[ELEMENT]
 * where ELEMENT is from the list datesToObscure.  Adds an element with name elapsedElementBase[ELEMENT] with
 * value equal to the number of days from the basis date until the given date.  (So, if the date is before the basis
 * date, the value will be negative.)  If the given date has no day then 1 is used.  If the given date has no month
 * then 1 is used.  If the given date has no year, then the elapsed days element will have no value, because the
 * calculation cannot be done./*from w ww .jav  a  2s .c  om*/
 *
 * @param file the clinical XML file to operate on
 * @param context the context for this QC call
 * @return the original archive (pulled from the context)
 * @throws ProcessorException if an error occurs during the process
 */
@Override
protected Archive processFile(final File file, final QcContext context) throws ProcessorException {

    // only process files that are newly submitted, otherwise are already obscured
    if (!context.getFilesCopiedFromPreviousArchive().contains(file.getName())) {

        try {
            if (getBcrUtils().isClinicalFile(file)) {
                processClinicalFile(file, context);
            } else if (getBcrUtils().isBiospecimenFile(file)) {
                processBiospecimenFile(file, context);
            } else if (getBcrUtils().isAuxiliaryFile(file)) {
                // Do nothing
            } else if (getBcrUtils().isControlFile(file)) {
                // Do nothing
            } else {//Unsupported XML file
                throw new ProcessorException("Unsupported XML file '" + file.getName() + "'");
            }

        } catch (ParserConfigurationException x) {
            throw new ProcessorException(
                    "Parser Configuration error, parsing file " + file.getName() + ": " + x.getMessage());
        } catch (SAXException x) {
            throw new ProcessorException("SAX error, parsing file " + file.getName() + ": " + x.getMessage());
        } catch (IOException x) {
            throw new ProcessorException("I/O error, parsing file " + file.getName() + ": " + x.getMessage());
        } catch (TransformerException x) {
            throw new ProcessorException(
                    "Error while dumping content of DOM Document in file '" + file.getAbsolutePath() + "'", x);
        } catch (NoSuchAlgorithmException e) {
            throw new ProcessorException(e.getMessage());
        }
    }

    return context.getArchive();
}

From source file:eu.eidas.auth.engine.core.stork.StorkExtensionProcessor.java

private XSAny createAttributeValueForSignedDoc(String value) throws EIDASSAMLEngineException {
    Document document;/*from  w w w. ja va  2 s  .c  o  m*/
    // Parse the signedDoc value into an XML DOM Document
    try {
        document = DocumentBuilderFactoryUtil.parse(value);
    } catch (SAXException e1) {
        LOG.info(ProtocolEngine.SAML_EXCHANGE,
                "BUSINESS EXCEPTION : SAX Error while parsing signModule attribute", e1.getMessage());
        LOG.debug(ProtocolEngine.SAML_EXCHANGE,
                "BUSINESS EXCEPTION : SAX Error while parsing signModule attribute", e1);
        throw new EIDASSAMLEngineRuntimeException(e1);
    } catch (ParserConfigurationException e2) {
        LOG.info(ProtocolEngine.SAML_EXCHANGE,
                "BUSINESS EXCEPTION : Parser Configuration Error while parsing signModule attribute",
                e2.getMessage());
        LOG.debug(ProtocolEngine.SAML_EXCHANGE,
                "BUSINESS EXCEPTION : Parser Configuration Error while parsing signModule attribute", e2);
        throw new EIDASSAMLEngineRuntimeException(e2);
    } catch (IOException e4) {
        LOG.info(ProtocolEngine.SAML_EXCHANGE,
                "BUSINESS EXCEPTION : IO Error while parsing signModule attribute", e4.getMessage());
        LOG.debug(ProtocolEngine.SAML_EXCHANGE,
                "BUSINESS EXCEPTION : IO Error while parsing signModule attribute", e4);
        throw new EIDASSAMLEngineRuntimeException(e4);
    }

    // Create the attribute statement
    final XSAny xmlValue = (XSAny) BuilderFactoryUtil.buildXmlObject(AttributeValue.DEFAULT_ELEMENT_NAME,
            XSAny.TYPE_NAME);

    //Set the signedDoc XML content to this element
    xmlValue.setDOM(document.getDocumentElement());

    // Create the attribute statement
    final XSAny attrValue = (XSAny) BuilderFactoryUtil.buildXmlObject(AttributeValue.DEFAULT_ELEMENT_NAME,
            XSAny.TYPE_NAME);

    //Add previous signedDocXML to the AttributeValue Element
    attrValue.getUnknownXMLObjects().add(xmlValue);
    return attrValue;
}

From source file:com.fujitsu.dc.common.auth.token.TransCellAccessToken.java

/**
 * TransCellAccessToken????./*from   ww w  . j av a 2s  .com*/
 * @param token 
 * @return TransCellAccessToken(?)
 * @throws AbstractOAuth2Token.TokenParseException ?
 * @throws AbstractOAuth2Token.TokenDsigException ???
 * @throws AbstractOAuth2Token.TokenRootCrtException CA?
 */
public static TransCellAccessToken parse(final String token) throws AbstractOAuth2Token.TokenParseException,
        AbstractOAuth2Token.TokenDsigException, AbstractOAuth2Token.TokenRootCrtException {
    try {
        byte[] samlBytes = DcCoreUtils.decodeBase64Url(token);
        ByteArrayInputStream bais = new ByteArrayInputStream(samlBytes);
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder builder = null;
        try {
            builder = dbf.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            // ????????????
            throw new RuntimeException(e);
        }

        Document doc = builder.parse(bais);

        Element assertion = doc.getDocumentElement();
        Element issuer = (Element) (doc.getElementsByTagName("Issuer").item(0));
        Element subject = (Element) (assertion.getElementsByTagName("Subject").item(0));
        Element subjectNameID = (Element) (subject.getElementsByTagName("NameID").item(0));
        String id = assertion.getAttribute("ID");
        String issuedAtStr = assertion.getAttribute("IssueInstant");

        DateTime dt = new DateTime(issuedAtStr);

        NodeList audienceList = assertion.getElementsByTagName("Audience");
        Element aud1 = (Element) (audienceList.item(0));
        String target = aud1.getTextContent();
        String schema = null;
        if (audienceList.getLength() > 1) {
            Element aud2 = (Element) (audienceList.item(1));
            schema = aud2.getTextContent();
        }

        List<Role> roles = new ArrayList<Role>();
        NodeList attrList = assertion.getElementsByTagName("AttributeValue");
        for (int i = 0; i < attrList.getLength(); i++) {
            Element attv = (Element) (attrList.item(i));
            roles.add(new Role(new URL(attv.getTextContent())));
        }

        NodeList nl = assertion.getElementsByTagName("Signature");
        if (nl.getLength() == 0) {
            throw new TokenParseException("Cannot find Signature element");
        }
        Element signatureElement = (Element) nl.item(0);

        // ???????TokenDsigException??
        // Create a DOMValidateContext and specify a KeySelector
        // and document context.
        X509KeySelector x509KeySelector = new X509KeySelector(issuer.getTextContent());
        DOMValidateContext valContext = new DOMValidateContext(x509KeySelector, signatureElement);

        // Unmarshal the XMLSignature.
        XMLSignature signature;
        try {
            signature = xmlSignatureFactory.unmarshalXMLSignature(valContext);
        } catch (MarshalException e) {
            throw new TokenDsigException(e.getMessage(), e);
        }

        // CA??
        try {
            x509KeySelector.readRoot(x509RootCertificateFileNames);
        } catch (CertificateException e) {
            // CA????????500
            throw new TokenRootCrtException(e.getMessage(), e);
        }

        // Validate the XMLSignature x509.
        boolean coreValidity;
        try {
            coreValidity = signature.validate(valContext);
        } catch (XMLSignatureException e) {
            if (e.getCause().getClass() == new KeySelectorException().getClass()) {
                throw new TokenDsigException(e.getCause().getMessage(), e.getCause());
            }
            throw new TokenDsigException(e.getMessage(), e);
        }

        // http://www.w3.org/TR/xmldsig-core/#sec-CoreValidation

        // Check core validation status.
        if (!coreValidity) {
            // ??
            boolean isDsigValid;
            try {
                isDsigValid = signature.getSignatureValue().validate(valContext);
            } catch (XMLSignatureException e) {
                throw new TokenDsigException(e.getMessage(), e);
            }
            if (!isDsigValid) {
                throw new TokenDsigException("Failed signature validation");
            }

            // 
            Iterator i = signature.getSignedInfo().getReferences().iterator();
            for (int j = 0; i.hasNext(); j++) {
                boolean refValid;
                try {
                    refValid = ((Reference) i.next()).validate(valContext);
                } catch (XMLSignatureException e) {
                    throw new TokenDsigException(e.getMessage(), e);
                }
                if (!refValid) {
                    throw new TokenDsigException("Failed to validate reference [" + j + "]");
                }
            }
            throw new TokenDsigException("Signature failed core validation. unkwnon reason.");
        }
        return new TransCellAccessToken(id, dt.getMillis(), issuer.getTextContent(),
                subjectNameID.getTextContent(), target, roles, schema);
    } catch (UnsupportedEncodingException e) {
        throw new TokenParseException(e.getMessage(), e);
    } catch (SAXException e) {
        throw new TokenParseException(e.getMessage(), e);
    } catch (IOException e) {
        throw new TokenParseException(e.getMessage(), e);
    }
}

From source file:io.personium.common.auth.token.TransCellAccessToken.java

/**
 * TransCellAccessToken????./*w ww. ja v a  2 s . co m*/
 * @param token 
 * @return TransCellAccessToken(?)
 * @throws AbstractOAuth2Token.TokenParseException ?
 * @throws AbstractOAuth2Token.TokenDsigException ???
 * @throws AbstractOAuth2Token.TokenRootCrtException CA?
 */
public static TransCellAccessToken parse(final String token) throws AbstractOAuth2Token.TokenParseException,
        AbstractOAuth2Token.TokenDsigException, AbstractOAuth2Token.TokenRootCrtException {
    try {
        byte[] samlBytes = PersoniumCoreUtils.decodeBase64Url(token);
        ByteArrayInputStream bais = new ByteArrayInputStream(samlBytes);
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder builder = null;
        try {
            builder = dbf.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            // ????????????
            throw new RuntimeException(e);
        }

        Document doc = builder.parse(bais);

        Element assertion = doc.getDocumentElement();
        Element issuer = (Element) (doc.getElementsByTagName("Issuer").item(0));
        Element subject = (Element) (assertion.getElementsByTagName("Subject").item(0));
        Element subjectNameID = (Element) (subject.getElementsByTagName("NameID").item(0));
        String id = assertion.getAttribute("ID");
        String issuedAtStr = assertion.getAttribute("IssueInstant");

        DateTime dt = new DateTime(issuedAtStr);

        NodeList audienceList = assertion.getElementsByTagName("Audience");
        Element aud1 = (Element) (audienceList.item(0));
        String target = aud1.getTextContent();
        String schema = null;
        if (audienceList.getLength() > 1) {
            Element aud2 = (Element) (audienceList.item(1));
            schema = aud2.getTextContent();
        }

        List<Role> roles = new ArrayList<Role>();
        NodeList attrList = assertion.getElementsByTagName("AttributeValue");
        for (int i = 0; i < attrList.getLength(); i++) {
            Element attv = (Element) (attrList.item(i));
            roles.add(new Role(new URL(attv.getTextContent())));
        }

        NodeList nl = assertion.getElementsByTagName("Signature");
        if (nl.getLength() == 0) {
            throw new TokenParseException("Cannot find Signature element");
        }
        Element signatureElement = (Element) nl.item(0);

        // ???????TokenDsigException??
        // Create a DOMValidateContext and specify a KeySelector
        // and document context.
        X509KeySelector x509KeySelector = new X509KeySelector(issuer.getTextContent());
        DOMValidateContext valContext = new DOMValidateContext(x509KeySelector, signatureElement);

        // Unmarshal the XMLSignature.
        XMLSignature signature;
        try {
            signature = xmlSignatureFactory.unmarshalXMLSignature(valContext);
        } catch (MarshalException e) {
            throw new TokenDsigException(e.getMessage(), e);
        }

        // CA??
        try {
            x509KeySelector.readRoot(x509RootCertificateFileNames);
        } catch (CertificateException e) {
            // CA????????500
            throw new TokenRootCrtException(e.getMessage(), e);
        }

        // Validate the XMLSignature x509.
        boolean coreValidity;
        try {
            coreValidity = signature.validate(valContext);
        } catch (XMLSignatureException e) {
            if (e.getCause().getClass() == new KeySelectorException().getClass()) {
                throw new TokenDsigException(e.getCause().getMessage(), e.getCause());
            }
            throw new TokenDsigException(e.getMessage(), e);
        }

        // http://www.w3.org/TR/xmldsig-core/#sec-CoreValidation

        // Check core validation status.
        if (!coreValidity) {
            // ??
            boolean isDsigValid;
            try {
                isDsigValid = signature.getSignatureValue().validate(valContext);
            } catch (XMLSignatureException e) {
                throw new TokenDsigException(e.getMessage(), e);
            }
            if (!isDsigValid) {
                throw new TokenDsigException("Failed signature validation");
            }

            // 
            Iterator i = signature.getSignedInfo().getReferences().iterator();
            for (int j = 0; i.hasNext(); j++) {
                boolean refValid;
                try {
                    refValid = ((Reference) i.next()).validate(valContext);
                } catch (XMLSignatureException e) {
                    throw new TokenDsigException(e.getMessage(), e);
                }
                if (!refValid) {
                    throw new TokenDsigException("Failed to validate reference [" + j + "]");
                }
            }
            throw new TokenDsigException("Signature failed core validation. unkwnon reason.");
        }
        return new TransCellAccessToken(id, dt.getMillis(), issuer.getTextContent(),
                subjectNameID.getTextContent(), target, roles, schema);
    } catch (UnsupportedEncodingException e) {
        throw new TokenParseException(e.getMessage(), e);
    } catch (SAXException e) {
        throw new TokenParseException(e.getMessage(), e);
    } catch (IOException e) {
        throw new TokenParseException(e.getMessage(), e);
    }
}

From source file:it.imtech.metadata.MetaUtility.java

public void setSessionMetadataFile(String filetoparse, String panelname) {
    try {/*from w  ww  .  java2s  .  c  o m*/
        DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc;

        File f = new File(Globals.BACKUP_METADATA);
        File s = new File(Globals.DUPLICATION_FOLDER_SEP + "session" + panelname);
        FileUtils.copyFile(f, s);

        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();

        File impmetadata = new File(filetoparse);
        doc = dBuilder.parse(impmetadata);

        String expression = "//*[local-name()='contribute']";
        NodeList nodeList = (NodeList) xpath.evaluate(expression, doc, XPathConstants.NODESET);

        for (int i = 0; i < nodeList.getLength() - 1; i++) {
            addContributorToMetadata(panelname);
        }

        expression = "//*[local-name()='taxonpath']";
        nodeList = (NodeList) xpath.evaluate(expression, doc, XPathConstants.NODESET);

        for (int i = 0; i < nodeList.getLength() - 1; i++) {
            addClassificationToMetadata(panelname);
        }
    } catch (ParserConfigurationException ex) {
        logger.error(ex.getMessage());
    } catch (XPathExpressionException ex) {
        logger.error(ex.getMessage());
    } catch (SAXException ex) {
        logger.error(ex.getMessage());
    } catch (IOException ex) {
        logger.error(ex.getMessage());
    }
}

From source file:it.imtech.metadata.MetaUtility.java

private void addContributorToMetadata(String panelname) {
    try {/*from w w w . j  a  va 2 s.  co  m*/
        DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc;

        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        File backupmetadata = new File(Globals.DUPLICATION_FOLDER_SEP + "session" + panelname);
        //File backupmetadata = new File(Globals.SESSION_METADATA);
        doc = dBuilder.parse(backupmetadata);

        String expression = "//*[@ID='11']";
        NodeList nodeList = (NodeList) xpath.evaluate(expression, doc, XPathConstants.NODESET);
        int maxseq = 0;
        int tmpseq = 0;

        for (int i = 0; i < nodeList.getLength(); i++) {
            NamedNodeMap attr = nodeList.item(i).getAttributes();
            Node nodeAttr = attr.getNamedItem("sequence");
            tmpseq = Integer.parseInt(nodeAttr.getNodeValue());

            if (tmpseq > maxseq) {
                maxseq = tmpseq;
            }
        }
        maxseq++;

        Node newNode = nodeList.item(0).cloneNode(true);
        Element nodetocopy = (Element) newNode;
        NamedNodeMap attr = nodeList.item(0).getAttributes();
        Node nodeAttr = attr.getNamedItem("sequence");
        nodeAttr.setTextContent(Integer.toString(maxseq));

        Node copyOfn = doc.importNode(nodetocopy, true);
        nodeList.item(0).getParentNode().appendChild(copyOfn);

        XMLUtil.xmlWriter(doc, Globals.DUPLICATION_FOLDER_SEP + "session" + panelname);
    } catch (ParserConfigurationException ex) {
        logger.error(ex.getMessage());
    } catch (SAXException ex) {
        logger.error(ex.getMessage());
    } catch (IOException ex) {
        logger.error(ex.getMessage());
    } catch (XPathExpressionException ex) {
        logger.error(ex.getMessage());
    }
}

From source file:it.imtech.metadata.MetaUtility.java

public String addClassificationLinkFromid(String id) {
    boolean found = false;
    String link = "";

    if (this.classificationIDS.containsValue(id)) {
        return Utility.getValueFromKey(this.classificationIDS, id);
    } else {// w w w .j  av  a2s .c  o  m
        for (String classificationLink : this.availableClassifications.keySet()) {
            try {
                if (found == false && !classificationIDS.containsKey(classificationLink)) {
                    Document doc = Utility.getDocument(classificationLink, true);
                    XPath taxonpath = XPathFactory.newInstance().newXPath();
                    String expression = "//*[local-name()='classification']";

                    NodeList nodeList = (NodeList) taxonpath.evaluate(expression, doc, XPathConstants.NODESET);

                    for (int i = 0; i < nodeList.getLength(); i++) {
                        Element node = (Element) nodeList.item(i);

                        if (node.getAttribute("ID").equals(id)) {
                            classificationIDS.put(classificationLink, id);
                            link = classificationLink;
                            found = true;
                        } else {
                            classificationIDS.put(classificationLink, id);
                        }
                    }
                }
            } catch (ParserConfigurationException ex) {
                logger.error(ex.getMessage());
            } catch (SAXException ex) {
                logger.error(ex.getMessage());
            } catch (IOException ex) {
                logger.error(ex.getMessage());
            } catch (XPathExpressionException ex) {
                logger.error(ex.getMessage());
            }
        }

        return link;
    }
}

From source file:it.imtech.metadata.MetaUtility.java

private void removeContributorToMetadata(String panelname) {
    try {//ww w. j  a  v  a2s  . c  om
        DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc;

        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        File backupmetadata = new File(Globals.DUPLICATION_FOLDER_SEP + "session" + panelname);
        //File backupmetadata = new File(Globals.SESSION_METADATA);
        doc = dBuilder.parse(backupmetadata);

        String expression = "//*[@ID='11']";
        NodeList nodeList = (NodeList) xpath.evaluate(expression, doc, XPathConstants.NODESET);
        int maxseq = 0;
        int tmpseq = 0;

        for (int i = 0; i < nodeList.getLength(); i++) {
            NamedNodeMap attr = nodeList.item(i).getAttributes();
            Node nodeAttr = attr.getNamedItem("sequence");
            tmpseq = Integer.parseInt(nodeAttr.getNodeValue());

            if (tmpseq > maxseq) {
                maxseq = tmpseq;
            }
        }
        //maxseq++;

        int nLast, idLast, counter = 0;

        for (int i = 0; i < nodeList.getLength(); i++) {
            NamedNodeMap attr = nodeList.item(i).getAttributes();
            Node nodeAttr = attr.getNamedItem("sequence");
            if (maxseq == Integer.parseInt(nodeAttr.getNodeValue())) {
                nLast = counter;
                nodeAttr = attr.getNamedItem("ID");
                idLast = Integer.parseInt(nodeAttr.getNodeValue());
                nodeList.item(i).getParentNode().removeChild(nodeList.item(i));
            }
            counter++;
        }

        XMLUtil.xmlWriter(doc, Globals.DUPLICATION_FOLDER_SEP + "session" + panelname);
    } catch (ParserConfigurationException ex) {
        logger.error(ex.getMessage());
    } catch (SAXException ex) {
        logger.error(ex.getMessage());
    } catch (IOException ex) {
        logger.error(ex.getMessage());
    } catch (XPathExpressionException ex) {
        logger.error(ex.getMessage());
    }
}