List of usage examples for org.xml.sax SAXException toString
public String toString()
From source file:com.example.apis.ifashion.WOEIDUtils.java
private Document convertStringToDocument(Context context, String src) { YahooWeatherLog.d("convert string to document"); Document dest = null;/*from ww w . jav a 2 s.co m*/ DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser; try { parser = dbFactory.newDocumentBuilder(); dest = parser.parse(new ByteArrayInputStream(src.getBytes())); } catch (ParserConfigurationException e1) { e1.printStackTrace(); Toast.makeText(context, e1.toString(), Toast.LENGTH_LONG).show(); } catch (SAXException e) { e.printStackTrace(); Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show(); } return dest; }
From source file:info.androidhive.androidsplashscreentimer.WOEIDUtils.java
private Document convertStringToDocument(Context context, String src) { MyLog.d("convert string to document"); Document dest = null;//from w ww . j a v a 2s . com DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser; try { parser = dbFactory.newDocumentBuilder(); dest = parser.parse(new ByteArrayInputStream(src.getBytes())); } catch (ParserConfigurationException e1) { e1.printStackTrace(); Toast.makeText(context, e1.toString(), Toast.LENGTH_LONG).show(); } catch (SAXException e) { e.printStackTrace(); Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show(); } return dest; }
From source file:de.badw.strauss.glyphpicker.controller.alltab.TeiLoadWorker.java
/** * Triggers parsing of the XML input stream. * * @param is the input stream/*w ww . j a v a 2 s . c o m*/ * @return the resulting GlyphDefinition list */ public List<GlyphDefinition> parseXmlSax(InputStream is) { TeiXmlHandler handler = new TeiXmlHandler(dataSource); try { parser.parse(is, handler); handler.resolveReferences(); return handler.getGlyphDefinitions(); } catch (SAXException e) { JOptionPane.showMessageDialog(null, e.toString(), i18n.getString("TeiLoadWorker.xmlParsingError"), JOptionPane.ERROR_MESSAGE); } catch (IOException e) { JOptionPane.showMessageDialog(null, e.toString(), i18n.getString("TeiLoadWorker.xmlParsingError"), JOptionPane.ERROR_MESSAGE); } catch (TeiXmlHandler.RecursionException e) { JOptionPane.showMessageDialog(null, e.getMessage(), i18n.getString("TeiLoadWorker.xmlParsingError"), JOptionPane.ERROR_MESSAGE); } return null; }
From source file:com.netflix.ice.login.saml.Saml.java
public LoginResponse processLogin(HttpServletRequest request) throws LoginMethodException { IceSession iceSession = new IceSession(request.getSession()); iceSession.voidSession(); //a second login request voids anything previous logger.info("Saml::processLogin"); LoginResponse lr = new LoginResponse(); String assertion = (String) request.getParameter("SAMLResponse"); if (assertion == null) { lr.redirectTo = config.singleSignOnUrl; return lr; }/* www .j ava 2s .c om*/ logger.trace("Received SAML Assertion: " + assertion); try { // 1.1 2.0 schemas Schema schema = SAMLSchemaBuilder.getSAML11Schema(); //get parser pool manager BasicParserPool parserPoolManager = new BasicParserPool(); parserPoolManager.setNamespaceAware(true); parserPoolManager.setIgnoreElementContentWhitespace(true); parserPoolManager.setSchema(schema); String data = new String(Base64.decode(assertion)); logger.info("Decoded SAML Assertion: " + data); StringReader reader = new StringReader(data); Document document = parserPoolManager.parse(reader); Element documentRoot = document.getDocumentElement(); QName qName = new QName(documentRoot.getNamespaceURI(), documentRoot.getLocalName(), documentRoot.getPrefix()); //get an unmarshaller Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(documentRoot); //unmarshall using the document root element XMLObject xmlObj = unmarshaller.unmarshall(documentRoot); Response response = (Response) xmlObj; for (Assertion myAssertion : response.getAssertions()) { if (!myAssertion.isSigned()) { logger.error("SAML Assertion not signed"); throw new LoginMethodException("SAML Assertions must be signed by a trusted provider"); } Signature assertionSignature = myAssertion.getSignature(); SAMLSignatureProfileValidator profVal = new SAMLSignatureProfileValidator(); logger.info("Validating SAML Assertion"); // will throw a ValidationException profVal.validate(assertionSignature); //Credential signCred = assertionSignature.getSigningCredential(); boolean goodSignature = false; for (Certificate trustedCert : trustedSigningCerts) { BasicCredential cred = new BasicCredential(); cred.setPublicKey(trustedCert.getPublicKey()); SignatureValidator validator = new SignatureValidator(cred); try { validator.validate(assertionSignature); } catch (ValidationException ve) { /* Not a good key! */ logger.debug("Not signed by " + trustedCert.toString()); continue; } logger.info("Assertion trusted from " + trustedCert.toString()); processAssertion(iceSession, myAssertion, lr); goodSignature = true; break; } if (goodSignature) { lr.loginSuccess = true; } } } catch (org.xml.sax.SAXException saxe) { logger.error(saxe.toString()); } catch (org.opensaml.xml.parse.XMLParserException xmlpe) { logger.error(xmlpe.toString()); } catch (org.opensaml.xml.io.UnmarshallingException uee) { logger.error(uee.toString()); } catch (org.opensaml.xml.validation.ValidationException ve) { throw new LoginMethodException("SAML Assertion Signature was not usable: " + ve.toString()); } return lr; }
From source file:net.ontopia.topicmaps.db2tm.RelationMapping.java
public static RelationMapping read(InputStream istream, File basedir) throws IOException { // Create new parser object XMLReader parser;/*from w w w . j ava2 s. c o m*/ try { parser = new DefaultXMLReaderFactory().createXMLReader(); } catch (SAXException e) { throw new IOException("Problems occurred when creating SAX2 XMLReader: " + e.getMessage()); } // Create content handler RelationMapping mapping = new RelationMapping(); mapping.setBaseDirectory(basedir); ContentHandler vhandler = new ValidatingContentHandler(mapping, getRelaxNGSchema(), true); parser.setContentHandler(vhandler); try { // Parse input source parser.parse(new InputSource(istream)); } catch (FileNotFoundException e) { log.error("Resource not found: {}", e.getMessage()); throw e; } catch (SAXParseException e) { throw new OntopiaRuntimeException("XML parsing problem: " + e.toString() + " at: " + e.getSystemId() + ":" + e.getLineNumber() + ":" + e.getColumnNumber(), e); } catch (SAXException e) { if (e.getException() instanceof IOException) throw (IOException) e.getException(); throw new OntopiaRuntimeException(e); } // Compile mapping mapping.compile(); return mapping; }
From source file:com.example.apis.ifashion.YahooWeather.java
private Document convertStringToDocument(Context context, String src) { Document dest = null;// ww w . j a v a 2 s . co m DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser; try { parser = dbFactory.newDocumentBuilder(); dest = parser.parse(new ByteArrayInputStream(src.getBytes())); } catch (ParserConfigurationException e1) { e1.printStackTrace(); Toast.makeText(context, e1.toString(), Toast.LENGTH_LONG).show(); } catch (SAXException e) { e.printStackTrace(); Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show(); } return dest; }
From source file:com.centeractive.ws.builder.soap.XmlUtils.java
static synchronized public Document parse(InputSource inputSource) throws IOException { try {/*from w w w .j a v a 2s .co m*/ return ensureDocumentBuilder().parse(inputSource); } catch (SAXException e) { throw new IOException(e.toString()); } }
From source file:com.frostwire.gui.updates.UpdateMessageReader.java
public void readUpdateFile() { HttpURLConnection connection = null; InputSource src = null;//ww w. j av a2s.co m try { String userAgent = "FrostWire/" + OSUtils.getOS() + "-" + OSUtils.getArchitecture() + "/" + FrostWireUtils.getFrostWireVersion(); connection = (HttpURLConnection) (new URL(getUpdateURL())).openConnection(); String url = getUpdateURL(); System.out.println("Reading update file from " + url); connection.setRequestProperty("User-Agent", userAgent); connection.setRequestProperty("Connection", "close"); connection.setReadTimeout(10000); // 10 secs timeout if (connection.getResponseCode() >= 400) { // invalid URL for sure connection.disconnect(); return; } src = new InputSource(connection.getInputStream()); XMLReader rdr = XMLReaderFactory .createXMLReader("com.sun.org.apache.xerces.internal.parsers.SAXParser"); rdr.setContentHandler(this); rdr.parse(src); connection.getInputStream().close(); connection.disconnect(); } catch (java.net.SocketTimeoutException e3) { System.out.println("UpdateMessageReadre.readUpdateFile() Socket Timeout Exeception " + e3.toString()); } catch (IOException e) { System.out.println("UpdateMessageReader.readUpdateFile() IO exception " + e.toString()); } catch (SAXException e2) { System.out.println("UpdateMessageReader.readUpdateFile() SAX exception " + e2.toString()); } }
From source file:com.cloudera.recordbreaker.analyzer.XMLSchemaDescriptor.java
void computeSchema() throws IOException { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = null;/*from ww w.j a v a 2 s . c o m*/ // Unfortunately, validation is often not possible factory.setValidating(false); try { // The XMLProcessor builds up a tree of tags XMLProcessor xp = new XMLProcessor(); parser = factory.newSAXParser(); parser.parse(dd.getRawBytes(), xp); // Grab the root tag this.rootTag = xp.getRoot(); // Once the tree is built, we: // a) Find the correct repetition node (and throws out 'bad' repeats) // b) Flatten hierarchies of subfields into a single layer, so it's suitable // for relational-style handling // c) Build an overall schema object that can summarize every expected // object, even if the objects' individual schemas differ somewhat this.rootTag.completeTree(); } catch (SAXException saxe) { throw new IOException(saxe.toString()); } catch (ParserConfigurationException pcee) { throw new IOException(pcee.toString()); } }
From source file:biz.taoconsulting.oxf.processor.converter.FromPdfConverter.java
/** * processBookmark gets called recursively for all nested bookmarks extracts * the bookmark and the text//from w ww .jav a2 s .c o m */ private void processBookmark(ContentHandler hd, PDDocument doc, PDOutlineItem curItem, String scope, int level) { // First we check on what page the bookmark is. If we can't retrieve the // page the bookmark can't be the outline we are looking for, however we // would process children (you never know) try { int curPageNo = getPageNumber(doc, curItem); if (curPageNo > -1) { AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", ATT_LEVEL, ATT_LEVEL, ATT_CDATA, Integer.toString(level)); atts.addAttribute("", ATT_PAGE, ATT_PAGE, ATT_CDATA, Integer.toString(curPageNo)); hd.startElement("", TAG_BOOKMARK, TAG_BOOKMARK, atts); // Write the properties of interest atts.clear(); hd.startElement("", TAG_TITLE, TAG_TITLE, atts); String curTitle = curItem.getTitle(); hd.characters(curTitle.toCharArray(), 0, curTitle.length()); hd.endElement("", TAG_TITLE, TAG_TITLE); //write out the text associated with this bookmark // if the scope allows for that if (!scope.toLowerCase().equals(SCOPE_BOOKMARKSONLY)) { PDFTextStripper stripper = new PDFTextStripper(); stripper.setStartBookmark(curItem); stripper.setEndBookmark(curItem); String textBetweenBookmarks = stripper.getText(doc); hd.startElement("", TAG_TEXT, TAG_TEXT, atts); textBetweenBookmarks = MassageTextResult(textBetweenBookmarks); hd.characters(textBetweenBookmarks.toCharArray(), 0, textBetweenBookmarks.length()); hd.endElement("", TAG_TEXT, TAG_TEXT); } } // Now check the children PDOutlineItem child = curItem.getFirstChild(); while (child != null) { processBookmark(hd, doc, child, scope, level + 1); logger.info("Child:" + child.getTitle()); child = child.getNextSibling(); } // Close the mark hd.endElement("", TAG_BOOKMARK, TAG_BOOKMARK); } catch (SAXException e) { logger.error(e); addErrorTagToOutput(hd, e.toString()); } catch (IOException e) { logger.error(e); addErrorTagToOutput(hd, e.toString()); } finally { // Nothing concluding to do } }