List of usage examples for javax.xml.stream XMLInputFactory newInstance
public static XMLInputFactory newInstance() throws FactoryConfigurationError
From source file:org.deegree.metadata.iso.ISORecordTest.java
@Test public void testInstantiationFromXMLStream() throws XMLStreamException, FactoryConfigurationError { InputStream is = ISORecordTest.class.getResourceAsStream("datasetRecord.xml"); XMLStreamReader xmlStream = XMLInputFactory.newInstance().createXMLStreamReader(is); ISORecord record = new ISORecord(xmlStream); assertEquals("5E50884F-5549-2A7A-99E3-334234A887C81", record.getIdentifier()); }
From source file:org.deegree.metadata.iso.ISORecordTest.java
@Test public void testInstantiationFromXMLStreamOfBrokenRecord() throws XMLStreamException, FactoryConfigurationError { InputStream is = ISORecordTest.class.getResourceAsStream("datasetRecord_invalidDate.invalid"); XMLStreamReader xmlStream = XMLInputFactory.newInstance().createXMLStreamReader(is); ISORecord record = new ISORecord(xmlStream); boolean exception = false; try {/*w ww . j a v a 2s . co m*/ record.getIdentifier(); } catch (Exception e) { exception = true; } assertTrue(exception); }
From source file:org.deegree.metadata.iso.ISORecordTest.java
@Test public void testEvalFilterSubject() throws Exception { InputStream is = ISORecordTest.class.getResourceAsStream("datasetRecord.xml"); XMLStreamReader xmlStream = XMLInputFactory.newInstance().createXMLStreamReader(is); ISORecord record = new ISORecord(xmlStream); Literal<PrimitiveValue> literal = new Literal<PrimitiveValue>("Hydrography"); Operator operator = new PropertyIsEqualTo(new ValueReference("Subject", nsContext), literal, true, null); Filter filter = new OperatorFilter(operator); boolean isMatching = record.eval(filter); assertTrue(isMatching);/*from w w w .j av a 2s . c om*/ }
From source file:org.deegree.metadata.iso.ISORecordTest.java
@Test public void testEvalFilterSubjectUnmatching() throws Exception { InputStream is = ISORecordTest.class.getResourceAsStream("datasetRecord.xml"); XMLStreamReader xmlStream = XMLInputFactory.newInstance().createXMLStreamReader(is); ISORecord record = new ISORecord(xmlStream); Literal<PrimitiveValue> literal = new Literal<PrimitiveValue>("NotAKeywordInRecord"); Operator operator = new PropertyIsEqualTo(new ValueReference("Subject", nsContext), literal, true, null); Filter filter = new OperatorFilter(operator); boolean isMatching = record.eval(filter); Assert.assertFalse(isMatching);/* w ww. j a v a 2 s.c o m*/ }
From source file:org.deegree.metadata.iso.ISORecordTest.java
@Test public void testEvalFilterBbox() throws Exception { InputStream is = ISORecordTest.class.getResourceAsStream("datasetRecord.xml"); XMLStreamReader xmlStream = XMLInputFactory.newInstance().createXMLStreamReader(is); ISORecord record = new ISORecord(xmlStream); GeometryFactory geomFactory = new GeometryFactory(); ValueReference reference = new ValueReference("apiso:BoundingBox", nsContext); Operator operator = new BBOX(reference, geomFactory.createEnvelope(7.2, 49.30, 10.70, 53.70, CRSUtils.EPSG_4326)); Filter filter = new OperatorFilter(operator); boolean isMatching = record.eval(filter); assertTrue(isMatching);/* w w w . j a v a 2 s. c o m*/ }
From source file:org.deegree.metadata.iso.ISORecordTest.java
@Test(expected = FilterEvaluationException.class) public void testEvalFilterUnknownPropertyName() throws Exception { InputStream is = ISORecordTest.class.getResourceAsStream("datasetRecord.xml"); XMLStreamReader xmlStream = XMLInputFactory.newInstance().createXMLStreamReader(is); ISORecord record = new ISORecord(xmlStream); Literal<PrimitiveValue> literal = new Literal<PrimitiveValue>("Hydrography"); Operator operator = new PropertyIsEqualTo(new ValueReference("Unknown", nsContext), literal, true, null); Filter filter = new OperatorFilter(operator); boolean isMatching = record.eval(filter); assertTrue(isMatching);//from w ww. j a va 2 s .com }
From source file:org.deegree.metadata.MetadataRecordFactory.java
/** * Creates a {@link MetadataRecord} instance out a {@link XMLStreamReader}. The reader must point to the * START_ELEMENT of the record. After reading the record the stream points to the END_ELEMENT of the record. * /*from w w w .j a v a 2 s. c om*/ * @param xmlStream * xmlStream must point to the START_ELEMENT of the record, must not be <code>null</code> * @return a {@link MetadataRecord} instance, never <code>null</code> */ public static MetadataRecord create(XMLStreamReader xmlStream) { if (!xmlStream.isStartElement()) { throw new XMLParsingException(xmlStream, "XMLStreamReader does not point to a START_ELEMENT."); } String ns = xmlStream.getNamespaceURI(); ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLStreamWriter writer = null; XMLStreamReader recordAsXmlStream; InputStream in = null; try { writer = XMLOutputFactory.newInstance().createXMLStreamWriter(out); writer.writeStartDocument(); XMLAdapter.writeElement(writer, xmlStream); writer.writeEndDocument(); writer.close(); in = new ByteArrayInputStream(out.toByteArray()); recordAsXmlStream = XMLInputFactory.newInstance().createXMLStreamReader(in); } catch (XMLStreamException e) { throw new XMLParsingException(xmlStream, e.getMessage()); } catch (FactoryConfigurationError e) { throw new XMLParsingException(xmlStream, e.getMessage()); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } if (ISO_RECORD_NS.equals(ns)) { return new ISORecord(recordAsXmlStream); } if (RIM_NS.equals(ns)) { throw new UnsupportedOperationException( "Creating ebRIM records from XMLStreamReader is not implemented yet."); } if (DC_RECORD_NS.equals(ns)) { throw new UnsupportedOperationException( "Creating DC records from XMLStreamReader is not implemented yet."); } throw new IllegalArgumentException("Unknown / unsuppported metadata namespace '" + ns + "'."); }
From source file:org.deegree.metadata.persistence.ebrim.eo.EbrimEOMDStore.java
/** * Creates a new {@link EbrimEOMDStore} instance. * /*from w w w. j av a 2 s .c o m*/ * @param connId * id of the JDBC connection to use, must not be <code>null</code> * @param queriesDir * directory containing individual AdhocQuery files (*.xml), can be <code>null</code> * @param profile * RegistryPackage containing the profile informations, can be <code>null</code> * @param queryTimeout * number of milliseconds to allow for queries, or <code>0</code> (unlimited) * @throws ResourceInitException */ public EbrimEOMDStore(String connId, File queriesDir, RegistryPackage profile, Date lastModified, long queryTimeout, ResourceMetadata<MetadataStore<? extends MetadataRecord>> metadata, Workspace workspace) throws ResourceInitException { this.connId = connId; this.profile = profile; this.lastModified = lastModified; this.queryTimeout = queryTimeout; this.metadata = metadata; this.workspace = workspace; if (queriesDir != null) { File[] listFiles = queriesDir.listFiles(new FilenameFilter() { @Override public boolean accept(File arg0, String arg1) { return arg1.endsWith(".xml"); } }); if (listFiles != null) { for (File file : listFiles) { FileInputStream is = null; try { is = FileUtils.openInputStream(file); XMLStreamReader xmlStream = XMLInputFactory.newInstance().createXMLStreamReader(is); AdhocQuery query = new AdhocQuery(xmlStream); idToQuery.put(query.getId(), query); LOG.info("Found adhocQuery " + file + " with id " + query.getId()); } catch (Throwable t) { LOG.error(t.getMessage(), t); throw new ResourceInitException(t.getMessage()); } finally { try { if (is != null) { is.close(); } } catch (IOException e) { LOG.info("Could not close InputStream"); } } } } } }
From source file:org.deegree.services.controller.OGCFrontController.java
@Override public void init(ServletConfig config) throws ServletException { instance = this; try {//from w ww . j av a2 s. co m super.init(config); ctxPath = config.getServletContext().getContextPath(); LOG.info("--------------------------------------------------------------------------------"); DeegreeAALogoUtils.logInfo(LOG); LOG.info("--------------------------------------------------------------------------------"); LOG.info("deegree modules"); LOG.info("--------------------------------------------------------------------------------"); LOG.info(""); try { modulesInfo = extractModulesInfo(config.getServletContext()); } catch (Throwable t) { LOG.error("Unable to extract deegree module information: " + t.getMessage()); modulesInfo = emptyList(); } for (ModuleInfo moduleInfo : modulesInfo) { LOG.info("- " + moduleInfo.toString()); if ("deegree-services-commons".equals(moduleInfo.getArtifactId())) { version = moduleInfo.getVersion(); } } if (version == null) { version = "unknown"; } LOG.info(""); LOG.info("--------------------------------------------------------------------------------"); LOG.info("System info"); LOG.info("--------------------------------------------------------------------------------"); LOG.info(""); LOG.info("- java version " + System.getProperty("java.version") + " (" + System.getProperty("java.vendor") + ")"); LOG.info("- operating system " + System.getProperty("os.name") + " (" + System.getProperty("os.version") + ", " + System.getProperty("os.arch") + ")"); LOG.info("- container " + config.getServletContext().getServerInfo()); LOG.info("- webapp path " + ctxPath); LOG.info("- default encoding " + DEFAULT_ENCODING); LOG.info("- system encoding " + Charset.defaultCharset().displayName()); LOG.info("- temp directory " + defaultTMPDir); LOG.info("- XMLOutputFactory " + XMLOutputFactory.newInstance().getClass().getCanonicalName()); LOG.info("- XMLInputFactory " + XMLInputFactory.newInstance().getClass().getCanonicalName()); LOG.info(""); initWorkspace(); } catch (NoClassDefFoundError e) { LOG.error("Initialization failed!"); LOG.error("You probably forgot to add a required .jar to the WEB-INF/lib directory."); LOG.error("The resource that could not be found was '{}'.", e.getMessage()); LOG.debug("Stack trace:", e); throw new ServletException(e); } catch (Exception e) { LOG.error("Initialization failed!"); LOG.error("An unexpected error was caught, stack trace:", e); throw new ServletException(e); } finally { CONTEXT.remove(); } }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java
/** * @param writer// w ww.jav a 2 s .c om * the writer to write the extedned capabilities, never <code>null</code> * @param owsNS * the namespaceURI of the ExtendedCapabilities element * @param extendedCapabilities * the inputStream containing the extended capabilites, if <code>null</code> nothing is exported * @param varToValue * an optional list of key value pairs replaced in the extended capabilities, may be <code>null</code> * @throws XMLStreamException */ void exportExtendedCapabilities(XMLStreamWriter writer, String owsNS, InputStream extendedCapabilities, Map<String, String> varToValue) throws XMLStreamException { if (extendedCapabilities != null) { if (varToValue == null) varToValue = Collections.emptyMap(); writer.writeStartElement(owsNS, "ExtendedCapabilities"); try { XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(extendedCapabilities); reader.nextTag(); writeTemplateElement(writer, reader, varToValue); writer.writeEndElement(); } finally { IOUtils.closeQuietly(extendedCapabilities); } } }