List of usage examples for javax.xml.parsers DocumentBuilderFactory setValidating
public void setValidating(boolean validating)
From source file:edu.washington.iam.tools.WebClient.java
public void init() { log.debug("webclient init"); // init the doc system try {/*from www.j a va 2s . c o m*/ DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(false); domFactory.setValidating(false); String feature = "http://apache.org/xml/features/nonvalidating/load-external-dtd"; domFactory.setFeature(feature, false); documentBuilder = domFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { log.error("javax.xml.parsers.ParserConfigurationException: " + e); } // init SSL // System.setProperty( "javax.net.debug", "ssl"); try { if (caFile != null && certFile != null && keyFile != null) { log.info("using the socketfactory: ca=" + caFile + ", cert=" + certFile + ", key=" + keyFile); IamConnectionManager icm = new IamConnectionManager(caFile, certFile, keyFile); connectionManager = icm.getConnectionManager(); /** } else { log.info("using default socketfactory"); socketFactory = new SSLSocketFactory(); **/ } httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, queryTimeLimit); HttpConnectionParams.setSoTimeout(httpParams, queryTimeLimit); initialized = true; } catch (Exception e) { log.error(" " + e); } log.debug("gws client initialize done"); }
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//ww w. j av a2 s . 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:com.qcadoo.maven.plugins.validator.ValidatorMojo.java
private void validateSchema(final String file) throws MojoFailureException { try {//from w ww. j ava 2s . c o m getLog().info("Validating file: " + file); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); try { URL url = new URL("http://www.qcadoo.com"); url.openConnection(); factory.setValidating(true); } catch (UnknownHostException e) { factory.setValidating(false); } catch (IOException e) { factory.setValidating(false); } factory.setValidating(false); factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema"); DocumentBuilder parser = factory.newDocumentBuilder(); parser.setErrorHandler(new ValidationErrorHandler()); parser.parse(new File(file)); } catch (ParserConfigurationException e) { getLog().error(e.getMessage()); throw (MojoFailureException) new MojoFailureException("We couldn't parse the file: " + file) .initCause(e); } catch (SAXException e) { getLog().error(e.getMessage()); throw (MojoFailureException) new MojoFailureException("We couldn't parse the file: " + file) .initCause(e); } catch (IOException e) { getLog().error(e.getMessage()); throw (MojoFailureException) new MojoFailureException("We couldn't parse the file: " + file) .initCause(e); } }
From source file:com.ecyrd.jspwiki.auth.authorize.XMLGroupDatabase.java
private void buildDOM() throws WikiSecurityException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setExpandEntityReferences(false); factory.setIgnoringComments(true);// w ww. j ava2 s . c o m factory.setNamespaceAware(false); try { m_dom = factory.newDocumentBuilder().parse(m_file); log.debug("Database successfully initialized"); m_lastModified = m_file.lastModified(); m_lastCheck = System.currentTimeMillis(); } catch (ParserConfigurationException e) { log.error("Configuration error: " + e.getMessage()); } catch (SAXException e) { log.error("SAX error: " + e.getMessage()); } catch (FileNotFoundException e) { log.info("Group database not found; creating from scratch..."); } catch (IOException e) { log.error("IO error: " + e.getMessage()); } if (m_dom == null) { try { // // Create the DOM from scratch // m_dom = factory.newDocumentBuilder().newDocument(); m_dom.appendChild(m_dom.createElement("groups")); } catch (ParserConfigurationException e) { log.fatal("Could not create in-memory DOM"); } } // Ok, now go and read this sucker in if (m_dom != null) { NodeList groupNodes = m_dom.getElementsByTagName(GROUP_TAG); for (int i = 0; i < groupNodes.getLength(); i++) { Element groupNode = (Element) groupNodes.item(i); String groupName = groupNode.getAttribute(GROUP_NAME); if (groupName == null) { log.warn("Detected null group name in XMLGroupDataBase. Check your group database."); } else { Group group = buildGroup(groupNode, groupName); m_groups.put(groupName, group); } } } }
From source file:com.amalto.workbench.providers.datamodel.SchemaTreeContentProvider.java
public XSDSchema createSchema(String location) { InputStream stream = null;/*w w w . j av a 2s.c om*/ try { stream = new FileInputStream(location); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilderFactory.setValidating(false); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(stream); return XSDSchemaImpl.createSchema(document.getDocumentElement()); } catch (Exception e) { log.error(e.getMessage()); return null; } finally { IOUtils.closeQuietly(stream); } }
From source file:net.sf.l2j.gameserver.instancemanager.DimensionalRiftManager.java
public void loadSpawns() { int countGood = 0, countBad = 0; try {//from www . j a v a 2s . c o m DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setIgnoringComments(true); File file = new File(Config.DATAPACK_ROOT + "/data/dimensionalRift.xml"); if (!file.exists()) throw new IOException(); Document doc = factory.newDocumentBuilder().parse(file); NamedNodeMap attrs; byte type, roomId; int mobId, x, y, z, delay, count; L2Spawn spawnDat; L2NpcTemplate template; for (Node rift = doc.getFirstChild(); rift != null; rift = rift.getNextSibling()) { if ("rift".equalsIgnoreCase(rift.getNodeName())) { for (Node area = rift.getFirstChild(); area != null; area = area.getNextSibling()) { if ("area".equalsIgnoreCase(area.getNodeName())) { attrs = area.getAttributes(); type = Byte.parseByte(attrs.getNamedItem("type").getNodeValue()); for (Node room = area.getFirstChild(); room != null; room = room.getNextSibling()) { if ("room".equalsIgnoreCase(room.getNodeName())) { attrs = room.getAttributes(); roomId = Byte.parseByte(attrs.getNamedItem("id").getNodeValue()); for (Node spawn = room.getFirstChild(); spawn != null; spawn = spawn .getNextSibling()) { if ("spawn".equalsIgnoreCase(spawn.getNodeName())) { attrs = spawn.getAttributes(); mobId = Integer.parseInt(attrs.getNamedItem("mobId").getNodeValue()); delay = Integer.parseInt(attrs.getNamedItem("delay").getNodeValue()); count = Integer.parseInt(attrs.getNamedItem("count").getNodeValue()); template = NpcTable.getInstance().getTemplate(mobId); if (template == null) _log.warn("Template " + mobId + " not found!"); if (!_rooms.containsKey(type)) _log.warn("Type " + type + " not found!"); else if (!_rooms.get(type).containsKey(roomId)) _log.warn("Room " + roomId + " in Type " + type + " not found!"); for (int i = 0; i < count; i++) { DimensionalRiftRoom riftRoom = _rooms.get(type).get(roomId); x = riftRoom.getRandomX(); y = riftRoom.getRandomY(); z = riftRoom.getTeleportCoords()[2]; if (template != null && _rooms.containsKey(type) && _rooms.get(type).containsKey(roomId)) { spawnDat = new L2Spawn(template); spawnDat.setAmount(1); spawnDat.setLocx(x); spawnDat.setLocy(y); spawnDat.setLocz(z); spawnDat.setHeading(-1); spawnDat.setRespawnDelay(delay); SpawnTable.getInstance().addNewSpawn(spawnDat, false); _rooms.get(type).get(roomId).getSpawns().add(spawnDat); countGood++; } else { countBad++; } } } } } } } } } } } catch (Exception e) { _log.warn("Error on loading dimensional rift spawns: " + e); e.printStackTrace(); } _log.info("DimensionalRiftManager: Loaded " + countGood + " dimensional rift spawns, " + countBad + " errors."); }
From source file:com.l2jfree.gameserver.instancemanager.MapRegionManager.java
private void load() { for (File xml : Util.getDatapackFiles("mapregion", ".xml")) { Document doc = null;/*from w w w.j av a2 s .c om*/ try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true); factory.setIgnoringComments(true); doc = factory.newDocumentBuilder().parse(xml); } catch (Exception e) { _log.warn("MapRegionManager: Error while loading XML definition: " + xml.getName() + e, e); return; } try { parseDocument(doc); } catch (Exception e) { _log.warn("MapRegionManager: Error in XML definition: " + xml.getName() + e, e); return; } } }
From source file:de.betterform.xml.dom.DOMUtil.java
/** * __UNDOCUMENTED__// w w w. j a v a 2s .c om * * @param isNamespaceAware __UNDOCUMENTED__ * @param isValidating __UNDOCUMENTED__ * @return __UNDOCUMENTED__ */ public static Document newDocument(boolean isNamespaceAware, boolean isValidating) { // !!! workaround to enable betterForm to run within WebLogic Server // Force JAXP to use xerces as the default JAXP parser doesn't work with BetterForm // // String oldFactory = System.getProperty("javax.xml.parsers.DocumentBuilderFactory"); // System.setProperty("javax.xml.parsers.DocumentBuilderFactory","org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); // restore to original factory // // System.setProperty("javax.xml.parsers.DocumentBuilderFactory",oldFactory); // !!! end workaround factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(isNamespaceAware); factory.setValidating(isValidating); try { // Create builder. DocumentBuilder builder = factory.newDocumentBuilder(); return builder.newDocument(); } catch (ParserConfigurationException pce) { System.err.println(pce.toString()); } return null; }
From source file:com.uisteps.utils.api.zapi.Zapi.java
private Document getXML(File file) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory f = DocumentBuilderFactory.newInstance(); f.setValidating(false); DocumentBuilder builder = f.newDocumentBuilder(); return builder.parse(file); }
From source file:com.qcadoo.plugin.internal.descriptorparser.DefaultPluginDescriptorParser.java
public DefaultPluginDescriptorParser() { try {/*w w w. ja v a 2 s .co m*/ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { URL url = new URL("http://www.qcadoo.com"); url.openConnection(); factory.setValidating(true); } catch (UnknownHostException e) { factory.setValidating(false); } catch (IOException e) { factory.setValidating(false); } factory.setValidating(false); factory.setNamespaceAware(true); factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema"); documentBuilder = factory.newDocumentBuilder(); documentBuilder.setErrorHandler(new com.qcadoo.plugin.api.errorhandler.ValidationErrorHandler()); } catch (ParserConfigurationException e) { throw new IllegalStateException("Error while parsing plugin xml schema", e); } }