List of usage examples for javax.xml.parsers SAXParser parse
public void parse(InputSource is, DefaultHandler dh) throws SAXException, IOException
From source file:org.infoscoop.request.filter.MakeMenuFilter.java
/** * TODO:isExternalService is not required because menuUrl is fixed * @param responseStream//from w w w . ja va 2 s .c om * @param menuType * @param menuUrl * @param locale * @param isExternalService * @return * @throws IOException */ public static byte[] process(InputStream responseStream, String menuType, String menuUrl, Locale locale, boolean isExternalService) throws IOException { SAXParser parser = null; try { parser = factory.newSAXParser(); } catch (ParserConfigurationException e) { log.error("", e); } catch (SAXException e) { log.error("", e); } Map resMap; try { resMap = I18NUtil.getResourceMap(I18NUtil.TYPE_MENU, locale); } catch (Exception ex) { log.error("Faild to processing of internationalizing menu.", ex); resMap = new HashMap(); } MakeMenuHandler handler = new MakeMenuHandler(menuUrl, resMap); try { parser.parse(responseStream, handler); } catch (SAXException e) { log.error("Failed to parse menu", e); } catch (IOException e) { log.error("Failed to parse menu", e); } try { String json = null; boolean isSidePanel = (menuType.equals(MENUTYPE_SIDEMENU)); if (!isExternalService) { json = handler.getJSONPString(isSidePanel); } else { json = handler.getSiteTopJSONPString(isSidePanel); } return json.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { log.error("", e); } return null; }
From source file:org.infoscoop.service.PortalLayoutService.java
/** * @return/*from w w w . j a va2 s.c o m*/ * @throws Exception */ public String getPortalLayoutJson() throws Exception { SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); MakePortalLayoutHandler handler = new MakePortalLayoutHandler(); parser.parse(new InputSource(new StringReader(getPortalLayout())), handler); return handler.getJSONPString(); }
From source file:org.infoscoop.service.ProxyConfService.java
/** * @return String/*from w ww. j av a 2 s . c o m*/ * @throws Exception */ public String getProxyConfJson() throws Exception { SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); MakeProxyConfHandler handler = new MakeProxyConfHandler(); parser.parse(new InputSource(new StringReader(getProxyConf())), handler); return handler.getJSONPString(); }
From source file:org.intermine.webservice.server.ServicesListingsServlet.java
private void parseWebXML() { String path = getServletContext().getRealPath("/WEB-INF/" + WEB_XML); File webxml = new File(path); SAXParser parser = getParser(); DefaultHandler handler = getHandler(); try {//from w ww . j ava 2 s . c o m parser.parse(webxml, handler); } catch (IOException e) { throw new InternalErrorException(e); } catch (SAXException e) { throw new InternalErrorException(e); } }
From source file:org.intermine.webservice.server.widget.ReportWidgetsServlet.java
private void parseXML() throws ReportWidgetException { String path = getServletContext().getRealPath("/WEB-INF/webconfig-model.xml"); SAXParser parser = parser(); try {//from ww w. j a v a 2s.c om parser.parse(new File(path), handler()); } catch (IOException e) { throw new ReportWidgetException(e.getMessage()); } catch (SAXException e) { throw new ReportWidgetException(e.getMessage()); } }
From source file:org.iterx.miru.bean.factory.XmlBeanParser.java
public void parse(StreamSource source) throws IOException { try {/* w ww. j a va2 s. c om*/ SAXParserFactory factory; SAXParser parser; factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(true); parser = factory.newSAXParser(); parser.parse(source.getInputStream(), this); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (SAXException e) { if (LOGGER.isErrorEnabled()) LOGGER.error(e, e); throw new IOException("Invalid xml stream [" + source + "]. " + e.getMessage()); } }
From source file:org.iterx.miru.dispatcher.handler.factory.XmlHandlerChainParser.java
public void parse(StreamSource source) throws IOException { try {/*from w w w . j av a2 s. c om*/ SAXParserFactory factory; SAXParser parser; factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(true); parser = factory.newSAXParser(); parser.parse(source.getInputStream(), this); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (SAXException e) { if (LOGGER.isErrorEnabled()) LOGGER.error(e); throw new IOException("Invalid xml stream [" + source + "]. " + e.getMessage()); } }
From source file:org.iterx.miru.handler.XmlHandlerMappingParser.java
public void parse(Resource resource) throws IOException { try {//ww w . ja va 2 s .co m SAXParserFactory factory; SAXParser parser; factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(true); parser = factory.newSAXParser(); parser.parse(resource.getInputStream(), this); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (SAXException e) { throw new IOException("Invalid xml stream: " + e.getMessage()); } }
From source file:org.jahia.services.content.JCRSessionWrapper.java
public void importXML(String path, InputStream inputStream, int uuidBehavior, int rootBehavior, Map<String, String> replacements, Map<String, List<String>> references) throws IOException, InvalidSerializedDataException, RepositoryException { JCRNodeWrapper node = getNode(path); try {//ww w. j av a2s. c om if (!node.isCheckedOut()) { checkout(node); } } catch (UnsupportedRepositoryOperationException ex) { // versioning not supported } DocumentViewImportHandler documentViewImportHandler = new DocumentViewImportHandler(this, path); documentViewImportHandler.setRootBehavior(rootBehavior); documentViewImportHandler.setUuidBehavior(uuidBehavior); documentViewImportHandler.setReplacements(replacements); if (references != null) { documentViewImportHandler.setReferences(references); } try { SAXParser parser = JahiaSAXParserFactory.newInstance().newSAXParser(); parser.parse(inputStream, documentViewImportHandler); } catch (SAXParseException e) { logger.error("Cannot import - File contains invalid XML", e); throw new RuntimeException("Cannot import file because it contains invalid XML", e); } catch (Exception e) { logger.error("Cannot import", e); throw new RuntimeException("Cannot import file", e); } }
From source file:org.jahia.services.importexport.ImportExportBaseService.java
private void handleImport(InputStream is, DefaultHandler h, String fileName) { try {//from www . j a v a 2 s . c o m SAXParser parser = JahiaSAXParserFactory.newInstance().newSAXParser(); parser.parse(is, h); if (h instanceof DocumentViewImportHandler) { DocumentViewImportHandler dh = (DocumentViewImportHandler) h; if (dh.getMissingDependencies().size() > 0) { for (String s : dh.getMissingDependencies()) { logger.error("Dependency not declared : " + s + " (set debug on DocumentViewImportHandler for more details)"); } } } } catch (SAXParseException e) { logger.error("Cannot import - File contains invalid XML", e); throw new RuntimeException( "Cannot import " + (fileName != null ? fileName : "") + " file as it contains invalid XML", e); } catch (Exception e) { logger.error("Cannot import", e); throw new RuntimeException("Cannot import " + (fileName != null ? fileName : "") + " file", e); } }