List of usage examples for org.dom4j.io SAXReader setValidation
public void setValidation(boolean validation)
From source file:de.ingrid.portal.interfaces.impl.WMSInterfaceImpl.java
License:EUPL
/** * @see de.ingrid.portal.interfaces.WMSInterface#getWMSServices(java.lang.String) *///from w w w . j av a 2 s . co m public Collection getWMSServices(String sessionID) { URL url; SAXReader reader = new SAXReader(false); ArrayList result = new ArrayList(); 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 url = new URL(config .getString("interface_url", "http://localhost/mapbender/php/mod_portalCommunication_gt.php") .concat("?PREQUEST=getWMSServices").concat("&PHPSESSID=" + sessionID)); 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 the wms services List nodes = document.selectNodes("//portal_communication/wms_services/wms"); String serviceURL = null; for (Iterator i = nodes.iterator(); i.hasNext();) { Node node = (Node) i.next(); serviceURL = node.valueOf("url"); if (mapBenderVersion.equals(MAPBENDER_VERSION_2_1)) { serviceURL = serviceURL.replace(',', '&'); } WMSServiceDescriptor wmsServiceDescriptor = new WMSServiceDescriptor(node.valueOf("name"), serviceURL); result.add(wmsServiceDescriptor); } return result; } catch (Exception e) { log.error(e.toString()); } return null; }
From source file:de.ingrid.portal.interfaces.impl.WMSInterfaceImpl.java
License:EUPL
/** * @see de.ingrid.portal.interfaces.WMSInterface#getWMSSearchParameter(java.lang.String) */// w w w.j ava 2s . c o m 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:de.innovationgate.webgate.api.auth.FileAuthenticationModule.java
License:Open Source License
/** * @param _file//w w w . j a va 2 s . com */ private synchronized void update(File _file) { try { // Parse doc SAXReader reader = new SAXReader(); reader.setIncludeExternalDTDDeclarations(false); reader.setIncludeInternalDTDDeclarations(false); reader.setValidation(false); Document doc = reader.read(_file); // Flags _allowAnonymous = Boolean.valueOf(doc.getRootElement().attributeValue("allowanonymous")).booleanValue(); // Read users Map users = new HashMap(); Iterator userNodes = doc.selectNodes("/users/user").iterator(); Element userNode; while (userNodes.hasNext()) { userNode = (Element) userNodes.next(); String name = userNode.attributeValue("name"); String password = userNode.attributeValue("password"); String mail = userNode.attributeValue("mail"); String aliasesStr = userNode.attributeValue("aliases"); Set aliases = new HashSet(); if (aliasesStr != null) { aliases.addAll(WGUtils.deserializeCollection(aliasesStr, ",", true)); } users.put(name, new User(name, password, mail, aliases)); } _users = users; // Read Groups Map groups = new HashMap(); Iterator groupNodes = doc.selectNodes("/users/group").iterator(); Element groupNode; while (groupNodes.hasNext()) { groupNode = (Element) groupNodes.next(); String name = groupNode.attributeValue("name"); List members = WGUtils.deserializeCollection(groupNode.attributeValue("members"), ",", true); Group group = new Group(name, members); groups.put(name, group); notifyMembers(group); } // Call listeners synchronized (_authenticationSourceListeners) { Iterator listeners = _authenticationSourceListeners.iterator(); while (listeners.hasNext()) { ((AuthenticationSourceListener) listeners.next()).authenticationDataChanged(); } } } catch (DocumentException e) { WGFactory.getLogger().error("Error parsing authentication file '" + getAuthenticationSource() + "': Error in XML: " + e.getMessage()); } }
From source file:edu.ku.brc.af.core.db.DBTableIdMgr.java
License:Open Source License
/** * Reads in datamodel input file and populates the Hashtable of the DBTableMgr with DBTableInfo * @param inputFile the input file.//from w w w . j ava 2s. co m */ public void initialize(final File inputFile) { log.debug( "Reading in datamodel file: " + inputFile.getAbsolutePath() + " to create and populate DBTableMgr"); //$NON-NLS-1$ //$NON-NLS-2$ String classname = null; try { SAXReader reader = new SAXReader(); reader.setValidation(false); Element databaseNode = XMLHelper.readFileToDOM4J(inputFile); if (databaseNode != null) { for (Iterator<?> i = databaseNode.elementIterator("table"); i.hasNext();) //$NON-NLS-1$ { Element tableNode = (Element) i.next(); classname = tableNode.attributeValue("classname"); //$NON-NLS-1$ String tablename = tableNode.attributeValue("table"); //$NON-NLS-1$ int tableId = Integer.parseInt(tableNode.attributeValue("tableid")); //$NON-NLS-1$ boolean isSearchable = XMLHelper.getAttr(tableNode, "searchable", false); //$NON-NLS-1$ String primaryKeyField = null; // iterate through child elements of id nodes, there should only be 1 for (Iterator<?> i2 = tableNode.elementIterator("id"); i2.hasNext();) //$NON-NLS-1$ { Element idNode = (Element) i2.next(); primaryKeyField = idNode.attributeValue("name"); //$NON-NLS-1$ } if (classname == null) { log.error("classname is null; check input file"); //$NON-NLS-1$ } if (tablename == null) { log.error("tablename is null; check input file"); //$NON-NLS-1$ } if (isFullSchema && primaryKeyField == null) { log.error("primaryKeyField is null; check input file table[" + tablename + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } //log.debug("Populating hashtable ID["+tableId+"]for class: " + classname+" "+ inputFile.getName()); DBTableInfo tblInfo = new DBTableInfo(tableId, classname, tablename, primaryKeyField, tableNode.attributeValue("abbrv")); //$NON-NLS-1$ tblInfo.setSearchable(isSearchable); tblInfo.setBusinessRuleName(XMLHelper.getAttr(tableNode, "businessrule", null)); //$NON-NLS-1$ if (hash.get(tableId) != null) { log.error("Table ID used twice[" + tableId + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } hash.put(tableId, tblInfo); byClassNameHash.put(classname.toLowerCase(), tblInfo); byShortClassNameHash.put(tblInfo.getShortClassName().toLowerCase(), tblInfo); tables.add(tblInfo); Element idElement = (Element) tableNode.selectSingleNode("id"); //$NON-NLS-1$ if (idElement != null) { tblInfo.setIdColumnName(getAttr(idElement, "column", null)); //$NON-NLS-1$ tblInfo.setIdFieldName(getAttr(idElement, "name", null)); //$NON-NLS-1$ tblInfo.setIdType(getAttr(idElement, "type", null)); //$NON-NLS-1$ } for (Iterator<?> ir = tableNode.elementIterator("tableindex"); ir.hasNext();) //$NON-NLS-1$ { Element irNode = (Element) ir.next(); String inxName = getAttr(irNode, "indexName", null); String inxColNames = getAttr(irNode, "columnNames", null); tblInfo.addTableIndex(inxName, inxColNames); } Element displayElement = (Element) tableNode.selectSingleNode("display"); //$NON-NLS-1$ if (displayElement != null) { tblInfo.setDefaultFormName(getAttr(displayElement, "view", null)); //$NON-NLS-1$ tblInfo.setUiFormatter(getAttr(displayElement, "uiformatter", null)); //$NON-NLS-1$ tblInfo.setDataObjFormatter(getAttr(displayElement, "dataobjformatter", null)); //$NON-NLS-1$ tblInfo.setSearchDialog(getAttr(displayElement, "searchdlg", null)); //$NON-NLS-1$ tblInfo.setNewObjDialog(getAttr(displayElement, "newobjdlg", null)); //$NON-NLS-1$ } else { tblInfo.setDefaultFormName(""); //$NON-NLS-1$ tblInfo.setUiFormatter(""); //$NON-NLS-1$ tblInfo.setDataObjFormatter(""); //$NON-NLS-1$ tblInfo.setSearchDialog(""); //$NON-NLS-1$ tblInfo.setNewObjDialog(""); //$NON-NLS-1$ } for (Iterator<?> ir = tableNode.elementIterator("relationship"); ir.hasNext();) //$NON-NLS-1$ { Element irNode = (Element) ir.next(); DBRelationshipInfo tblRel = new DBRelationshipInfo( irNode.attributeValue("relationshipname"), //$NON-NLS-1$ getRelationshipType(irNode.attributeValue("type")), //$NON-NLS-1$ irNode.attributeValue("classname"), //$NON-NLS-1$ irNode.attributeValue("columnname"), //$NON-NLS-1$ irNode.attributeValue("othersidename"), //$NON-NLS-1$ irNode.attributeValue("jointable"), //$NON-NLS-1$ getAttr(irNode, "required", false), //$NON-NLS-1$ getAttr(irNode, "updatable", false), //$NON-NLS-1$ getAttr(irNode, "save", false), //$NON-NLS-1$ getAttr(irNode, "likemanytoone", false)); //$NON-NLS-1$ tblInfo.getRelationships().add(tblRel); } for (Iterator<?> ir = tableNode.elementIterator("field"); ir.hasNext();) //$NON-NLS-1$ { Element irNode = (Element) ir.next(); int len = -1; String lenStr = irNode.attributeValue("length"); //$NON-NLS-1$ if (StringUtils.isNotEmpty(lenStr) && StringUtils.isNumeric(lenStr)) { len = Integer.parseInt(lenStr); // if (!UIRegistry.isMobile() && len > 256) // length over 255 are memo/text fields in MySQL and do not need to be constrained // { // len = 32767; // } } DBFieldInfo fieldInfo = new DBFieldInfo(tblInfo, irNode.attributeValue("column"), //$NON-NLS-1$ irNode.attributeValue("name"), //$NON-NLS-1$ irNode.attributeValue("type"), //$NON-NLS-1$ len, getAttr(irNode, "required", false), //$NON-NLS-1$ getAttr(irNode, "updatable", false), //$NON-NLS-1$ getAttr(irNode, "unique", false), //$NON-NLS-1$ getAttr(irNode, "indexed", false), //$NON-NLS-1$ getAttr(irNode, "partialDate", false), //$NON-NLS-1$ getAttr(irNode, "datePrecisionName", null)); //$NON-NLS-1$ // This done to cache the original setting. fieldInfo.setRequiredInSchema(fieldInfo.isRequired()); tblInfo.addField(fieldInfo); } for (Iterator<?> faIter = tableNode.elementIterator("fieldalias"); faIter.hasNext();) //$NON-NLS-1$ { Element faNode = (Element) faIter.next(); String vName = getAttr(faNode, "vname", null);//$NON-NLS-1$ String aName = getAttr(faNode, "aname", null);//$NON-NLS-1$ if (vName != null && aName != null) { tblInfo.addFieldAlias(vName, aName); } } //Collections.sort(tblInfo.getFields()); } } else { log.error("Reading in datamodel file. SAX parser got null for the root of the document."); //$NON-NLS-1$ } } catch (java.lang.NumberFormatException numEx) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DBTableIdMgr.class, numEx); log.error("Specify datamodel input file: " + inputFile.getAbsolutePath() //$NON-NLS-1$ + " failed to provide valid table id for class/table:" + classname); //$NON-NLS-1$ log.error(numEx); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DBTableIdMgr.class, ex); log.error(ex); ex.printStackTrace(); } Collections.sort(tables); log.debug("Done Reading in datamodel file: " + inputFile.getAbsolutePath()); //$NON-NLS-1$ }
From source file:edu.ku.brc.helpers.XMLHelper.java
License:Open Source License
/** * Reads a DOM from a stream/* w w w . jav a 2 s. c o m*/ * @param fileinputStream the stream to be read * @return the root element of the DOM */ public static org.dom4j.Element readFileToDOM4J(final FileInputStream fileinputStream) throws Exception { SAXReader saxReader = new SAXReader(); saxReader.setValidation(false); saxReader.setStripWhitespaceText(true); saxReader.setFeature("http://xml.org/sax/features/namespaces", false); saxReader.getXMLReader().setFeature("http://xml.org/sax/features/namespaces", false); //saxReader.setFeature("http://apache.org/xml/features/validation/schema", false); //saxReader.setFeature("http://xml.org/sax/features/validation", false); //saxReader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", // (FormViewFactory.class.getResource("../form.xsd")).getPath()); org.dom4j.Document document = saxReader.read(fileinputStream); return document.getRootElement(); }
From source file:edu.ku.brc.helpers.XMLHelper.java
License:Open Source License
public static org.dom4j.Element readStrToDOM4J(final String data) throws Exception { SAXReader saxReader = new SAXReader(); saxReader.setValidation(false); saxReader.setStripWhitespaceText(true); saxReader.setFeature("http://xml.org/sax/features/namespaces", false); saxReader.getXMLReader().setFeature("http://xml.org/sax/features/namespaces", false); //saxReader.setFeature("http://apache.org/xml/features/validation/schema", false); //saxReader.setFeature("http://xml.org/sax/features/validation", false); //saxReader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", // (FormViewFactory.class.getResource("../form.xsd")).getPath()); org.dom4j.Document document = saxReader.read(new StringReader(data)); return document.getRootElement(); }
From source file:edu.ku.brc.specify.tools.AppendHelp.java
License:Open Source License
/** * Reads a DOM from a stream//from w w w. jav a 2 s. co m * @param fileinputStream the stream to be read * @return the root element of the DOM */ public Element readFileToDOM4J(final File file) throws IOException, DocumentException { SAXReader saxReader = new SAXReader(); try { saxReader.setValidation(false); saxReader.setStripWhitespaceText(true); //saxReader.setIncludeExternalDTDDeclarations(false); //saxReader.setIncludeInternalDTDDeclarations(false); saxReader.setIgnoreComments(true); //saxReader.setXMLFilter(new TransparentFilter(saxReader.getXMLReader())); EntityResolver entityResolver = new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) { return new InputSource(""); } }; saxReader.setEntityResolver(entityResolver); //saxReader.getXMLFilter().setDTDHandler(null); } catch (Exception ex) { ex.printStackTrace(); } org.dom4j.Document document = saxReader.read(new FileInputStream(file)); return document.getRootElement(); }
From source file:edu.ku.brc.specify.tools.datamodelgenerator.DatamodelGenerator.java
License:Open Source License
/** * Reads in file that provides listing of tables with their respective Id's and default views. * @return boolean true if reading of tableId file was successful. *//*from w w w . jav a2 s. com*/ private boolean readTableMetadataFromFile(final String tableIdListingFilePath) { Hashtable<String, Boolean> abbrvHashLocal = new Hashtable<String, Boolean>(); log.info("Preparing to read in Table and TableID listing from file: " + tableIdListingFilePath); try { File tableIdFile = new File(tableIdListingFilePath); FileInputStream fileInputStream = new FileInputStream(tableIdFile); SAXReader reader = new SAXReader(); reader.setValidation(false); org.dom4j.Document doc = reader.read(fileInputStream); Element root = doc.getRootElement(); Element dbNode = (Element) root.selectSingleNode("database"); if (dbNode != null) { for (Iterator<?> i = dbNode.elementIterator("table"); i.hasNext();) { Element element = (Element) i.next(); String tablename = element.attributeValue("name"); String defaultView = element.attributeValue("view"); String id = element.attributeValue("id"); String abbrv = XMLHelper.getAttr(element, "abbrev", null); boolean isSearchable = XMLHelper.getAttr(element, "searchable", false); if (StringUtils.isNotEmpty(abbrv)) { if (abbrvHashLocal.get(abbrv) == null) { abbrvHashLocal.put(abbrv, true); } else { throw new RuntimeException( "`abbrev` [" + abbrv + "] or table[" + tablename + "] ids already in use."); } } else { throw new RuntimeException("`abbrev` is missing or empty for table[" + tablename + "]"); } String busRule = ""; Element brElement = (Element) element.selectSingleNode("businessrule"); if (brElement != null) { busRule = brElement.getTextTrim(); } //log.debug("Creating TableMetaData and putting in tblMetaDataHashtable for name: " + tablename + " id: " + id + " defaultview: " + defaultView); TableMetaData tblMetaData = new TableMetaData(id, defaultView, createDisplay(element), createFieldAliases(element), isSearchable, busRule, abbrv); tblMetaDataHash.put(tablename, tblMetaData); for (Iterator<?> ir = element.elementIterator("relationship"); ir.hasNext();) { Element relElement = (Element) ir.next(); String relName = relElement.attributeValue("relationshipname"); boolean isLike = XMLHelper.getAttr(relElement, "likemanytoone", false); tblMetaData.setIsLikeManyToOne(relName, isLike); } } } else { log.debug("Ill-formatted file for reading in Table and TableID listing. Filename:" + tableIdFile.getAbsolutePath()); } fileInputStream.close(); return true; } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DatamodelGenerator.class, ex); ex.printStackTrace(); log.fatal(ex); } return false; }
From source file:edu.ku.brc.specify.toycode.L18NStringResApp.java
License:Open Source License
/** * Reads a DOM from a stream//from ww w.jav a 2s . c o m * @param fileinputStream the stream to be read * @return the root element of the DOM */ public static org.dom4j.Document readFileToDOM4J(final FileInputStream fileinputStream) throws Exception { SAXReader saxReader = new SAXReader(); saxReader.setValidation(false); saxReader.setStripWhitespaceText(true); saxReader.setFeature("http://xml.org/sax/features/namespaces", false); saxReader.getXMLReader().setFeature("http://xml.org/sax/features/namespaces", false); //saxReader.setFeature("http://apache.org/xml/features/validation/schema", false); //saxReader.setFeature("http://xml.org/sax/features/validation", false); //saxReader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", // (FormViewFactory.class.getResource("../form.xsd")).getPath()); return saxReader.read(fileinputStream); }
From source file:eu.scape_project.planning.services.taverna.parser.T2FlowParser.java
License:Apache License
/** * Initialises the parser by reading the the t2flow from the input stream * and parsing it./* ww w .jav a2 s . co m*/ * * @param t2flow * the t2flow * @throws TavernaParserException * if the parser could not be initialized */ protected void initialise(InputStream t2flow) throws TavernaParserException { log.debug("Parsing inputstream"); T2FLOW_NAMESPACE_MAP.put("t2f", "http://taverna.sf.net/2008/xml/t2flow"); ValidatingParserFactory vpf = new ValidatingParserFactory(); try { SAXParser parser = vpf.getValidatingParser(); parser.setProperty(ValidatingParserFactory.JAXP_SCHEMA_SOURCE, ProjectImporter.TAVERNA_SCHEMA_URI); SAXReader reader = new SAXReader(parser.getXMLReader()); reader.setValidation(false); SchemaResolver schemaResolver = new SchemaResolver(); schemaResolver.addSchemaLocation(ProjectImporter.TAVERNA_SCHEMA_URI, SCHEMA_LOCATION + ProjectImporter.TAVERNA_SCHEMA); reader.setEntityResolver(schemaResolver); doc = reader.read(t2flow); } catch (DocumentException e) { log.error("Error initialising T2FlowParser: {}", e.getMessage()); throw new TavernaParserException("Error parsing workflow.", e); } catch (ParserConfigurationException e) { log.error("Error initialising T2FlowParser: {}", e.getMessage()); throw new TavernaParserException("Error parsing workflow.", e); } catch (SAXException e) { log.error("Error initialising T2FlowParser: {}", e.getMessage()); throw new TavernaParserException("Error parsing workflow.", e); } }