List of usage examples for org.dom4j.io SAXReader setDefaultHandler
public void setDefaultHandler(ElementHandler handler)
ElementHandler
instances have been registered, this will set a default ElementHandler
to be called for any path which does NOT have a handler registered. From source file:de.interactive_instruments.etf.bsxm.GmlGeoX.java
License:Apache License
/** * Validates the given (GML geometry) node. * <p>/*from www. j av a2 s . com*/ * By default validation is only performed for the following GML geometry * elements: Point, Polygon, Surface, Curve, LinearRing, MultiPolygon, * MultiGeometry, MultiSurface, MultiCurve, Ring, and LineString. The set of * GML elements to validate can be modified via the following methods: * {@link #registerGmlGeometry(String)}, * {@link #unregisterGmlGeometry(String)}, and * {@link #unregisterAllGmlGeometries()}. These methods are also available * for XQueries. * <p> * The validation tasks to perform can be specified via the given mask. The * mask is a simple string, where the character '1' at the position of a * specific test (assuming a 1-based index) specifies that the test shall be * performed. If the mask does not contain a character at the position of a * specific test (because the mask is empty or the length is smaller than * the position), then the test will be executed. * <p> * The following tests are available: * <p> * <table> * <tr> * <th>Position</th> * <th>Test Name</th> * <th>Description</th> * </tr> * <tr> * <td>1</td> * <td>General Validation</td> * <td>This test validates the given geometry using the validation * functionality of both deegree and JTS.</td> * </tr> * <tr> * <td>2</td> * <td>Polygon Patch Connectivity</td> * <td>Checks that multiple polygon patches within a single surface are * connected.</td> * </tr> * <tr> * <td>3</td> * <td>Repetition of Position in CurveSegments</td> * <td>Checks that consecutive positions within a CurveSegment are not * equal.</td> * </tr> * </table> * <p> * Examples: * <ul> * <li>The mask '010' indicates that only the 'Polygon Patch Connectivity' * test shall be performed.</li> * <li>The mask '1' indicates that all tests shall be performed (because the * first one is set to true/'1' and nothing is said for the other tests). * </li> * <li>The mask '0' indicates that all except the first test shall be * performed. * </ul> * * @param o * the GML geometry to validate * @return a mask with the test results, encoded as characters - one at each * position (1-based index) of the available tests. 'V' indicates * that the test passed, i.e. that the geometry is valid according * to that test. 'F' indicates that the test failed. 'S' indicates * that the test was skipped. Example: the string 'SVF' shows that * the first test was skipped, while the second test passed and the * third failed. * @throws QueryException */ @Requires(Permission.NONE) public String validate(Object o, String testMask) throws QueryException { try { // determine which tests to execute boolean isTestGeonovum, isTestPolygonPatchConnectivity, isTestRepetitionInCurveSegments; if (testMask == null) { isTestGeonovum = true; isTestPolygonPatchConnectivity = true; isTestRepetitionInCurveSegments = true; } else { isTestGeonovum = (testMask.length() >= 1 && testMask.charAt(0) == '1') ? true : false; isTestPolygonPatchConnectivity = (testMask.length() >= 2 && testMask.charAt(1) == '1') ? true : false; isTestRepetitionInCurveSegments = (testMask.length() >= 3 && testMask.charAt(2) == '1') ? true : false; } boolean isValidGeonovum = false; boolean polygonPatchesAreConnected = false; boolean noRepetitionInCurveSegment = false; BXNode elem; if (o instanceof ANode) { elem = ((ANode) o).toJava(); } else if (o instanceof BXNode) { elem = (BXNode) o; } else { // unknown type encountered throw new IllegalArgumentException( "Object type '" + o.getClass().getName() + "' is not supported for this method."); } // ================ // Geonovum validation (deegree and JTS validation) if (isTestGeonovum) { ValidatorContext ctx = new ValidatorContext(); GeometryElementHandler handler = new GeometryElementHandler(ctx, null); /* * configure handler with GML geometries specified through this * class */ handler.unregisterAllGmlGeometries(); for (String additionalGmlElementName : gmlGeometries) { handler.registerGmlGeometry(additionalGmlElementName); } SAXReader saxReader = new SAXReader(); saxReader.setDefaultHandler(handler); final InputStream stream = geoutils.nodeToInputStream(elem); saxReader.read(stream); isValidGeonovum = ctx.isSuccessful(); if (!isValidGeonovum) { List<ValidatorMessage> vmsgs = ctx.getMessages(); for (ValidatorMessage msg : vmsgs) { LOGGER.error(msg.toString()); } } } if (isTestPolygonPatchConnectivity || isTestRepetitionInCurveSegments) { ValidatorContext ctx = new ValidatorContext(); SecondaryGeometryElementValidationHandler handler = new SecondaryGeometryElementValidationHandler( isTestPolygonPatchConnectivity, isTestRepetitionInCurveSegments, ctx); /* * configure handler with GML geometries specified through this * class */ handler.unregisterAllGmlGeometries(); for (String additionalGmlElementName : gmlGeometries) { handler.registerGmlGeometry(additionalGmlElementName); } SAXReader saxReader = new SAXReader(); saxReader.setDefaultHandler(handler); final InputStream stream = geoutils.nodeToInputStream(elem); saxReader.read(stream); // ================ // Test: polygon patches of a surface are connected if (isTestPolygonPatchConnectivity) { polygonPatchesAreConnected = handler.arePolygonPatchesConnected(); } // ================ // Test: point repetition in curve segment if (isTestRepetitionInCurveSegments) { noRepetitionInCurveSegment = handler.isNoRepetitionInCurveSegments(); } } // combine results StringBuilder sb = new StringBuilder(); if (!isTestGeonovum) { sb.append("S"); } else if (isValidGeonovum) { sb.append("V"); } else { sb.append("F"); } if (!isTestPolygonPatchConnectivity) { sb.append("S"); } else if (polygonPatchesAreConnected) { sb.append("V"); } else { sb.append("F"); } if (!isTestRepetitionInCurveSegments) { sb.append("S"); } else if (noRepetitionInCurveSegment) { sb.append("V"); } else { sb.append("F"); } return sb.toString(); } catch (Exception e) { throw new QueryException(e); } }
From source file:de.tudarmstadt.ukp.lmf.transform.XMLToDBTransformer.java
License:Apache License
/** * Read xml File and save its contents to Database * @param xmlFile/*from ww w . ja v a 2s . c om*/ * @param lexicalResourceName * @throws DocumentException * @throws UbyInvalidArgumentException */ public void transform(File xmlFile, String lexicalResourceName) throws DocumentException, IllegalArgumentException { long startTime = System.currentTimeMillis(); openSession(); if (lexicalResourceName != null) { lexicalResource = (LexicalResource) session.get(LexicalResource.class, lexicalResourceName); } SAXReader reader = new SAXReader(false); reader.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (systemId.endsWith(".dtd")) { return new InputSource(new StringReader("")); } return null; } }); reader.setDefaultHandler(this); reader.read(xmlFile); commit(); closeSession(); System.out.println("TOTAL TIME: " + (System.currentTimeMillis() - startTime)); System.out.println("NUM ENTRIES: " + commitCounter); }