List of usage examples for javax.xml.parsers ParserConfigurationException getMessage
public String getMessage()
From source file:com.onet.OnetAuth.java
private void parseUo(String data) { try {/* w w w. ja va2 s . co m*/ Log.i(TAG, "pareUO: " + data); if (data == null) { Messages.getInstance().showMessage(Channels.STATUS, "Bd autoryzacji [Brak odpowiedzi od serwera]"); return; } DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(data))); document.getDocumentElement().normalize(); Node error = document.getElementsByTagName("error").item(0); String err_code = error.getAttributes().getNamedItem("err_code").getNodeValue(); String err_text = error.getAttributes().getNamedItem("err_text").getNodeValue(); if (err_code.equalsIgnoreCase("true")) { String UOKey = document.getElementsByTagName("uoKey").item(0).getTextContent(); String nick = document.getElementsByTagName("zuoUsername").item(0).getTextContent(); if (Network.getInstance().isConnected()) { Settings.getInstance().set("nick", nick); Settings.getInstance().set("uo_key", UOKey); Network.getInstance().send(String.format("AUTHKEY")); } } else { Log.e(TAG, String.format("Authentication error [%s]", err_text)); Messages.getInstance().showMessage(Channels.STATUS, String.format("Bd autoryzacji [%s]", err_text)); } } catch (ParserConfigurationException e) { Log.e(TAG, "Parse XML configuration exception:" + e.getMessage()); e.printStackTrace(); } catch (SAXException e) { Log.e(TAG, "Wrong XML file structure:" + e.getMessage()); e.printStackTrace(); } catch (IOException e) { Log.e(TAG, "Cannot parse XML:" + e.getMessage()); e.printStackTrace(); } }
From source file:de.fzi.ALERT.actor.MessageObserver.ComplexEventObserver.JMSMessageParser.java
public Message XMLFileParse(String msgString) { Message message = new Message(); try {//from www . j a v a 2 s .c om DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setErrorHandler(new MyErrorHandler()); InputStream in = new ByteArrayInputStream(msgString.getBytes("UTF-8")); org.w3c.dom.Document doc = builder.parse(in); XPath xpath = XPathFactory.newInstance().newXPath(); // XPath Query for showing all nodes value javax.xml.xpath.XPathExpression expr = xpath.compile("//patternID/text()"); Object result = expr.evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) result; Pattern pattern = new Pattern(); if (nodes.getLength() > 0) { pattern = patternDAO.findById(nodes.item(0).getNodeValue()); } if (pattern != null) { message.setPatternId(pattern); for (int i = 0; i < nodes.getLength(); i++) { System.out.println(nodes.item(i).getNodeValue()); } javax.xml.xpath.XPathExpression expr1 = xpath.compile("//alertcomplex/*/text()"); Object result1 = expr1.evaluate(doc, XPathConstants.NODESET); NodeList nodes1 = (NodeList) result1; String content = ""; if (nodes.getLength() > 0) { for (int i = 0; i < nodes1.getLength(); i++) { System.out.println("modes " + nodes1.item(i).getParentNode().getNodeName()); System.out.println(nodes1.item(i).getNodeValue()); content += nodes1.item(i).getNodeValue(); } } message.setSubject("complex event"); message.setSummary("default summary"); message.setContent(content); message.setMsgDate(new Date()); message.setMsgID(1); } else { message.setContent("ERROR!"); } } catch (ParserConfigurationException e) { // TODO Auto-generated catch block message.setContent("ERROR!"); System.out.println(e.getMessage()); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block message.setContent("ERROR!"); System.out.println(e.getMessage()); } catch (SAXException e) { // TODO Auto-generated catch block message.setContent("ERROR!"); System.out.println(e.getMessage()); } catch (IOException e) { // TODO Auto-generated catch block message.setContent("ERROR!"); System.out.println(e.getMessage()); } catch (XPathExpressionException e) { // TODO Auto-generated catch block message.setContent("ERROR!"); System.out.println(e.getMessage()); } return message; }
From source file:it.grid.storm.namespace.config.xml.XMLNamespaceLoader.java
private String getNamespaceSchemaFileName() { String schemaName = it.grid.storm.config.Configuration.getInstance().getNamespaceSchemaFilename(); if (schemaName.equals("Schema UNKNOWN!")) { schemaName = "namespace.xsd"; String namespaceFN = getNamespaceFileName(); File namespaceFile = new File(namespaceFN); if (namespaceFile.exists()) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(namespaceFN); Element rootElement = doc.getDocumentElement(); String tagName = rootElement.getTagName(); if (tagName.equals("namespace")) { if (rootElement.hasAttributes()) { String value = rootElement.getAttribute("xsi:noNamespaceSchemaLocation"); if ((value != null) && (value.length() > 0)) { schemaName = value; // log.debug("namespace schema is : " + schemaName); }//from ww w . j av a 2 s . c o m } else { log.error(namespaceFN + " don't have a valid root element attributes"); } } else { log.error(namespaceFN + " don't have a valid root element."); } } catch (ParserConfigurationException e) { log.error("Error while parsing " + namespaceFN + e.getMessage()); } catch (SAXException e) { log.error("Error while parsing " + namespaceFN + e.getMessage()); } catch (IOException e) { log.error("Error while parsing " + namespaceFN + e.getMessage()); } } } return schemaName; }
From source file:com.ecyrd.jspwiki.auth.authorize.XMLGroupDatabase.java
private void buildDOM() throws WikiSecurityException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false);// ww w .j ava 2s . c om factory.setExpandEntityReferences(false); factory.setIgnoringComments(true); factory.setNamespaceAware(false); try { m_dom = factory.newDocumentBuilder().parse(m_file); log.debug("Database successfully initialized"); m_lastModified = m_file.lastModified(); m_lastCheck = System.currentTimeMillis(); } catch (ParserConfigurationException e) { log.error("Configuration error: " + e.getMessage()); } catch (SAXException e) { log.error("SAX error: " + e.getMessage()); } catch (FileNotFoundException e) { log.info("Group database not found; creating from scratch..."); } catch (IOException e) { log.error("IO error: " + e.getMessage()); } if (m_dom == null) { try { // // Create the DOM from scratch // m_dom = factory.newDocumentBuilder().newDocument(); m_dom.appendChild(m_dom.createElement("groups")); } catch (ParserConfigurationException e) { log.fatal("Could not create in-memory DOM"); } } // Ok, now go and read this sucker in if (m_dom != null) { NodeList groupNodes = m_dom.getElementsByTagName(GROUP_TAG); for (int i = 0; i < groupNodes.getLength(); i++) { Element groupNode = (Element) groupNodes.item(i); String groupName = groupNode.getAttribute(GROUP_NAME); if (groupName == null) { log.warn("Detected null group name in XMLGroupDataBase. Check your group database."); } else { Group group = buildGroup(groupNode, groupName); m_groups.put(groupName, group); } } } }
From source file:XMLReader.java
/** Parses XML file and returns XML document. * @param fileName XML file to parse// www.j a v a 2s . co m * @return XML document or <B>null</B> if error occured */ private Document parseFile(String fileName) { System.out.println("Parsing XML file... " + fileName); DocumentBuilder docBuilder; Document doc = null; DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setIgnoringElementContentWhitespace(true); boolean success = true; try { docBuilder = docBuilderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { System.err.println("XMLReader::parseFile - Wrong parser configuration: " + e.getMessage()); success = false; return null; } File sourceFile = new File(fileName); try { doc = docBuilder.parse(sourceFile); } catch (SAXException e) { System.err.println("XMLReader::parseFile - Wrong XML file structure: " + e.getMessage()); success = false; return null; } catch (FileNotFoundException catcher) { System.err.println("AgencyTable::initNames - AgencyInfo.skc not Found: " + catcher.getMessage()); System.out.println("Expected XML file to be in following location: " + System.getProperty("user.dir") + "\\" + fileName + "."); } catch (IOException e) { System.err.println("XMLReader::parseFile - Could not read source file: " + e.getMessage()); success = false; } System.out.println("XML file parsed" + (success ? "" : " - but with errors")); if (!success) { System.out.println("Error reading XML file. Refer to the log file for more information."); } return doc; }
From source file:com.twinsoft.convertigo.engine.util.RemoteAdmin.java
public void deployArchive(File archiveFile, boolean bAssembleXsl) throws RemoteAdminException { String deployServiceURL = (bHttps ? "https" : "http") + "://" + serverBaseUrl + "/admin/services/projects.Deploy?bAssembleXsl=" + bAssembleXsl; PostMethod deployMethod = null;//from www . java 2 s.c o m Protocol myhttps = null; try { if (bHttps && bTrustAllCertificates) { ProtocolSocketFactory socketFactory = MySSLSocketFactory.getSSLSocketFactory(null, null, null, null, true); myhttps = new Protocol("https", socketFactory, serverPort); Protocol.registerProtocol("https", myhttps); hostConfiguration = httpClient.getHostConfiguration(); hostConfiguration.setHost(host, serverPort, myhttps); httpClient.setHostConfiguration(hostConfiguration); } deployMethod = new PostMethod(deployServiceURL); Part[] parts = { new FilePart(archiveFile.getName(), archiveFile) }; deployMethod.setRequestEntity(new MultipartRequestEntity(parts, deployMethod.getParams())); int returnCode = httpClient.executeMethod(deployMethod); String httpResponse = deployMethod.getResponseBodyAsString(); if (returnCode == HttpStatus.SC_OK) { Document domResponse; try { DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); domResponse = parser.parse(new InputSource(new StringReader(httpResponse))); domResponse.normalize(); NodeList nodeList = domResponse.getElementsByTagName("error"); if (nodeList.getLength() != 0) { Element errorNode = (Element) nodeList.item(0); Element errorMessage = (Element) errorNode.getElementsByTagName("message").item(0); Element exceptionName = (Element) errorNode.getElementsByTagName("exception").item(0); Element stackTrace = (Element) errorNode.getElementsByTagName("stacktrace").item(0); if (errorMessage != null) { throw new RemoteAdminException(errorMessage.getTextContent(), exceptionName.getTextContent(), stackTrace.getTextContent()); } else { throw new RemoteAdminException( "An unexpected error has occured during the Convertigo project deployment: \n" + "Body content: \n\n" + XMLUtils.prettyPrintDOMWithEncoding(domResponse, "UTF-8")); } } } catch (ParserConfigurationException e) { throw new RemoteAdminException("Unable to parse the Convertigo server response: \n" + e.getMessage() + ".\n" + "Received response: " + httpResponse); } catch (IOException e) { throw new RemoteAdminException( "An unexpected error has occured during the Convertigo project deployment.\n" + "(IOException) " + e.getMessage() + "\n" + "Received response: " + httpResponse, e); } catch (SAXException e) { throw new RemoteAdminException("Unable to parse the Convertigo server response: " + e.getMessage() + ".\n" + "Received response: " + httpResponse); } } else { decodeResponseError(httpResponse); } } catch (HttpException e) { throw new RemoteAdminException( "An unexpected error has occured during the Convertigo project deployment.\n" + "Cause: " + e.getMessage(), e); } catch (IOException e) { throw new RemoteAdminException( "Unable to reach the Convertigo server: \n" + "(IOException) " + e.getMessage(), e); } catch (Exception e) { throw new RemoteAdminException( "Unable to reach the Convertigo server: \n" + "(Exception) " + e.getMessage(), e); } finally { Protocol.unregisterProtocol("https"); if (deployMethod != null) deployMethod.releaseConnection(); } }
From source file:com.vmware.o11n.plugin.powershell.model.RemotePsType.java
private void initDomDocument() { if (doc == null && xml != null) { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); // domFactory.setNamespaceAware(true); // never forget this! DocumentBuilder builder;// w w w. j ava 2s .c o m try { builder = domFactory.newDocumentBuilder(); doc = builder.parse(IOUtils.toInputStream(xml)); } catch (ParserConfigurationException e) { throw new PowerShellException(e.getMessage(), e); } catch (SAXException e) { throw new PowerShellException(e.getMessage(), e); } catch (IOException e) { throw new PowerShellException(e.getMessage(), e); } xpathFactory = XPathFactory.newInstance(); } }
From source file:com.qcadoo.view.internal.xml.ViewDefinitionParserImpl.java
@Override public Node getRootOfXmlDocument(final Resource xmlFile) { try {/*from w ww . j av a2s .c om*/ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = documentBuilder.parse(xmlFile.getInputStream()); return document.getDocumentElement(); } catch (ParserConfigurationException e) { throw new IllegalStateException(e.getMessage(), e); } catch (SAXException e) { throw new IllegalStateException(e.getMessage(), e); } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); } }
From source file:com.twinsoft.convertigo.engine.util.RemoteAdmin.java
public void login(String username, String password) throws RemoteAdminException, EngineException { PostMethod loginMethod = null;/*from w ww. j a va 2 s . c om*/ try { String loginServiceURL = (bHttps ? "https" : "http") + "://" + serverBaseUrl + "/admin/services/engine.Authenticate"; Protocol myhttps = null; hostConfiguration = httpClient.getHostConfiguration(); if (bHttps) { if (bTrustAllCertificates) { ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory(); myhttps = new Protocol("https", socketFactory, serverPort); Protocol.registerProtocol("https", myhttps); hostConfiguration.setHost(host, serverPort, myhttps); } } if (("").equals(username) || username == null) { throw new RemoteAdminException( "Unable to connect to the Convertigo server: \"Server administrator\" field is empty."); } if (("").equals(password) || password == null) { throw new RemoteAdminException( "Unable to connect to the Convertigo server: \"Password\" field is empty."); } URL url = new URL(loginServiceURL); HttpState httpState = new HttpState(); httpClient.setState(httpState); // Proxy configuration Engine.theApp.proxyManager.setProxy(hostConfiguration, httpState, url); loginMethod = new PostMethod(loginServiceURL); loginMethod.addParameter("authType", "login"); loginMethod.addParameter("authUserName", username); loginMethod.addParameter("authPassword", password); int returnCode = httpClient.executeMethod(loginMethod); String httpResponse = loginMethod.getResponseBodyAsString(); if (returnCode == HttpStatus.SC_OK) { Document domResponse; try { DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); domResponse = parser.parse(new InputSource(new StringReader(httpResponse))); domResponse.normalize(); NodeList nodeList = domResponse.getElementsByTagName("error"); if (nodeList.getLength() != 0) { throw new RemoteAdminException( "Unable to connect to the Convertigo server: wrong username or password."); } } catch (ParserConfigurationException e) { throw new RemoteAdminException("Unable to parse the Convertigo server response: \n" + e.getMessage() + ".\n" + "Received response: " + httpResponse); } catch (IOException e) { throw new RemoteAdminException( "An unexpected error has occured during the Convertigo server login.\n" + "(IOException) " + e.getMessage() + "\n" + "Received response: " + httpResponse, e); } catch (SAXException e) { throw new RemoteAdminException("Unable to parse the Convertigo server response: " + e.getMessage() + ".\n" + "Received response: " + httpResponse); } } else { decodeResponseError(httpResponse); } } catch (HttpException e) { throw new RemoteAdminException("An unexpected error has occured during the Convertigo server login.\n" + "Cause: " + e.getMessage(), e); } catch (UnknownHostException e) { throw new RemoteAdminException( "Unable to find the Convertigo server (unknown host): " + e.getMessage()); } catch (IOException e) { String message = e.getMessage(); if (message.indexOf("unable to find valid certification path") != -1) { throw new RemoteAdminException( "The SSL certificate of the Convertigo server is not trusted.\nPlease check the 'Trust all certificates' checkbox."); } else throw new RemoteAdminException( "Unable to reach the Convertigo server: \n" + "(IOException) " + e.getMessage(), e); } catch (GeneralSecurityException e) { throw new RemoteAdminException( "Unable to reach the Convertigo server: \n" + "(GeneralSecurityException) " + e.getMessage(), e); } finally { Protocol.unregisterProtocol("https"); if (loginMethod != null) loginMethod.releaseConnection(); } }
From source file:com.qcadoo.view.internal.xml.ViewDefinitionParserImpl.java
private InternalViewDefinition parse(final InputStream viewDefinitionInputStream, final String pluginIdentifier) throws ViewDefinitionParserNodeException { try {/*w w w. j a v a 2 s . c o m*/ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = documentBuilder.parse(viewDefinitionInputStream); Node root = document.getDocumentElement(); checkState("view".equals(root.getNodeName()), root, "Wrong root node '" + root.getNodeName() + "'"); return parseViewDefinition(root, pluginIdentifier); } catch (ParserConfigurationException e) { throw new IllegalStateException(e.getMessage(), e); } catch (SAXException e) { throw new IllegalStateException(e.getMessage(), e); } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); } }