List of usage examples for javax.xml.parsers SAXParser parse
public void parse(InputSource is, DefaultHandler dh) throws SAXException, IOException
From source file:gov.nasa.ensemble.core.jscience.xml.XMLProfileParser.java
@Override public int numberParsable(URI uri, InputStream inputStream) { BufferedInputStream bis = null; XMLProfileHandler xmlProfileHandler = new XMLProfileHandler(); try {// ww w .j av a 2 s . com bis = new BufferedInputStream(inputStream); SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); xmlProfileHandler.setTestOnly(true); parser.parse(inputStream, xmlProfileHandler); } catch (Exception ex) { return ProfilesParser.UNPARSABLE; } finally { IOUtils.closeQuietly(bis); } return xmlProfileHandler.getProfileCount(); }
From source file:com.epam.wilma.test.client.HttpRequestSender.java
private InputStream compress(final InputStream source) { try {// ww w . j a v a 2 s. c o m OutputStream fis = new ByteArrayOutputStream(); SAXDocumentSerializer saxDocumentSerializer = new SAXDocumentSerializer(); saxDocumentSerializer.setOutputStream(fis); SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setNamespaceAware(true); SAXParser saxParser = saxParserFactory.newSAXParser(); saxParser.parse(source, saxDocumentSerializer); return new ByteArrayInputStream(((ByteArrayOutputStream) fis).toByteArray()); } catch (ParserConfigurationException e) { throw new SystemException("error", e); } catch (SAXException e) { throw new SystemException("error", e); } catch (IOException e) { throw new SystemException("error", e); } }
From source file:org.apache.syncope.core.init.ContentLoader.java
@Transactional public void load() { // 1. Check wether we are allowed to load default content into the DB final List<SyncopeConf> res = confDAO.findAll(); if (res == null || res.size() > 0) { LOG.info("Data found in the database, leaving untouched"); return;/*from w ww. j a v a 2s . c o m*/ } LOG.info("Empty database found, loading default content"); // 2. Create views LOG.debug("Creating views"); try { InputStream viewsStream = getClass().getResourceAsStream("/views.xml"); Properties views = new Properties(); views.loadFromXML(viewsStream); for (String idx : views.stringPropertyNames()) { LOG.debug("Creating view {}", views.get(idx).toString()); final String updateViews = views.get(idx).toString().replaceAll("\\n", " "); entityManager.createNativeQuery(updateViews).executeUpdate(); } LOG.debug("Views created, go for indexes"); } catch (Exception e) { LOG.error("While creating views", e); } // 3. Create indexes LOG.debug("Creating indexes"); try { InputStream indexesStream = getClass().getResourceAsStream("/indexes.xml"); Properties indexes = new Properties(); indexes.loadFromXML(indexesStream); for (String idx : indexes.stringPropertyNames()) { LOG.debug("Creating index {}", indexes.get(idx).toString()); final String updateIndexed = indexes.get(idx).toString(); entityManager.createNativeQuery(updateIndexed).executeUpdate(); } LOG.debug("Indexes created, go for default content"); } catch (Exception e) { LOG.error("While creating indexes", e); } // noop workflow // entityManager.createNativeQuery("DELETE FROM ACT_GE_PROPERTY").executeUpdate(); // 4. Load default content SAXParserFactory factory = SAXParserFactory.newInstance(); try { SAXParser parser = factory.newSAXParser(); parser.parse(getClass().getResourceAsStream("/content.xml"), importExport); LOG.debug("Default content successfully loaded"); } catch (Exception e) { LOG.error("While loading default content", e); } }
From source file:io.lightlink.excel.StreamingExcelTransformer.java
private List<String> processSharedStrings(byte[] bytes) throws ParserConfigurationException, SAXException, IOException { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); SharedStringsHandler handler = new SharedStringsHandler(); saxParser.parse(new ByteArrayInputStream(bytes), handler); return handler.getSharedStings(); }
From source file:io.lightlink.excel.StreamingExcelTransformer.java
private void processSheet(byte[] bytes, OutputStream out, ExcelStreamVisitor visitor) throws ParserConfigurationException, SAXException, IOException { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); Writer printWriter = new OutputStreamWriter(out, "UTF-8"); saxParser.parse(new ByteArrayInputStream(bytes), new SheetTemplateHandler(printWriter, sharedStrings, visitor)); printWriter.flush();/*from w w w .j a v a 2 s . c o m*/ }
From source file:com.opengamma.financial.convention.calendar.XMLCalendarLoader.java
/** * Populate the specified working day calendar from the XML file. * @param calendar the calendar to populate, not null */// w w w . j a v a 2 s.co m public void populateCalendar(final ExceptionCalendar calendar) { final SAXParserFactory factory = SAXParserFactory.newInstance(); try { final SAXParser parser = factory.newSAXParser(); parser.parse(getSourceDataURI(), new DefaultHandler() { private ParserState _state = ParserState.OTHER; private String _innerText; @Override public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) { switch (_state) { case OTHER: if (qName.equalsIgnoreCase(TAG_WORKING_DAYS)) { _state = ParserState.WORKING_DAYS; } else if (qName.equalsIgnoreCase(TAG_NON_WORKING_DAYS)) { _state = ParserState.NON_WORKING_DAYS; } break; } } @Override public void characters(final char[] ch, final int start, final int length) { _innerText = new String(ch, start, length); } @Override public void endElement(final String uri, final String localName, final String qName) { switch (_state) { case WORKING_DAYS: if (qName.equalsIgnoreCase(TAG_DATE)) { calendar.addWorkingDay(LocalDate.parse(_innerText)); } else if (qName.equalsIgnoreCase(TAG_WORKING_DAYS)) { _state = ParserState.OTHER; } break; case NON_WORKING_DAYS: if (qName.equalsIgnoreCase(TAG_DATE)) { calendar.addNonWorkingDay(LocalDate.parse(_innerText)); } else if (qName.equalsIgnoreCase(TAG_NON_WORKING_DAYS)) { _state = ParserState.OTHER; } break; } } }); } catch (final ParserConfigurationException ex) { throw wrap(ex); } catch (final SAXException ex) { throw wrap(ex); } catch (final IOException ex) { throw wrap(ex); } }
From source file:fr.ybo.transportsbordeaux.tbcapi.Keolis.java
/** * @param <ObjetKeolis> type d'objet Keolis. * @param url url./*from w w w.j a v a2 s . c o m*/ * @param handler handler. * @return liste d'objets Keolis. * @throws TbcErreurReseaux en cas d'erreur rseau. */ private <ObjetKeolis> List<ObjetKeolis> appelKeolis(String url, KeolisHandler<ObjetKeolis> handler) throws ErreurReseau { LOG_YBO.debug("Appel d'une API Keolis sur l'url '" + url + '\''); long startTime = System.nanoTime() / 1000; HttpClient httpClient = HttpUtils.getHttpClient(); HttpUriRequest httpPost = new HttpPost(url); List<ObjetKeolis> answer; try { HttpResponse reponse = httpClient.execute(httpPost); ByteArrayOutputStream ostream = new ByteArrayOutputStream(); if (reponse == null || reponse.getEntity() == null) { throw new ErreurReseau("Erreur lors de la rcupration de la rponse http"); } reponse.getEntity().writeTo(ostream); String contenu = new String(ostream.toByteArray(), "ISO-8859-1"); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); parser.parse(new ByteArrayInputStream(contenu.getBytes("UTF-8")), handler); answer = handler.getObjets(); } catch (IOException socketException) { throw new ErreurReseau(socketException); } catch (SAXException saxException) { throw new ErreurReseau(saxException); } catch (ParserConfigurationException exception) { throw new KeolisException("Erreur lors de l'appel l'API keolis", exception); } if (answer == null) { throw new ErreurReseau("Erreur dans la rponse donnes par Keolis."); } long elapsedTime = System.nanoTime() / 1000 - startTime; LOG_YBO.debug("Rponse de Keolis en " + elapsedTime + "s"); return answer; }
From source file:com.sshtools.common.mru.MRUList.java
/** * * * @param in//from w ww. ja va 2 s . co m * * @throws SAXException * @throws ParserConfigurationException * @throws IOException */ public void reload(InputStream in) throws SAXException, ParserConfigurationException, IOException { try { SAXParserFactory saxFactory = SAXParserFactory.newInstance(); SAXParser saxParser = saxFactory.newSAXParser(); saxParser.parse(in, new MRUSAXHandler()); } catch (Throwable e) { System.out.println("MRUList.reload: Exception loading most-recently-used list."); e.printStackTrace(); } }
From source file:de.shadowhunt.subversion.internal.InfoLoader.java
public Info load(final Resource resource, final Revision revision) throws Exception { final File infoFile = new File(root, resolve(revision) + resource.getValue() + SUFFIX); final SAXParser saxParser = BasicHandler.FACTORY.newSAXParser(); final InfoHandler handler = new InfoHandler(); saxParser.parse(infoFile, handler); final InfoImpl info = handler.getInfo(); info.setResource(resource);/*from w w w .j a v a 2 s .c o m*/ final File f = new File(root, resolve(revision) + resource.getValue()); info.setDirectory(f.isDirectory()); if (info.isFile()) { final FileInputStream fis = new FileInputStream(f); try { info.setMd5(DigestUtils.md5Hex(fis)); } finally { IOUtils.closeQuietly(fis); } } info.setProperties(resourcePropertyLoader.load(resource, revision)); Assert.assertEquals("resource must match", resource, info.getResource()); return info; }
From source file:es.mityc.firmaJava.libreria.utilidades.AnalizadorFicheroFirma.java
public void analizar(File fichero) { SAXParserFactory factoria = SAXParserFactory.newInstance(); factoria.setNamespaceAware(true);//from w ww . j a va 2s. com factoria.setValidating(false); FileInputStream fis = null; try { fis = new FileInputStream(fichero); SAXParser parser = factoria.newSAXParser(); parser.parse(fis, this); } catch (ParserConfigurationException e) { log.error(e); } catch (SAXException e) { log.error(e); } catch (FileNotFoundException e) { log.error(e); } catch (IOException e) { log.error(e); } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { } } } }