List of usage examples for org.xml.sax EntityResolver EntityResolver
EntityResolver
From source file:de.micromata.genome.gwiki.page.gspt.taglibs.TagLibraryInfoImpl.java
protected void loadTagLibary(String uri) { Digester dig = new Digester(); dig.setClassLoader(Thread.currentThread().getContextClassLoader()); dig.setValidating(false);/* w ww . j a v a2s . c om*/ final EntityResolver parentResolver = dig.getEntityResolver(); dig.setEntityResolver(new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { InputStream is = null; if (StringUtils.equals(systemId, "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd") == true || StringUtils.equals(publicId, "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN") == true) { is = loadLocalDtd("web-jsptaglibrary_1_1.dtd"); } else if (StringUtils.equals(systemId, "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd") == true || StringUtils.equals(publicId, "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN") == true) { is = loadLocalDtd("web-jsptaglibrary_1_2.dtd"); } if (is == null) { if (parentResolver == null) { GWikiLog.error("Cannot resolve entity: " + systemId); return null; } return parentResolver.resolveEntity(publicId, systemId); } InputSource source = new InputSource(is); source.setPublicId(publicId); source.setSystemId(systemId); return source; } }); dig.addCallMethod("taglib/tlib-version", "setTlibversion", 0); dig.addCallMethod("taglib/tlibversion", "setTlibversion", 0); dig.addCallMethod("taglib/jsp-version", "setJspversion", 0); dig.addCallMethod("taglib/jspversion", "setJspversion", 0); dig.addCallMethod("taglib/short-name", "setShortname", 0); dig.addCallMethod("taglib/shortname", "setShortname", 0); dig.addObjectCreate("taglib/tag", TagTmpInfo.class); dig.addCallMethod("taglib/tag/name", "setTagName", 0); dig.addCallMethod("taglib/tag/description", "setInfoString", 0); dig.addCallMethod("taglib/tag/tag-class", "setTagClassName", 0); dig.addCallMethod("taglib/tag/tagclass", "setTagClassName", 0); dig.addCallMethod("taglib/tag/body-content", "setBodycontent", 0); dig.addCallMethod("taglib/tag/bodycontent", "setBodycontent", 0); dig.addObjectCreate("taglib/tag/attribute", TagTmpAttributeInfo.class); dig.addCallMethod("taglib/tag/attribute/name", "setName", 0); dig.addCallMethod("taglib/tag/attribute/required", "setRequired", 0); dig.addCallMethod("taglib/tag/attribute/rtexprvalue", "setRtexprvalue", 0); dig.addSetNext("taglib/tag/attribute", "addAttributeInfo"); dig.addSetNext("taglib/tag", "addTag"); dig.push(this); try { InputStream is = loadImpl(uri); if (is == null) { throw new RuntimeException("could not load tld '" + uri + "'"); } /* * ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(is, baos); String text = * Converter.stringFromBytes(baos.toByteArray()); dig.parse(new StringReader(text)); */ dig.parse(is); rework(); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:com.sap.prd.mobile.ios.mios.xcodeprojreader.jaxb.JAXBPlistParserTest.java
private DocumentBuilder initDocumentBuilder() throws Exception { DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); db.setEntityResolver(new EntityResolver() { @Override/*from ww w. j av a2 s . co m*/ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return new InputSource(new StringReader("")); } }); return db; }
From source file:com.graphhopper.jsprit.core.problem.io.VrpXMLReader.java
private XMLConfiguration createXMLConfiguration() { XMLConfiguration xmlConfig = new XMLConfiguration(); xmlConfig.setAttributeSplittingDisabled(true); xmlConfig.setDelimiterParsingDisabled(true); if (schemaValidation) { final InputStream resource = Resource.getAsInputStream("vrp_xml_schema.xsd"); if (resource != null) { EntityResolver resolver = new EntityResolver() { @Override/*from w ww .ja va 2 s . c o m*/ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { { InputSource is = new InputSource(resource); return is; } } }; xmlConfig.setEntityResolver(resolver); xmlConfig.setSchemaValidation(true); } else { logger.debug( "cannot find schema-xsd file (vrp_xml_schema.xsd). try to read xml without xml-file-validation."); } } return xmlConfig; }
From source file:de.ingrid.portal.interfaces.impl.WMSInterfaceImpl.java
/** * @see de.ingrid.portal.interfaces.WMSInterface#getWMSSearchParameter(java.lang.String) *//* w w w. j a v a2 s . c om*/ public WMSSearchDescriptor getWMSSearchParameter(String sessionID) { URL url; SAXReader reader = new SAXReader(false); try { // workaround for wrong dtd location EntityResolver resolver = new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) { if (systemId.indexOf("portalCommunication.dtd") > 0) { InputStream in = getClass().getResourceAsStream("wms_interface.dtd"); return new InputSource(in); } return null; } }; reader.setEntityResolver(resolver); // END workaround for wrong dtd location String urlStr = config.getString("interface_url", "http://localhost/mapbender/php/mod_portalCommunication_gt.php"); if (urlStr.indexOf("?") > 0) { urlStr = urlStr.concat("&PREQUEST=getWMSSearch").concat("&PHPSESSID=" + sessionID); } else { urlStr = urlStr.concat("?PREQUEST=getWMSSearch").concat("&PHPSESSID=" + sessionID); } url = new URL(urlStr); reader.setValidation(false); Document document = reader.read(url); // check for valid server response if (document.selectSingleNode("//portal_communication") == null) { throw new Exception("WMS Server Response is not valid!"); } // check for valid server response String error = document.valueOf("//portal_communication/error"); if (error != null && error.length() > 0) { throw new Exception("WMS Server Error: " + error); } // get search type String searchType = document.valueOf("//portal_communication/search/@type"); if (searchType == null || (!searchType.equalsIgnoreCase("bbox") && !searchType.equalsIgnoreCase("gkz"))) { throw new Exception("WMS Interface: unsupported search type (" + searchType + ")"); } WMSSearchDescriptor wmsSearchDescriptor = new WMSSearchDescriptor(); if (searchType.equalsIgnoreCase("bbox")) { wmsSearchDescriptor.setType(WMSSearchDescriptor.WMS_SEARCH_BBOX); wmsSearchDescriptor .setTypeOfCoordinates(document.valueOf("//portal_communication/search/bbox/@cootype")); wmsSearchDescriptor .setMinX(Double.parseDouble(document.valueOf("//portal_communication/search/bbox/minx"))); wmsSearchDescriptor .setMinY(Double.parseDouble(document.valueOf("//portal_communication/search/bbox/miny"))); wmsSearchDescriptor .setMaxX(Double.parseDouble(document.valueOf("//portal_communication/search/bbox/maxx"))); wmsSearchDescriptor .setMaxY(Double.parseDouble(document.valueOf("//portal_communication/search/bbox/maxy"))); } else if (searchType.equalsIgnoreCase("gkz")) { wmsSearchDescriptor.setType(WMSSearchDescriptor.WMS_SEARCH_COMMUNITY_CODE); wmsSearchDescriptor.setCommunityCode(document.valueOf("//portal_communication/search/gkz")); } return wmsSearchDescriptor; } catch (Exception e) { log.error(e.toString()); } return null; }
From source file:com.autentia.tnt.manager.report.ReportManager.java
private void parseDocument(Boolean typeFile, String reportName) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); final InputStream jasperreportDtd = loader .getResourceAsStream("net/sf/jasperreports/engine/dtds/jasperreport.dtd"); InputStream xmlSource = null; parsingStart = System.currentTimeMillis(); log.debug("parseDocument - [start] " + reportName); try {/*from w w w .j a v a 2s . c o m*/ SAXParser sp = new SAXParser(); log.debug("parseDocument - newSAXParser=" + (System.currentTimeMillis() - parsingStart) + " ms."); File f = null; try { if (typeFile == true) f = new File(loader.getResource(reportName).toURI()); else f = new File(reportName); } catch (URISyntaxException e) { log.error("Error en ParseDocument", e); } log.debug("parseDocument - getResource=" + (System.currentTimeMillis() - parsingStart) + " ms."); xmlSource = new FileInputStream(f); sp.setContentHandler(this); sp.setEntityResolver(new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (publicId.equals("//JasperReports//DTD Report Design//EN") || systemId.equals("http://jasperreports.sourceforge.net/dtds/jasperreport.dtd")) { return new InputSource(jasperreportDtd); } else { String msg = "DTD (" + publicId + " " + systemId + ") cannot be resolved by ReportManager: " + "please change TNTConcept to add the new DTD or change your JasperReport's JRXML file " + "to use the standard DTD"; log.error("parseDocument - " + msg); throw new IllegalArgumentException(msg); } } }); sp.parse(new InputSource(xmlSource)); } catch (FinalizeParsingException fpe) { // ignore this exception as it is thrown as an optimization } catch (SAXException se) { log.error("parseDocument - exception", se); } catch (IOException ie) { log.error("parseDocument - exception", ie); } finally { if (xmlSource != null) { try { xmlSource.close(); } catch (IOException e) { // ignored } } try { jasperreportDtd.close(); } catch (IOException e) { // ignored } log.info( "parseDocument - " + reportName + " (" + (System.currentTimeMillis() - parsingStart) + " ms.)"); } }
From source file:com.dgwave.osrs.OsrsClient.java
private void initJaxb() throws OsrsException { if (jc != null && oj != null) return;//w w w.j a va 2 s .c o m try { this.jc = JAXBContext.newInstance("com.dgwave.osrs.jaxb"); this.oj = new ObjectFactory(); SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); spf.setNamespaceAware(true); spf.setValidating(false); xmlReader = spf.newSAXParser().getXMLReader(); xmlReader.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { logger.debug("Ignoring DTD"); return new InputSource(new StringReader("")); } }); } catch (Exception e) { throw new OsrsException("JAXB Error", e); } }
From source file:com.microsoft.windowsazure.messaging.NotificationHub.java
private void refreshRegistrationInformation(String pnsHandle) throws Exception { if (isNullOrWhiteSpace(pnsHandle)) { throw new IllegalArgumentException("pnsHandle"); }// w w w . j av a2 s . c om // delete old registration information Editor editor = mSharedPreferences.edit(); Set<String> keys = mSharedPreferences.getAll().keySet(); for (String key : keys) { if (key.startsWith(STORAGE_PREFIX + REGISTRATION_NAME_STORAGE_KEY)) { editor.remove(key); } } editor.commit(); // get existing registrations Connection conn = new Connection(mConnectionString); String filter = PnsSpecificRegistrationFactory.getInstance().getPNSHandleFieldName() + " eq '" + pnsHandle + "'"; String resource = mNotificationHubPath + "/Registrations/?$filter=" + URLEncoder.encode(filter, "UTF-8"); String content = null; String response = conn.executeRequest(resource, content, XML_CONTENT_TYPE, "GET"); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return null; } }); Document doc = builder.parse(new InputSource(new StringReader(response))); doc.getDocumentElement().normalize(); Element root = doc.getDocumentElement(); //for each registration, parse it NodeList entries = root.getElementsByTagName("entry"); for (int i = 0; i < entries.getLength(); i++) { Registration registration; Element entry = (Element) entries.item(i); String xml = getXmlString(entry); if (PnsSpecificRegistrationFactory.getInstance().isTemplateRegistration(xml)) { registration = PnsSpecificRegistrationFactory.getInstance() .createTemplateRegistration(mNotificationHubPath); } else { registration = PnsSpecificRegistrationFactory.getInstance() .createNativeRegistration(mNotificationHubPath); } registration.loadXml(xml, mNotificationHubPath); storeRegistrationId(registration.getName(), registration.getRegistrationId(), registration.getPNSHandle()); } mIsRefreshNeeded = false; }
From source file:com.jaspersoft.studio.custom.adapter.controls.DynamicControlComposite.java
/** * Search a castor mapping file inside the data adapter jar and if it is found create the controls * to edit it/* www . j ava 2s.c o m*/ */ protected void createDynamicControls() { String xmlDefinition = getXmlDefinitionLocation(); if (xmlDefinition != null) { DataAdapter adapter = dataAdapterDescriptor.getDataAdapter(); InputStream is = dataAdapterDescriptor.getClass().getResourceAsStream("/" + xmlDefinition); if (null != is) { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setIgnoringComments(true); dbf.setNamespaceAware(false); DocumentBuilder builder = dbf.newDocumentBuilder(); builder.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (systemId.contains("http://castor.org/mapping.dtd")) { return new InputSource(new StringReader("")); } else { return null; } } }); Document document = builder.parse(is); Node mapNode = document.getDocumentElement(); if (mapNode.getNodeName().equals("mapping")) { NodeList adapterNodes = mapNode.getChildNodes(); for (int j = 0; j < adapterNodes.getLength(); ++j) { Node adapterNode = adapterNodes.item(j); if (adapterNode.getNodeName().equals("class")) { String classAttribute = adapterNode.getAttributes().getNamedItem("name") .getNodeValue(); if (classAttribute != null && classAttribute.equals(adapter.getClass().getName())) { createDynamicControls(adapterNode.getChildNodes()); is.close(); return; } } } } } catch (Exception ex) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } ex.printStackTrace(); } } } }
From source file:net.jawr.web.bundle.processor.BundleProcessor.java
/** * Returns the XML document of the web.xml file * // w ww .ja v a 2 s . com * @param webXmlPath * the web.xml path * @return the Xml document of the web.xml file * * @throws ParserConfigurationException * if a parser configuration exception occurs * @throws FactoryConfigurationError * if a factory configuration exception occurs * @throws SAXException * if a SAX exception occurs * @throws IOException * if an IO exception occurs */ protected Document getWebXmlDocument(String baseDir) throws ParserConfigurationException, FactoryConfigurationError, SAXException, IOException { File webXml = new File(baseDir, WEB_XML_FILE_PATH); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); docBuilder.setEntityResolver(new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return null; } }); Document doc = docBuilder.parse(webXml); return doc; }
From source file:com.meidusa.amoeba.context.ProxyRuntimeContext.java
private ProxyServerConfig loadConfig(String configFileName) { DocumentBuilder db;/* w ww. j ava 2s . c o m*/ try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(true); dbf.setNamespaceAware(false); db = dbf.newDocumentBuilder(); db.setEntityResolver(new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) { if (systemId.endsWith("amoeba.dtd")) { InputStream in = ProxyRuntimeContext.class .getResourceAsStream("/com/meidusa/amoeba/xml/amoeba.dtd"); if (in == null) { LogLog.error("Could not find [amoeba.dtd]. Used [" + ProxyRuntimeContext.class.getClassLoader() + "] class loader in the search."); return null; } else { return new InputSource(in); } } else { return null; } } }); db.setErrorHandler(new ErrorHandler() { public void warning(SAXParseException exception) { } public void error(SAXParseException exception) throws SAXException { logger.error(exception.getMessage() + " at (" + exception.getLineNumber() + ":" + exception.getColumnNumber() + ")"); throw exception; } public void fatalError(SAXParseException exception) throws SAXException { logger.fatal(exception.getMessage() + " at (" + exception.getLineNumber() + ":" + exception.getColumnNumber() + ")"); throw exception; } }); return loadConfigurationFile(configFileName, db); } catch (Exception e) { logger.fatal("Could not load configuration file, failing", e); throw new ConfigurationException("Error loading configuration file " + configFileName, e); } }