List of usage examples for javax.xml.parsers ParserConfigurationException getMessage
public String getMessage()
From source file:com.connectutb.xfuel.FuelPlanner.java
public Document parseFuelResponse(String response) { /** Need to modify the response string to fix malformed XML **/ //* Split our string on newlines String[] response_array = response.split("(\\n)"); //Loop through string array String fixed_response = ""; for (int n = 0; n < response_array.length - 1; n++) { if (n == 1) { //Add a ROOT element <DATA> fixed_response += "<DATA>" + System.getProperty("line.separator"); }/*from ww w . j ava 2 s. c o m*/ if (response_array[n].startsWith("<MESSAGES>") || response_array[n].startsWith("</MESSAGES>")) { //Remove <Messages> tag } else { fixed_response += response_array[n] + System.getProperty("line.separator"); } } //Close the </DATA> tag fixed_response += "</DATA>" + System.getProperty("line.separator"); //Close the XML tag if necessary if (fixed_response.contains("</xml>") == false) { fixed_response += "</XML>" + System.getProperty("line.separator"); } Log.d(TAG, fixed_response); //Parse the response string and set values //Parse XML Response Document doc = null; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(fixed_response)); doc = db.parse(is); } catch (ParserConfigurationException e) { Log.e(TAG, e.getMessage()); return null; } catch (SAXException e) { Log.e(TAG, e.getMessage()); return null; } catch (IOException e) { Log.e(TAG, e.getMessage()); return null; } // return DOM Log.d(TAG, "XML parsing completed successfully"); return doc; }
From source file:fr.paris.lutece.plugins.dila.modules.solr.utils.parsers.DilaSolrLocalParser.java
/** * Initializes and launches the parsing of the local cards (public * constructor)/*from w w w .j av a 2 s. c o m*/ */ public DilaSolrLocalParser() { // Gets the local cards List<LocalDTO> localCardsList = _dilaLocalService.findAll(); // Initializes the SolrItem list _listSolrItems = new ArrayList<SolrItem>(); // Initializes the indexing type _strType = AppPropertiesService.getProperty(PROPERTY_INDEXING_TYPE); // Initializes the site _strSite = SolrIndexerService.getWebAppName(); // Initializes the prod url _strProdUrl = SolrIndexerService.getBaseUrl(); try { // Initializes the SAX parser SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); // Launches the parsing on each local card parseAllLocalCards(localCardsList, parser); } catch (ParserConfigurationException e) { AppLogService.error(e.getMessage(), e); } catch (SAXException e) { AppLogService.error(e.getMessage(), e); } }
From source file:eu.eidas.auth.engine.SAMLEngineUtils.java
private static void parseSignedDoc(List<XMLObject> attributeValues, String nameSpace, String prefix, String value) {// w w w . j ava2s . c o m DocumentBuilderFactory domFactory = EIDASSAMLEngine.newDocumentBuilderFactory(); domFactory.setNamespaceAware(true); Document document = null; DocumentBuilder builder; // Parse the signedDoc value into an XML DOM Document try { builder = domFactory.newDocumentBuilder(); InputStream is; is = new ByteArrayInputStream(value.trim().getBytes("UTF-8")); document = builder.parse(is); is.close(); } catch (SAXException e1) { LOG.info("ERROR : SAX Error while parsing signModule attribute", e1.getMessage()); LOG.debug("ERROR : SAX Error while parsing signModule attribute", e1); throw new EIDASSAMLEngineRuntimeException(e1); } catch (ParserConfigurationException e2) { LOG.info("ERROR : Parser Configuration Error while parsing signModule attribute", e2.getMessage()); LOG.debug("ERROR : Parser Configuration Error while parsing signModule attribute", e2); throw new EIDASSAMLEngineRuntimeException(e2); } catch (UnsupportedEncodingException e3) { LOG.info("ERROR : Unsupported encoding Error while parsing signModule attribute", e3.getMessage()); LOG.debug("ERROR : Unsupported encoding Error while parsing signModule attribute", e3); throw new EIDASSAMLEngineRuntimeException(e3); } catch (IOException e4) { LOG.info("ERROR : IO Error while parsing signModule attribute", e4.getMessage()); LOG.debug("ERROR : IO Error while parsing signModule attribute", e4); throw new EIDASSAMLEngineRuntimeException(e4); } // Create the XML statement(this will be overwritten with the previous DOM structure) final XSAny xmlValue = (XSAny) SAMLEngineUtils.createSamlObject(new QName(nameSpace, "XMLValue", prefix), XSAny.TYPE_NAME); //Set the signedDoc XML content to this element xmlValue.setDOM(document.getDocumentElement()); // Create the attribute statement final XSAny attrValue = (XSAny) SAMLEngineUtils .createSamlObject(new QName(nameSpace, "AttributeValue", prefix), XSAny.TYPE_NAME); //Add previous signedDocXML to the AttributeValue Element attrValue.getUnknownXMLObjects().add(xmlValue); attributeValues.add(attrValue); }
From source file:com.aurel.track.lucene.util.openOffice.OOIndexer.java
/** * Get the string content of an xml file *//* w ww . j a v a 2s .com*/ public String parseXML(File file) { Document document = null; DocumentBuilderFactory documentBuilderfactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = null; try { builder = documentBuilderfactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { LOGGER.info("Building the document builder from factory failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); return null; } try { document = builder.parse(file); } catch (SAXException e) { LOGGER.info("Parsing the XML document " + file.getPath() + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } catch (IOException e) { LOGGER.info("Reading the XML document " + file.getPath() + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } if (document == null) { return null; } StringWriter result = new StringWriter(); Transformer transformer = null; try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); } catch (TransformerConfigurationException e) { LOGGER.warn( "Creating the transformer failed with TransformerConfigurationException: " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); return null; } try { transformer.transform(new DOMSource(document), new StreamResult(result)); } catch (TransformerException e) { LOGGER.warn("Transform failed with TransformerException: " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } return result.getBuffer().toString(); }
From source file:com.aurel.track.exchange.docx.importer.HTMLParser.java
private void parse(ByteArrayOutputStream byteArrayOutputStream, Locale locale) { localizedHeading = "berschrift";//LocalizeUtil.getLocalizedTextFromApplicationResources(HEADING_KEY, locale); SAXParserFactory spf = SAXParserFactory.newInstance(); Reader fileReader = null;/*from ww w . j a v a 2s. com*/ try { fileReader = new FileReader(new File("d:/docx/PN164_SC_Track.docx.html")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block LOGGER.error(ExceptionUtils.getStackTrace(e)); } try { //get a new instance of parser SAXParser sp = spf.newSAXParser(); //InputSource is=new InputSource(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); InputSource is = new InputSource(fileReader); sp.parse(is, this); } catch (SAXException se) { LOGGER.error("Parsing failed with " + se.getMessage()); if (LOGGER.isDebugEnabled()) { LOGGER.error(ExceptionUtils.getStackTrace(se)); } } catch (ParserConfigurationException pce) { LOGGER.error("Parsing failed with " + pce.getMessage()); if (LOGGER.isDebugEnabled()) { LOGGER.error(ExceptionUtils.getStackTrace(pce)); } } catch (IOException ie) { LOGGER.error("Reading failed with " + ie.getMessage()); LOGGER.error(ExceptionUtils.getStackTrace(ie)); } }
From source file:com.mhise.util.MHISEUtil.java
public final static Document XMLfromString(String xml) { Document doc = null;/*from w w w . j a v a 2 s .co m*/ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xml)); doc = db.parse(is); } catch (ParserConfigurationException e) { System.out.println("XML parse error: " + e.getMessage()); Logger.debug("MHISEUtil-->XMLfromString -->", "" + e); return null; } catch (SAXException e) { System.out.println("Wrong XML file structure: " + e.getMessage()); Logger.debug("MHISEUtil-->XMLfromString -->", "" + e); return null; } catch (IOException e) { System.out.println("I/O exeption: " + e.getMessage()); Logger.debug("MHISEUtil-->XMLfromString -->", "" + e); return null; } return doc; }
From source file:net.sourceforge.fenixedu.presentationTier.servlets.filters.ProcessCandidacyPrintAllDocumentsFilter.java
@Override public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException { arg2.doFilter(arg0, arg1);/*from w w w .j a va2s . 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())); // 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:com.aurel.track.exchange.docx.importer.HTMLParser.java
private void parse(String fileName, Locale locale) { //get a factory localizedHeading = "berschrift";//LocalizeUtil.getLocalizedTextFromApplicationResources(HEADING_KEY, locale); SAXParserFactory spf = SAXParserFactory.newInstance(); try {// w w w . j av a 2 s.c om //get a new instance of parser SAXParser sp = spf.newSAXParser(); //spf.setValidating(true); XMLReader xmlReader = sp.getXMLReader(); xmlReader.setErrorHandler(new MyErrorHandler(System.err)); xmlReader.setContentHandler(this); //parse the file and also register this class for call backs //InputSource is=new InputSource(new StringReader(xml)); xmlReader.parse(convertToFileURL(fileName)); } catch (SAXException se) { LOGGER.error("Parsing the file " + fileName + " failed with " + se.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(se)); } catch (ParserConfigurationException pce) { LOGGER.error("Parsing the file " + fileName + " failed with " + pce.getMessage()); if (LOGGER.isDebugEnabled()) { LOGGER.error(ExceptionUtils.getStackTrace(pce)); } } catch (IOException ie) { LOGGER.error("Reading the file " + fileName + " failed with " + ie.getMessage()); LOGGER.error(ExceptionUtils.getStackTrace(ie)); } }
From source file:fr.paris.lutece.plugins.dila.modules.solr.utils.parsers.DilaSolrPublicParser.java
/** * Initializes and launches the parsing of the public cards (public * constructor)/*from www. j a v a 2 s .com*/ */ public DilaSolrPublicParser() { // Gets the list of CDC index keys String strIndexKeys = AppPropertiesService .getProperty(PROPERTY_INDEXING_FRAGMENT + PROPERTY_LIST_INDEX_KEYS_FRAGMENT); // Initializes the Solr Item list _listSolrItems = new ArrayList<SolrItem>(); // Initializes the indexing type _strType = AppPropertiesService.getProperty(PROPERTY_INDEXING_TYPE); // Initializes the site _strSite = AppPropertiesService.getProperty(PROPERTY_SITE); // Initializes the prod url _strProdUrl = SolrIndexerService.getBaseUrl(); try { // Initializes the SAX parser SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); // Splits the list of CDC index keys String[] splitKeys = strIndexKeys.split(","); for (int i = 0; i < splitKeys.length; i++) { // Gets the XML index file path String strXmlDirectory = AppPropertiesService .getProperty(splitKeys[i] + STRING_POINT + PROPERTY_INDEXING_XML_BASE_VAR); File xmlPath = new File(strXmlDirectory); // Launches the parsing of all files in this directory parseAllPublicCards(xmlPath, parser); } } catch (ParserConfigurationException e) { AppLogService.error(e.getMessage(), e); } catch (SAXException e) { AppLogService.error(e.getMessage(), e); } }
From source file:com.google.enterprise.adaptor.experimental.Sim.java
private void processMultipartPost(HttpExchange ex) throws IOException { InputStream inStream = ex.getRequestBody(); String encoding = ex.getRequestHeaders().getFirst("Content-encoding"); if (null != encoding && "gzip".equals(encoding.toLowerCase())) { inStream = new GZIPInputStream(inStream); }//from w w w . j a va 2s . c o m String lens = ex.getRequestHeaders().getFirst("Content-Length"); long len = (null != lens) ? Long.parseLong(lens) : 0; String ct = ex.getRequestHeaders().getFirst("Content-Type"); try { String xml = extractFeedFromMultipartPost(inStream, len, ct); processXml(xml); respond(ex, HttpURLConnection.HTTP_OK, "text/plain", "Success".getBytes(UTF8)); } catch (NoXmlFound nox) { log.warning("failed to find xml"); respond(ex, HttpURLConnection.HTTP_BAD_REQUEST, "text/plain", "xml beginning not found".getBytes(UTF8)); } catch (SAXException saxe) { log.warning("sax error: " + saxe.getMessage()); respond(ex, HttpURLConnection.HTTP_BAD_REQUEST, "text/plain", "sax not liking the xml".getBytes(UTF8)); } catch (ParserConfigurationException confige) { log.warning("parser error: " + confige.getMessage()); respond(ex, HttpURLConnection.HTTP_BAD_REQUEST, "text/plain", "parser error".getBytes(UTF8)); } catch (BadFeed bad) { log.warning("error in feed: " + bad.getMessage()); respond(ex, HttpURLConnection.HTTP_BAD_REQUEST, "text/plain", bad.getMessage().getBytes(UTF8)); } }