List of usage examples for javax.xml.parsers ParserConfigurationException getMessage
public String getMessage()
From source file:org.sead.va.dataone.Object.java
@POST @Path("/{objectId}") @Consumes(MediaType.APPLICATION_XML)//ww w.j a va 2s . co m @Produces(MediaType.APPLICATION_XML) public Response addObject(@Context HttpServletRequest request, @PathParam("objectId") String id, @QueryParam("creators") String creators, @QueryParam("deprecateFgdc") String deprecateFgdc, String fgdcString) throws UnsupportedEncodingException { Document metaInfo = new Document(); metaInfo.put(Constants.META_FORMAT, "http://www.fgdc.gov/schemas/metadata/fgdc-std-001-1998.xsd"); metaInfo.put(Constants.RO_ID, id); org.w3c.dom.Document doc = null; try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); doc = dBuilder.parse(new ByteArrayInputStream(fgdcString.getBytes())); } catch (ParserConfigurationException e) { System.out.println(e.getMessage()); } catch (SAXException e) { System.out.println(e.getMessage()); } catch (IOException e) { System.out.println(e.getMessage()); } String creator = ""; if (creators != null && !creators.equals("")) { creator = URLEncoder.encode(creators.split("\\|")[0].replace(" ", "").replace(",", "")) + "-"; } String fgdcId = "seadva-" + creator + UUID.randomUUID().toString(); metaInfo.put(Constants.FGDC_ID, fgdcId); final byte[] utf8Bytes = fgdcString.getBytes("UTF-8"); metaInfo.put(Constants.SIZE, utf8Bytes.length); String strDate = simpleDateFormat.format(new Date()); metaInfo.put(Constants.META_UPDATE_DATE, strDate); metaInfo.put(Constants.DEPOSIT_DATE, strDate); try { DigestInputStream digestStream = new DigestInputStream(new ByteArrayInputStream(fgdcString.getBytes()), MessageDigest.getInstance("SHA-1")); if (digestStream.read() != -1) { byte[] buf = new byte[1024]; while (digestStream.read(buf) != -1) ; } byte[] digest = digestStream.getMessageDigest().digest(); metaInfo.put(Constants.FIXITY_FORMAT, "SHA-1"); metaInfo.put(Constants.FIXITY_VAL, new String(Hex.encodeHex(digest))); } catch (IOException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } Document document = new Document(); document.put(Constants.META_INFO, metaInfo); document.put(Constants.METADATA, fgdcString); RO_STATUS updated = RO_STATUS.NOT_EXIST; updated = deprecateFGDC(id, document); if (deprecateFgdc != null && !deprecateFgdc.equals("") && updated == RO_STATUS.NOT_EXIST) { updated = deprecateFGDC(deprecateFgdc, document); } if (updated == RO_STATUS.NON_IDENTICAL || updated == RO_STATUS.NOT_EXIST) { fgdcCollection.insertOne(document); } return Response.ok().build(); }
From source file:org.servalproject.maps.indexgenerator.IndexWriter.java
public static boolean writeXmlIndex(File outputFile, ArrayList<MapInfo> mapInfoList) { // create the xml document builder factory object DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); // create the xml document builder object and get the DOMImplementation object DocumentBuilder builder = null; try {// ww w. j a v a 2 s .co m builder = factory.newDocumentBuilder(); } catch (javax.xml.parsers.ParserConfigurationException e) { System.err.println("ERROR: unable to build the XML data. " + e.getMessage()); return false; } DOMImplementation domImpl = builder.getDOMImplementation(); // start to build the document Document document = domImpl.createDocument(null, "maps", null); // get the root element Element rootElement = document.getDocumentElement(); // add the basic metadata Element element = document.createElement("version"); element.setTextContent(VERSION); rootElement.appendChild(element); element = document.createElement("generated"); element.setTextContent(Long.toString(System.currentTimeMillis())); rootElement.appendChild(element); element = document.createElement("author"); element.setTextContent(AUTHOR); rootElement.appendChild(element); element = document.createElement("data_source"); element.setTextContent(DATA_SOURCE); rootElement.appendChild(element); element = document.createElement("data_format"); element.setTextContent(DATA_FORMAT); rootElement.appendChild(element); element = document.createElement("data_format_info"); element.setTextContent(DATA_FORMAT_INFO); rootElement.appendChild(element); element = document.createElement("data_format_version"); element.setTextContent(DATA_FORMAT_VERSION); rootElement.appendChild(element); element = document.createElement("more_info"); element.setTextContent(MORE_INFO); rootElement.appendChild(element); // add the map file information Element mapInfoElement = document.createElement("map-info"); rootElement.appendChild(mapInfoElement); for (MapInfo info : mapInfoList) { mapInfoElement.appendChild(info.toXml(document.createElement("map"))); } // output the xml try { // create a transformer TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); // set some options on the transformer transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); // get a transformer and supporting classes StreamResult result = new StreamResult(new PrintWriter(outputFile)); DOMSource source = new DOMSource(document); // transform the internal objects into XML and print it transformer.transform(source, result); } catch (javax.xml.transform.TransformerException e) { System.err.println("ERROR: unable to write the XML data. " + e.getMessage()); return false; } catch (FileNotFoundException e) { System.err.println("ERROR: unable to write the XML data. " + e.getMessage()); return false; } return true; }
From source file:org.springframework.oxm.support.AbstractMarshaller.java
/** * Build a new {@link Document} from this marshaller's {@link DocumentBuilderFactory}, * as a placeholder for a DOM node./*from www .j a v a 2 s . co m*/ * @see #createDocumentBuilderFactory() * @see #createDocumentBuilder(DocumentBuilderFactory) */ protected Document buildDocument() { try { DocumentBuilder documentBuilder; synchronized (this.documentBuilderFactoryMonitor) { if (this.documentBuilderFactory == null) { this.documentBuilderFactory = createDocumentBuilderFactory(); } documentBuilder = createDocumentBuilder(this.documentBuilderFactory); } return documentBuilder.newDocument(); } catch (ParserConfigurationException ex) { throw new UnmarshallingFailureException("Could not create document placeholder: " + ex.getMessage(), ex); } }
From source file:org.talend.mdm.webapp.browserecords.server.util.CommonUtil.java
public static Document getSubXML(TypeModel typeModel, String realType, Map<String, List<String>> map, String language) throws ServiceException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try {/* w w w. j av a2s . com*/ DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.newDocument(); List<Element> list = _getDefaultXML(typeModel, null, realType, doc, map, language); Element root = list.get(0); root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); //$NON-NLS-1$//$NON-NLS-2$ doc.appendChild(root); return doc; } catch (ParserConfigurationException e) { LOG.error(e.getMessage(), e); throw new ServiceException(e.getMessage()); } }
From source file:org.unitedinternet.cosmo.calendar.hcalendar.HCalendarParser.java
/** * Parse.//w w w. ja v a2s .c o m * @param in The input source. * @param handler The content handler. * @throws IOException - if something is wrong this exception is thrown. * @throws ParserException - if something is wrong this exception is thrown. */ private void parse(InputSource in, ContentHandler handler) throws IOException, ParserException { try { Document d = BUILDER_FACTORY.newDocumentBuilder().parse(in); buildCalendar(d, handler); } catch (ParserConfigurationException e) { throw new CosmoParseException(e); } catch (SAXException e) { if (e instanceof SAXParseException) { SAXParseException pe = (SAXParseException) e; throw new ParserException("Could not parse XML", pe.getLineNumber(), e); } throw new ParserException(e.getMessage(), -1, e); } }
From source file:org.webical.plugin.xml.PluginManifestReader.java
/** * @param pluginManifest the manifest to unMarshall * @return a Plugin//from www .j a v a 2 s. c o m * @throws PluginException with wrapped exception */ public Plugin parsePluginManifest(File pluginManifest) throws PluginException { if (pluginManifest == null) { log.error("Null reference passed for pluginManifest file"); return null; } if (!pluginManifest.exists()) { log.error("File: " + pluginManifest.getAbsolutePath() + " does not excist"); throw new PluginException("File: " + pluginManifest.getAbsolutePath() + " does not excist"); } Document document = null; try { document = validatePluginManifest(pluginManifest); } catch (ParserConfigurationException exception) { log.error("Exception while configuring parser", exception); throw new PluginException("File: " + pluginManifest.getAbsolutePath() + " does not excist", exception); } catch (SAXException exception) { log.error("File: " + pluginManifest.getAbsolutePath() + " is not valid: " + exception.getMessage(), exception); throw new PluginException( "File: " + pluginManifest.getAbsolutePath() + " is not valid: " + exception.getMessage(), exception); } catch (IOException exception) { log.error("File: " + pluginManifest.getAbsolutePath() + " could not be read", exception); throw new PluginException("File: " + pluginManifest.getAbsolutePath() + " could not be read", exception); } try { return unMarshall(document); } catch (JAXBException e) { log.error(e, e); throw new PluginException( "Could not unmarshall the plugin manifest for file: " + pluginManifest.getName(), e); } }
From source file:org.wso2.carbon.humantask.core.utils.DOMUtils.java
private static DocumentBuilder getBuilder() { DocumentBuilder builder = builders.get(); if (builder == null) { synchronized (documentBuilderFactory) { try { builder = documentBuilderFactory.newDocumentBuilder(); builder.setErrorHandler(new SAXLoggingErrorHandler()); } catch (ParserConfigurationException e) { log.error(e.getMessage(), e); throw new RuntimeException(e); }//from w w w.j av a 2 s . c o m } builders.set(builder); } return builder; }
From source file:org.wso2.carbon.identity.user.store.configuration.UserStoreConfigAdminService.java
/** * Update a domain to be disabled/enabled * * @param domain: Name of the domain to be updated * @param isDisable : Whether to disable/enable domain(true/false) *///from w ww .j av a 2 s .c o m public void changeUserStoreState(String domain, Boolean isDisable) throws IdentityUserStoreMgtException { File userStoreConfigFile = createConfigurationFile(domain); StreamResult result = new StreamResult(userStoreConfigFile); if (!userStoreConfigFile.exists()) { String errorMessage = "Cannot edit user store." + domain + " does not exist."; throw new IdentityUserStoreMgtException(errorMessage); } DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = null; try { documentBuilder = documentFactory.newDocumentBuilder(); Document doc = documentBuilder.parse(userStoreConfigFile); NodeList elements = doc.getElementsByTagName("Property"); for (int i = 0; i < elements.getLength(); i++) { //Assumes a property element only have attribute 'name' if ("Disabled".compareToIgnoreCase(elements.item(i).getAttributes().item(0).getNodeValue()) == 0) { elements.item(i).setTextContent(String.valueOf(isDisable)); break; } } DOMSource source = new DOMSource(doc); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "6"); transformer.transform(source, result); if (log.isDebugEnabled()) { log.debug("New state :" + isDisable + " of the user store \'" + domain + "\' successfully written to the file system"); } } catch (ParserConfigurationException e) { log.error(e.getMessage(), e); throw new IdentityUserStoreMgtException("Error while updating user store state", e); } catch (SAXException e) { log.error(e.getMessage(), e); throw new IdentityUserStoreMgtException("Error while updating user store state", e); } catch (TransformerConfigurationException e) { log.error(e.getMessage(), e); throw new IdentityUserStoreMgtException("Error while updating user store state", e); } catch (TransformerException e) { log.error(e.getMessage(), e); throw new IdentityUserStoreMgtException("Error while updating user store state", e); } catch (IOException e) { log.error(e.getMessage(), e); throw new IdentityUserStoreMgtException("Error while updating user store state", e); } }
From source file:org.wso2.carbon.mediator.datamapper.engine.input.readers.XMLReader.java
@Override public void read(InputStream input, InputModelBuilder inputModelBuilder, Schema inputSchema) throws ReaderException { this.modelBuilder = inputModelBuilder; this.inputSchema = inputSchema; SAXParserFactory factory = SAXParserFactory.newInstance(); try {/* w w w .j a v a 2 s . c o m*/ SAXParser parser = factory.newSAXParser(); org.xml.sax.XMLReader xmlReader = parser.getXMLReader(); xmlReader.setContentHandler(this); xmlReader.setDTDHandler(this); xmlReader.setEntityResolver(this); xmlReader.setFeature(HTTP_XML_ORG_SAX_FEATURES_NAMESPACES, true); xmlReader.setFeature(HTTP_XML_ORG_SAX_FEATURES_NAMESPACE_PREFIXES, true); xmlReader.parse(new InputSource(input)); } catch (ParserConfigurationException e) { throw new ReaderException("ParserConfig error. " + e.getMessage()); } catch (SAXException e) { throw new ReaderException("XML not well-formed. " + e.getMessage()); } catch (IOException e) { throw new ReaderException("IO Error while parsing xml input stream. " + e.getMessage()); } }
From source file:org.wso2.carbon.sample.tfl.traffic.TrafficPollingTask.java
public void run() { try {/*from w w w.j av a 2 s . c o m*/ URL obj = new URL(streamURL); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); ArrayList<Disruption> disruptionsList = new ArrayList<Disruption>(); try { // optional default is GET con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); log.info("Sending 'GET' request to URL : " + streamURL); log.info("Response Code : " + responseCode); double t = System.currentTimeMillis(); // Get SAX Parser Factory SAXParserFactory factory = SAXParserFactory.newInstance(); // Turn on validation, and turn off namespaces factory.setValidating(true); factory.setNamespaceAware(false); SAXParser parser = factory.newSAXParser(); parser.parse(con.getInputStream(), new TrafficXMLHandler(disruptionsList)); log.info("Number of Disruptions added to the list: " + disruptionsList.size()); log.info("Time taken for parsing: " + (System.currentTimeMillis() - t)); } catch (ParserConfigurationException e) { log.info("The underlying parser does not support " + " the requested features."); } catch (FactoryConfigurationError e) { log.info("Error occurred obtaining SAX Parser Factory."); } catch (Exception e) { e.printStackTrace(); } finally { con.disconnect(); } ArrayList<String> list = new ArrayList<String>(); int count = 0; for (Disruption disruption : disruptionsList) { if (disruption.getState().contains("Active")) { list.add(disruption.toJson()); } count++; } TflStream.writeToFile("tfl-traffic-data.out", list, true); } catch (IOException e) { log.error("Error occurred while getting traffic data: " + e.getMessage(), e); } }