List of usage examples for org.xml.sax SAXException getLocalizedMessage
public String getLocalizedMessage()
From source file:Main.java
public static Element loadXml(final InputStream inStream) throws IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false);/*from w w w . j a v a 2s . c o m*/ Document doc; try { doc = factory.newDocumentBuilder().parse(inStream); } catch (SAXException e) { throw new IOException(e.getLocalizedMessage(), e); } catch (ParserConfigurationException e) { throw new IOException(e.getLocalizedMessage(), e); } return doc.getDocumentElement(); }
From source file:Main.java
public static boolean creteEntity(Object entity, String fileName) { boolean flag = false; try {//from ww w .j av a 2 s . com DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(fileName); Class clazz = entity.getClass(); Field[] fields = clazz.getDeclaredFields(); Node EntityElement = document.getElementsByTagName(clazz.getSimpleName() + "s").item(0); Element newEntity = document.createElement(clazz.getSimpleName()); EntityElement.appendChild(newEntity); for (Field field : fields) { field.setAccessible(true); Element element = document.createElement(field.getName()); element.appendChild(document.createTextNode(field.get(entity).toString())); newEntity.appendChild(element); } TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource domSource = new DOMSource(document); StreamResult streamResult = new StreamResult(new File(fileName)); transformer.transform(domSource, streamResult); flag = true; } catch (ParserConfigurationException pce) { System.out.println(pce.getLocalizedMessage()); pce.printStackTrace(); } catch (TransformerException te) { System.out.println(te.getLocalizedMessage()); te.printStackTrace(); } catch (IOException ioe) { System.out.println(ioe.getLocalizedMessage()); ioe.printStackTrace(); } catch (SAXException sae) { System.out.println(sae.getLocalizedMessage()); sae.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return flag; }
From source file:Main.java
public static boolean validate(URL schemaFile, String xmlString) { boolean success = false; try {//w w w. j a va 2 s. c o m SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(schemaFile); Validator validator = schema.newValidator(); Source xmlSource = null; try { xmlSource = new StreamSource(new java.io.StringReader(xmlString)); validator.validate(xmlSource); System.out.println("Congratulations, the document is valid"); success = true; } catch (SAXException e) { e.printStackTrace(); System.out.println(xmlSource.getSystemId() + " is NOT valid"); System.out.println("Reason: " + e.getLocalizedMessage()); } } catch (Exception e) { e.printStackTrace(); } return success; }
From source file:de.iteratec.iteraplan.businesslogic.service.SavedQueryXmlHelper.java
/** * Loads a query from database//from ww w .j a v a 2s . com * * @param <T> The XML dto class the XML content reflects * @param clazz The XML dto class the XML content reflects * @param schemaName The URI of the schema that will be used to validate the XML query * @param savedQuery the query object * @return The object tree reflecting the XML query. Instance of a JAXB-marshallable class */ @SuppressWarnings("unchecked") public static <T extends SerializedQuery<? extends ReportMemBean>> T loadQuery(Class<T> clazz, String schemaName, SavedQuery savedQuery) { if (!ReportType.LANDSCAPE.equals(savedQuery.getType()) && clazz.isAssignableFrom(LandscapeDiagramXML.class)) { LOGGER.error("requested QueryType ('{0}') does not fit the required QueryType ('{1}')", ReportType.LANDSCAPE, savedQuery.getType()); throw new IteraplanBusinessException(IteraplanErrorMessages.INVALID_REQUEST_PARAMETER, "savedQueryType"); } try { String content = savedQuery.getContent(); if (content == null || content.length() <= 0) { throw new IteraplanTechnicalException(IteraplanErrorMessages.LOAD_QUERY_EXCEPTION); } Reader queryDefinitionReader = null; try { Schema schema = getSchema(schemaName); JAXBContext context = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = context.createUnmarshaller(); unmarshaller.setSchema(schema); queryDefinitionReader = new StringReader(content); return (T) unmarshaller.unmarshal(queryDefinitionReader); } finally { IOUtils.closeQuietly(queryDefinitionReader); } } catch (SAXException e) { LOGGER.error("SAXException in SavedQueryServiceImpl#loadQuery " + e.getLocalizedMessage()); throw new IteraplanTechnicalException(IteraplanErrorMessages.INTERNAL_ERROR, e); } catch (JAXBException e) { LOGGER.error("JAXBException in SavedQueryServiceImpl#loadQuery " + e.getLocalizedMessage()); throw new IteraplanTechnicalException(IteraplanErrorMessages.INTERNAL_ERROR, e); } }
From source file:com.microsoft.tfs.core.clients.build.internal.utils.BuildTypeUtil.java
/** * Attempt to parse the specified file for values required to populated the * returned {@link BuildTypeInfo}// w w w . java 2 s.co m * * @param buildTypeName * name of the build type downloading. * @param localBuildFile * local file to parse. * @param encoding * suggested file encoding to use, passing <code>null</code> will * mean a suggesting encoding of <code>UTF-8</code> will be used. * @return parsed values for the passed file. * @throws IOException * @throws ParserConfigurationException * @throws SAXNotSupportedException * @throws SAXNotRecognizedException */ public static BuildTypeInfo parseBuildTypeInfo(final String buildTypeName, final File localBuildFile, final FileEncoding encoding) throws IOException { final BasicBuildTypeParseHandler handler = new BasicBuildTypeParseHandler(buildTypeName); try { final SAXParser saxParser = SAXUtils.newSAXParser(); saxParser.parse(localBuildFile, handler); } catch (final SAXException e) { // We did our best - log and rethrow any exceptions... final String message = MessageFormat.format( Messages.getString("BuildTypeUtil.SAXExceptionParsingFileFormat"), //$NON-NLS-1$ localBuildFile.getPath(), e.getLocalizedMessage()); log.error(message, e); throw new BuildTypeFileParseException(message, e); } catch (final ParserConfigurationException e) { // We did our best - log and rethrow any exceptions... final String message = MessageFormat.format( Messages.getString("BuildTypeUtil.ParserConfigurationExceptionParsingFileFormat"), //$NON-NLS-1$ localBuildFile.getPath(), e.getLocalizedMessage()); log.error(message, e); throw new BuildTypeFileParseException(message, e); } return handler.getBuildTypeInfo(); }
From source file:com.googlecode.jgenhtml.JGenHtmlUtils.java
public static Document loadXmlDoc(final InputStream stream) { Document result = null;/* w w w . j av a2s. c o m*/ try { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setExpandEntityReferences(false); domFactory.setNamespaceAware(true); DocumentBuilder builder = domFactory.newDocumentBuilder(); result = builder.parse(stream); } catch (SAXException ex) { LOGGER.log(Level.SEVERE, ex.getLocalizedMessage()); } catch (IOException ex) { LOGGER.log(Level.SEVERE, ex.getLocalizedMessage()); } catch (ParserConfigurationException ex) { LOGGER.log(Level.SEVERE, ex.getLocalizedMessage()); } return result; }
From source file:com.grameenfoundation.ictc.controllers.SaleforceIntegrationController.java
public static Document parseXmlText(InputSource input_data) { //get the factory DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try {/*from w w w. ja va2 s . co m*/ //Using factory get an instance of document builder DocumentBuilder db = dbf.newDocumentBuilder(); //InputSource is = new InputSource(); //is.setCharacterStream(new StringReader(data)); //parse using builder to get DOM representation of the data Document doc = db.parse(input_data); // normalize text representation doc.getDocumentElement().normalize(); System.out.println("Root element of the doc is " + doc.getDocumentElement().getNodeName()); return doc; } catch (ParserConfigurationException pce) { System.out.println("Exception is " + pce.getLocalizedMessage()); pce.printStackTrace(); return null; } catch (SAXException se) { System.out.println("Exception is " + se.getLocalizedMessage()); System.out.println("line " + se.getMessage()); se.printStackTrace(); return null; } catch (IOException ioe) { System.out.println("Exception is " + ioe.getLocalizedMessage()); ioe.printStackTrace(); return null; } catch (Exception ex) { System.out.println("Exception is " + ex.getLocalizedMessage()); // ioe.printStackTrace(); return null; } }
From source file:com.jkoolcloud.tnt4j.streams.StreamsAgent.java
private static void loadConfigAndRun(Reader reader, InputStreamListener streamListener, StreamTasksListener streamTasksListener) { try {/*from ww w . ja va 2 s. co m*/ initAndRun(reader == null ? new StreamsConfigLoader() : new StreamsConfigLoader(reader), streamListener, streamTasksListener); } catch (SAXException e) { LOGGER.log(OpLevel.ERROR, String.valueOf(e.toString())); } catch (Exception e) { LOGGER.log(OpLevel.ERROR, String.valueOf(e.getLocalizedMessage()), e); } }
From source file:com.mothsoft.alexis.engine.textual.WebContentParserImpl.java
private String parse(org.apache.tika.parser.Parser parser, InputStream is, ContentHandler handler, StringBuffer buffer) throws IOException { final Metadata metadata = new Metadata(); final ParseContext context = new ParseContext(); try {/* w w w.jav a 2 s . c om*/ parser.parse(is, handler, metadata, context); return StringUtils.trimToEmpty(buffer.toString()); } catch (SAXException e) { throw new IOException(e.getLocalizedMessage()); } catch (TikaException e) { throw new IOException(e.getLocalizedMessage()); } }
From source file:fr.fastconnect.factory.tibco.bw.codereview.ConvertRulesToSonarMojo.java
@Override public void execute() throws MojoExecutionException { // super.execute(); // don't call or it will call the Service if (!codeReviewProjectDirectory.exists()) { getLog().error("Reviewer project not found. Skipping."); throw new MojoExecutionException("Reviewer project not found. Skipping."); }/* ww w.j a v a 2 s . c o m*/ File rulesDirectory = new File(codeReviewProjectDirectory, rulesPath); if (!rulesDirectory.exists()) { getLog().error("Rules directory not found in reviewer project not found. Skipping."); throw new MojoExecutionException("Rules directory not found in reviewer project not found. Skipping."); } Collection<File> rules = FileUtils.listFiles(rulesDirectory, new RegexFileFilter(rulesPattern), FileFilterUtils.directoryFileFilter()); try { processRules(rules); } catch (SAXException e) { throw new MojoExecutionException(e.getLocalizedMessage(), e); } catch (IOException e) { throw new MojoExecutionException(e.getLocalizedMessage(), e); } }