List of usage examples for javax.xml.stream XMLStreamWriter writeEndDocument
public void writeEndDocument() throws XMLStreamException;
From source file:org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer.java
/** * Writes a document graph to the file given by {@link #getPath()}. * /*w ww. j a va 2 s. c o m*/ * @param graph */ public void writeDocumentGraph(SDocumentGraph graph) { XMLStreamWriter xml = null; try (OutputStream output = new FileOutputStream(path)) { xml = xmlFactory.createXMLStreamWriter(output, "UTF-8"); xml.writeStartDocument("1.0"); if (isPrettyPrint) { xml.writeCharacters("\n"); } writeDocumentGraph(xml, graph); xml.writeEndDocument(); } catch (XMLStreamException | IOException e) { throw new SaltResourceException("Cannot store document graph to file '" + getLocationStr() + "'. ", e); } finally { if (xml != null) { try { xml.flush(); xml.close(); } catch (XMLStreamException e) { throw new SaltResourceException("Cannot store document graph to file '" + getLocationStr() + "', because the opened stream is not closable. ", e); } } } }
From source file:org.corpus_tools.salt.util.VisJsVisualizer.java
private void writeHTML(File outputFolder) throws XMLStreamException, IOException { int nodeDist = 0; int sprLength = 0; double sprConstant = 0.0; try (OutputStream os = new FileOutputStream(new File(outputFolder, HTML_FILE)); FileOutputStream fos = new FileOutputStream(tmpFile)) { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLStreamWriter xmlWriter = outputFactory.createXMLStreamWriter(os, "UTF-8"); setNodeWriter(os);// ww w. j a va 2 s .c o m setEdgeWriter(fos); xmlWriter.writeStartDocument("UTF-8", "1.0"); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_HTML); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_HEAD); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_TITLE); xmlWriter.writeCharacters("Salt Document Tree"); xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_STYLE); xmlWriter.writeAttribute(ATT_TYPE, "text/css"); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeCharacters("body {" + NEWLINE + "font: 10pt sans;" + NEWLINE + "}" + NEWLINE + "#mynetwork {" + NEWLINE + "height: 90%;" + NEWLINE + "width: 90%;" + NEWLINE + "border: 1px solid lightgray; " + NEWLINE + "text-align: center;" + NEWLINE + "}" + NEWLINE + "#loadingBar {" + NEWLINE + "position:absolute;" + NEWLINE + "top:0px;" + NEWLINE + "left:0px;" + NEWLINE + "width: 0px;" + NEWLINE + "height: 0px;" + NEWLINE + "background-color:rgba(200,200,200,0.8);" + NEWLINE + "-webkit-transition: all 0.5s ease;" + NEWLINE + "-moz-transition: all 0.5s ease;" + NEWLINE + "-ms-transition: all 0.5s ease;" + NEWLINE + "-o-transition: all 0.5s ease;" + NEWLINE + "transition: all 0.5s ease;" + NEWLINE + "opacity:1;" + NEWLINE + "}" + NEWLINE + "#wrapper {" + NEWLINE + "position:absolute;" + NEWLINE + "width: 1200px;" + NEWLINE + "height: 90%;" + NEWLINE + "}" + NEWLINE + "#text {" + NEWLINE + "position:absolute;" + NEWLINE + "top:8px;" + NEWLINE + "left:530px;" + NEWLINE + "width:30px;" + NEWLINE + "height:50px;" + NEWLINE + "margin:auto auto auto auto;" + NEWLINE + "font-size:16px;" + NEWLINE + "color: #000000;" + NEWLINE + "}" + NEWLINE + "div.outerBorder {" + NEWLINE + "position:relative;" + NEWLINE + "top:400px;" + NEWLINE + "width:600px;" + NEWLINE + "height:44px;" + NEWLINE + "margin:auto auto auto auto;" + NEWLINE + "border:8px solid rgba(0,0,0,0.1);" + NEWLINE + "background: rgb(252,252,252); /* Old browsers */" + NEWLINE + "background: -moz-linear-gradient(top, rgba(252,252,252,1) 0%, rgba(237,237,237,1) 100%); /* FF3.6+ */" + NEWLINE + "background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(252,252,252,1)), color-stop(100%,rgba(237,237,237,1))); /* Chrome,Safari4+ */" + NEWLINE + "background: -webkit-linear-gradient(top, rgba(252,252,252,1) 0%,rgba(237,237,237,1) 100%); /* Chrome10+,Safari5.1+ */" + NEWLINE + "background: -o-linear-gradient(top, rgba(252,252,252,1) 0%,rgba(237,237,237,1) 100%); /* Opera 11.10+ */" + NEWLINE + "background: -ms-linear-gradient(top, rgba(252,252,252,1) 0%,rgba(237,237,237,1) 100%); /* IE10+ */" + NEWLINE + "background: linear-gradient(to bottom, rgba(252,252,252,1) 0%,rgba(237,237,237,1) 100%); /* W3C */" + NEWLINE + "filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fcfcfc', endColorstr='#ededed',GradientType=0 ); /* IE6-9 */" + NEWLINE + "border-radius:72px;" + NEWLINE + "box-shadow: 0px 0px 10px rgba(0,0,0,0.2);" + NEWLINE + "}" + NEWLINE + "#border {" + NEWLINE + "position:absolute;" + NEWLINE + "top:10px;" + NEWLINE + "left:10px;" + NEWLINE + "width:500px;" + NEWLINE + "height:23px;" + NEWLINE + "margin:auto auto auto auto;" + NEWLINE + "box-shadow: 0px 0px 4px rgba(0,0,0,0.2);" + NEWLINE + "border-radius:10px;" + NEWLINE + "}" + NEWLINE + "#bar {" + NEWLINE + "position:absolute;" + NEWLINE + "top:0px;" + NEWLINE + "left:0px;" + NEWLINE + "width:20px;" + NEWLINE + "height:20px;" + NEWLINE + "margin:auto auto auto auto;" + NEWLINE + "border-radius:6px;" + NEWLINE + "border:1px solid rgba(30,30,30,0.05);" + NEWLINE + "background: rgb(0, 173, 246); /* Old browsers */" + NEWLINE + "box-shadow: 2px 0px 4px rgba(0,0,0,0.4);" + NEWLINE + "}" + NEWLINE); xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_SCRIPT); xmlWriter.writeAttribute(ATT_SRC, VIS_JS_SRC); xmlWriter.writeAttribute(ATT_TYPE, "text/javascript"); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_SCRIPT); xmlWriter.writeAttribute(ATT_SRC, JQUERY_SRC); xmlWriter.writeAttribute(ATT_TYPE, "text/javascript"); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeEmptyElement(TAG_LINK); xmlWriter.writeAttribute(ATT_HREF, VIS_CSS_SRC); xmlWriter.writeAttribute(ATT_REL, "stylesheet"); xmlWriter.writeAttribute(ATT_TYPE, "text/css"); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_SCRIPT); xmlWriter.writeAttribute(ATT_TYPE, "text/javascript"); xmlWriter.writeCharacters(NEWLINE + "function frameSize() {" + NEWLINE + "$(document).ready(function() {" + NEWLINE + "function elementResize() {" + NEWLINE + "var browserWidth = $(window).width()*0.98;" + NEWLINE + "document.getElementById('mynetwork').style.width = browserWidth;" + NEWLINE + "}" + NEWLINE + "elementResize();" + NEWLINE + "$(window).bind(\"resize\", function(){" + NEWLINE + "elementResize();" + NEWLINE + "});" + NEWLINE + "});" + NEWLINE + "}" + NEWLINE); xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_SCRIPT); xmlWriter.writeAttribute(ATT_TYPE, "text/javascript"); xmlWriter.writeCharacters(NEWLINE + "function start(){" + NEWLINE + "loadSaltObjectAndDraw();" + NEWLINE + "frameSize();" + NEWLINE + "}" + NEWLINE + "var nodesJson = [];" + NEWLINE + "var edgesJson = [];" + NEWLINE + "var network = null;" + NEWLINE + "function loadSaltObjectAndDraw() {" + NEWLINE + "var nodesJson = " + NEWLINE); xmlWriter.flush(); try { buildJSON(); } catch (SaltParameterException e) { throw new SaltParameterException(e.getMessage()); } catch (SaltException e) { throw new SaltException(e.getMessage()); } if (nNodes < 20) { nodeDist = 120; sprConstant = 1.2; sprLength = 120; } else if (nNodes >= 20 && nNodes < 100) { nodeDist = 150; sprConstant = 1.1; sprLength = 160; } else if (nNodes >= 100 && nNodes < 400) { nodeDist = 180; sprConstant = 0.9; sprLength = 180; } else if (nNodes >= 400 && nNodes < 800) { nodeDist = 200; sprConstant = 0.6; sprLength = 200; } else { nodeDist = 250; sprConstant = 0.3; sprLength = 230; } ; // write nodes as array nodeWriter.flush(); xmlWriter.writeCharacters(";" + NEWLINE); xmlWriter.writeCharacters("var edgesJson = " + NEWLINE); xmlWriter.flush(); // write edges as array to tmp file edgeWriter.flush(); // copy edges from tmp file ByteStreams.copy(new FileInputStream(tmpFile), os); xmlWriter.writeCharacters(";" + NEWLINE); xmlWriter.writeCharacters("var nodeDist =" + nodeDist + ";" + NEWLINE); xmlWriter.writeCharacters("draw(nodesJson, edgesJson, nodeDist);" + NEWLINE + "}" + NEWLINE + "var directionInput = document.getElementById(\"direction\");" + NEWLINE + "function destroy() {" + NEWLINE + "if (network !== null) {" + NEWLINE + "network.destroy();" + NEWLINE + "network = null;" + NEWLINE + "}" + NEWLINE + "}" + NEWLINE + NEWLINE + "function draw(nodesJson, edgesJson, nodeDist) {" + NEWLINE + "destroy();" + NEWLINE + "var connectionCount = [];" + NEWLINE + "var nodes = [];" + NEWLINE + "var edges = [];" + NEWLINE + NEWLINE + "nodes = new vis.DataSet(nodesJson);" + NEWLINE + "edges = new vis.DataSet(edgesJson);" + NEWLINE + "var container = document.getElementById('mynetwork');" + NEWLINE + "var data = {" + NEWLINE + "nodes: nodes," + NEWLINE + "edges: edges" + NEWLINE + "};" + NEWLINE + "var options = {" + NEWLINE + "nodes:{" + NEWLINE + "shape: \"box\"" + NEWLINE + "}," + NEWLINE + "edges: {" + NEWLINE + "smooth: true," + NEWLINE + "arrows: {" + NEWLINE + "to: {" + NEWLINE + "enabled: true" + NEWLINE + "}" + NEWLINE + "}" + NEWLINE + "}," + NEWLINE + "interaction: {" + NEWLINE + "navigationButtons: true," + NEWLINE + "keyboard: true" + NEWLINE + "}," + NEWLINE + "layout: {" + NEWLINE + "hierarchical:{" + NEWLINE + "direction: directionInput.value" + NEWLINE + "}" + NEWLINE + "}," + NEWLINE + "physics: {" + NEWLINE + "hierarchicalRepulsion: {" + NEWLINE + "centralGravity: 0.8," + NEWLINE + "springLength: " + sprLength + "," + NEWLINE + "springConstant: " + sprConstant + "," + NEWLINE + "nodeDistance: nodeDist," + NEWLINE + "damping: 0.04" + NEWLINE + "}," + NEWLINE + "maxVelocity: 50," + NEWLINE + "minVelocity: 1," + NEWLINE + "solver: 'hierarchicalRepulsion'," + NEWLINE + "timestep: 0.5," + NEWLINE + "stabilization: {" + NEWLINE + "iterations: 1000" + NEWLINE + "}" + NEWLINE + "}" + NEWLINE + "}" + NEWLINE + ";" + NEWLINE + "network = new vis.Network(container, data, options);" + NEWLINE); if (withPhysics == true) { xmlWriter.writeCharacters("network.on(\"stabilizationProgress\", function(params) {" + NEWLINE + "var maxWidth = 496;" + NEWLINE + "var minWidth = 20;" + NEWLINE + "var widthFactor = params.iterations/params.total;" + NEWLINE + "var width = Math.max(minWidth,maxWidth * widthFactor);" + NEWLINE + "document.getElementById('loadingBar').style.opacity = 1;" + NEWLINE + "document.getElementById('bar').style.width = width + 'px';" + NEWLINE + "document.getElementById('text').innerHTML = Math.round(widthFactor*100) + '%';" + NEWLINE + "});" + NEWLINE + "network.on(\"stabilizationIterationsDone\", function() {" + NEWLINE + "document.getElementById('text').innerHTML = '100%';" + NEWLINE + "document.getElementById('bar').style.width = '496px';" + NEWLINE + "document.getElementById('loadingBar').style.opacity = 0;" + NEWLINE + "});" + NEWLINE); } xmlWriter.writeCharacters("}" + NEWLINE); // script xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); // head xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_BODY); xmlWriter.writeAttribute("onload", "start();"); xmlWriter.writeCharacters(NEWLINE); if (withPhysics == true) { xmlWriter.writeStartElement(TAG_DIV); xmlWriter.writeAttribute(ATT_ID, "wrapper"); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_DIV); xmlWriter.writeAttribute(ATT_ID, "loadingBar"); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_DIV); xmlWriter.writeAttribute(ATT_CLASS, "outerBorder"); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_DIV); xmlWriter.writeAttribute(ATT_ID, "text"); xmlWriter.writeCharacters("0%"); xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_DIV); xmlWriter.writeAttribute(ATT_ID, "border"); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_DIV); xmlWriter.writeAttribute(ATT_ID, "bar"); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); } xmlWriter.writeStartElement(TAG_H2); xmlWriter.writeCharacters("Dokument-Id: " + docId); xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_DIV); xmlWriter.writeAttribute(ATT_STYLE, TEXT_STYLE); xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement("p"); xmlWriter.writeEmptyElement(TAG_INPUT); xmlWriter.writeAttribute(ATT_TYPE, "button"); xmlWriter.writeAttribute(ATT_ID, "btn-UD"); xmlWriter.writeAttribute(ATT_VALUE, "Up-Down"); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeEmptyElement(TAG_INPUT); xmlWriter.writeAttribute(ATT_TYPE, "button"); xmlWriter.writeAttribute(ATT_ID, "btn-DU"); xmlWriter.writeAttribute(ATT_VALUE, "Down-Up"); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeEmptyElement(TAG_INPUT); xmlWriter.writeAttribute(ATT_TYPE, "hidden"); // TODO check the apostrophes xmlWriter.writeAttribute(ATT_ID, "direction"); xmlWriter.writeAttribute(ATT_VALUE, "UD"); xmlWriter.writeCharacters(NEWLINE); // p xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_DIV); xmlWriter.writeAttribute(ATT_ID, "mynetwork"); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_P); xmlWriter.writeAttribute(ATT_ID, "selection"); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeStartElement(TAG_SCRIPT); xmlWriter.writeAttribute(ATT_LANG, "JavaScript"); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeCharacters("var directionInput = document.getElementById(\"direction\");" + NEWLINE + "var btnUD = document.getElementById(\"btn-UD\");" + NEWLINE + "btnUD.onclick = function() {" + NEWLINE + "directionInput.value = \"UD\";" + NEWLINE + "start();" + NEWLINE + "};" + NEWLINE + "var btnDU = document.getElementById(\"btn-DU\");" + NEWLINE + "btnDU.onclick = function() {" + NEWLINE + "directionInput.value = \"DU\";" + NEWLINE + "start();" + NEWLINE + "};" + NEWLINE); xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); // div wrapper if (withPhysics == true) { xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); } // body xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); // html xmlWriter.writeEndElement(); xmlWriter.writeCharacters(NEWLINE); xmlWriter.writeEndDocument(); xmlWriter.flush(); xmlWriter.close(); nodeWriter.close(); edgeWriter.close(); } }
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. * //w w w . ja v a 2 s . c o m * @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.protocol.wps.client.wps100.ExecuteResponse100Reader.java
/** * <ul>//from www .j a v a 2s. c o m * <li>Precondition: cursor must point at the <code>START_ELEMENT</code> event (<wps:ComplexData>)</li> * <li>Postcondition: cursor points at the corresponding <code>END_ELEMENT</code> event (</wps:ComplexData>)</li> * </ul> * * @return * @throws XMLStreamException * @throws IOException */ private ExecutionOutput parseComplexOutput(CodeType id) throws XMLStreamException { ComplexFormat attribs = parseComplexAttributes(); StreamBufferStore tmpSink = new StreamBufferStore(); try { if (attribs.getMimeType().startsWith("text/xml") || attribs.getMimeType().startsWith("application/xml")) { XMLOutputFactory fac = XMLOutputFactory.newInstance(); fac.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true); XMLStreamWriter xmlWriter = fac.createXMLStreamWriter(tmpSink, "UTF-8"); XMLStreamUtils.nextElement(reader); xmlWriter.writeStartDocument("UTF-8", "1.0"); if (reader.getEventType() == START_ELEMENT) { XMLAdapter.writeElement(xmlWriter, reader); XMLStreamUtils.nextElement(reader); } else { LOG.debug("Response document contains empty complex data output '" + id + "'"); } xmlWriter.writeEndDocument(); xmlWriter.close(); } else { if ("base64".equals(attribs.getEncoding())) { String base64String = reader.getElementText(); byte[] bytes = Base64.decodeBase64(base64String); tmpSink.write(bytes); } else { LOG.warn("The encoding of binary data (found at response location " + reader.getLocation() + ") is not base64. Currently only for this format the decoding can be performed. Skipping the data."); } } tmpSink.close(); } catch (IOException e) { LOG.error(e.getMessage()); } return new ComplexOutput(id, tmpSink, attribs.getMimeType(), attribs.getEncoding(), attribs.getEncoding()); }
From source file:org.deegree.services.csw.exporthandling.EbrimGetCapabilitiesHandler.java
private void export(XMLStreamWriter writer, Set<Sections> sections, ServiceIdentificationType identification, ServiceProviderType provider) throws XMLStreamException { writer.writeStartElement(WRS_PREFIX, "Capabilities", WRS_NS); writer.writeNamespace(WRS_PREFIX, WRS_NS); writer.writeNamespace(OWS_PREFIX, OWS_NS); writer.writeNamespace(OGC_PREFIX, OGCNS); writer.writeNamespace(XLINK_PREFIX, XLN_NS); writer.writeNamespace(XSINS, XSI_PREFIX); writer.writeAttribute("version", "2.0.2"); writer.writeAttribute("schemaLocation", WRS_NS + " " + WRS_SCHEMA, XSINS); // ows:ServiceIdentification if (sections.isEmpty() || sections.contains(Sections.ServiceIdentification)) { gcHelper.exportServiceIdentification(writer, identification, "urn:ogc:serviceType:CatalogueService:2.0.2:HTTP:ebRIM", "2.0.2", "http://www.opengeospatial.org/ogcna"); }//from ww w.j ava 2 s . c o m // ows:ServiceProvider if (sections.isEmpty() || sections.contains(Sections.ServiceProvider)) { exportServiceProvider100Old(writer, provider); } // ows:OperationsMetadata if (sections.isEmpty() || sections.contains(Sections.OperationsMetadata)) { exportOperationsMetadata(writer, OGCFrontController.getHttpGetURL(), OGCFrontController.getHttpPostURL(), OWS_NS); } // mandatory FilterCapabilitiesExporter.export110(writer); writer.writeEndElement(); writer.writeEndDocument(); }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHandler.java
private void export202(XMLStreamWriter writer, Set<Sections> sections, ServiceIdentificationType identification, DeegreeServicesMetadataType mainControllerConf, DeegreeServiceControllerType mainConf) throws XMLStreamException { writer.writeStartElement(CSW_PREFIX, "Capabilities", CSW_202_NS); writer.writeNamespace(CSW_PREFIX, CSW_202_NS); writer.writeNamespace(OWS_PREFIX, OWS_NS); writer.writeNamespace(OGC_PREFIX, OGCNS); writer.writeNamespace(XLINK_PREFIX, XLN_NS); writer.writeNamespace(XSI_PREFIX, XSINS); writer.writeAttribute("version", "2.0.2"); writer.writeAttribute(XSINS, "schemaLocation", CSW_202_NS + " " + CSW_202_DISCOVERY_SCHEMA); // ows:ServiceIdentification if (sections.isEmpty() || sections.contains(Sections.ServiceIdentification)) { gcHelper.exportServiceIdentification(writer, identification, "CSW", "2.0.2", null); }/*from w w w. j a v a2 s.c om*/ // ows:ServiceProvider if (sections.isEmpty() || sections.contains(Sections.ServiceProvider)) { exportServiceProvider100Old(writer, mainControllerConf.getServiceProvider()); } // ows:OperationsMetadata if (sections.isEmpty() || sections.contains(Sections.OperationsMetadata)) { exportOperationsMetadata(writer, OGCFrontController.getHttpGetURL(), OGCFrontController.getHttpPostURL(), OWS_NS); } // mandatory FilterCapabilitiesExporter.export110(writer); writer.writeEndElement(); writer.writeEndDocument(); }
From source file:org.deegree.services.sos.SOSController.java
private void doGetFeatureOfInterest(GetFeatureOfInterest foi, HttpResponseBuffer response) throws IOException, XMLStreamException { XMLStreamWriter xmlWriter = response.getXMLWriter(); List<String> foiIDs = Arrays.asList(foi.getFoiID()); xmlWriter.writeStartElement(SA_PREFIX, "SamplingFeatureCollection", SA_NS); xmlWriter.writeNamespace(SA_PREFIX, SA_NS); xmlWriter.writeNamespace(XSI_PREFIX, XSINS); xmlWriter.writeNamespace(XLINK_PREFIX, XLNNS); xmlWriter.writeNamespace(GML_PREFIX, GMLNS); xmlWriter.writeAttribute(XSI_PREFIX, XSINS, "schemaLocation", "http://www.opengis.net/sampling/1.0 http://schemas.opengis.net/sampling/1.0.0/sampling.xsd"); // TODO a url should be specified in the xlink:href of sampledFeature xmlWriter.writeEmptyElement(SA_PREFIX, "sampledFeature", SA_NS); for (Offering offering : sosService.getAllOfferings()) { for (Procedure procedure : offering.getProcedures()) { if (foiIDs.contains(procedure.getFeatureOfInterestHref())) { Geometry procGeometry = procedure.getLocation(); if (procGeometry instanceof Point) { // TODO check if the procedure can have some other geometries // and if so, // handle them xmlWriter.writeStartElement(SA_PREFIX, "member", SA_NS); xmlWriter.writeStartElement(SA_PREFIX, "SamplingPoint", SA_NS); xmlWriter.writeStartElement(GML_PREFIX, "name", GMLNS); xmlWriter.writeCharacters(procedure.getFeatureOfInterestHref()); // TODO if the GetFeatureOfInterest does not provide a foi but a location instead, search // for all // sensors // inside that BBOX xmlWriter.writeEndElement(); // TODO a url should be specified in the xlink:href of sampledFeature xmlWriter.writeEmptyElement(SA_PREFIX, "sampledFeature", SA_NS); xmlWriter.writeStartElement(SA_PREFIX, "position", SA_NS); // exporting a gml:Point TODO use GML encoder xmlWriter.writeStartElement(GML_PREFIX, "Point", GMLNS); // have the last part of the foiID as the Point id attribute String[] foiParts = procedure.getFeatureOfInterestHref().split(":"); xmlWriter.writeAttribute(GML_PREFIX, GMLNS, "id", foiParts[foiParts.length - 1]); xmlWriter.writeStartElement(GML_PREFIX, "pos", GMLNS); ICRS foiCRS = null;/*from ww w . jav a 2 s .com*/ foiCRS = procGeometry.getCoordinateSystem(); xmlWriter.writeAttribute("srsName", foiCRS.getCode().toString()); Point p = (Point) procGeometry; xmlWriter.writeCharacters(p.get0() + " " + p.get1()); xmlWriter.writeEndElement(); // gml:pos xmlWriter.writeEndElement(); // gml:Point xmlWriter.writeEndElement(); // gml:position xmlWriter.writeEndElement(); // sa:SamplingPoint xmlWriter.writeEndElement(); // sa:member } } } } xmlWriter.writeEndElement(); // sa:SamplingFeatureCollection xmlWriter.writeEndDocument(); xmlWriter.flush(); }
From source file:org.deegree.services.wcs.WCSController.java
private void doGetCapabilities(GetCapabilities request, HttpServletRequest requestWrapper, HttpResponseBuffer response) throws IOException, XMLStreamException, OWSException { Set<Sections> sections = getSections(request); Version negotiateVersion = negotiateVersion(request); // if update sequence is given and matches the given update sequence an error should occur // http://cite.opengeospatial.org/OGCTestData/wcs/1.0.0/specs/03-065r6.html#7.2.1_Key-value_pair_encoding if (negotiateVersion.equals(VERSION_100)) { String updateSeq = request.getUpdateSequence(); int requestedUS = UPDATE_SEQUENCE - 1; try {//from w w w . j a v a2 s . com requestedUS = Integer.parseInt(updateSeq); } catch (NumberFormatException e) { // nothing to do, just ignore it. } if (requestedUS == UPDATE_SEQUENCE) { throw new OWSException("Update sequence may not be equal than server's current update sequence.", WCSConstants.ExeptionCode_1_0_0.CurrentUpdateSequence.name()); } else if (requestedUS > UPDATE_SEQUENCE) { throw new OWSException("Update sequence may not be higher than server's current update sequence.", WCSConstants.ExeptionCode_1_0_0.InvalidUpdateSequence.name()); } } XMLOutputFactory factory = XMLOutputFactory.newInstance(); factory.setProperty(IS_REPAIRING_NAMESPACES, true); response.setContentType("text/xml"); XMLStreamWriter xmlWriter = getXMLStreamWriter(response.getWriter()); if (negotiateVersion.equals(VERSION_100)) { Capabilities100XMLAdapter.export(xmlWriter, request, identification, provider, allowedOperations, sections, wcsService.getAllCoverages(), mainMetadataConf, mainControllerConf, xmlWriter, UPDATE_SEQUENCE); } else { // the 1.1.0 } xmlWriter.writeEndDocument(); xmlWriter.flush(); }
From source file:org.deegree.services.wms.controller.WMSController.java
private void getFeatureInfoSchema(Map<String, String> map, HttpResponseBuffer response) throws IOException { GetFeatureInfoSchema fis = new GetFeatureInfoSchema(map); List<FeatureType> schema = service.getSchema(fis); try {/* w ww .j a v a 2 s . c o m*/ response.setContentType("text/xml"); XMLStreamWriter writer = response.getXMLWriter(); // TODO handle multiple namespaces String namespace = "http://www.deegree.org/app"; if (!schema.isEmpty()) { namespace = schema.get(0).getName().getNamespaceURI(); } Map<String, String> nsToPrefix = new HashMap<String, String>(); if (namespace != null && !namespace.isEmpty()) { nsToPrefix.put("app", namespace); } new GMLAppSchemaWriter(GMLVersion.GML_2, namespace, null, nsToPrefix).export(writer, schema); writer.writeEndDocument(); } catch (XMLStreamException e) { LOG.error("Unknown error", e); } }
From source file:org.deegree.tools.services.wms.FeatureTypesToLayerTree.java
/** * @param args/* w ww . j a va 2 s . com*/ */ public static void main(String[] args) { Options options = initOptions(); // for the moment, using the CLI API there is no way to respond to a help argument; see // https://issues.apache.org/jira/browse/CLI-179 if (args.length == 0 || (args.length > 0 && (args[0].contains("help") || args[0].contains("?")))) { CommandUtils.printHelp(options, FeatureTypesToLayerTree.class.getSimpleName(), null, null); } XMLStreamWriter out = null; try { CommandLine line = new PosixParser().parse(options, args); String storeFile = line.getOptionValue("f"); String nm = new File(storeFile).getName(); String storeId = nm.substring(0, nm.length() - 4); FileOutputStream os = new FileOutputStream(line.getOptionValue("o")); XMLOutputFactory fac = XMLOutputFactory.newInstance(); out = new IndentingXMLStreamWriter(fac.createXMLStreamWriter(os)); out.setDefaultNamespace(ns); Workspace ws = new DefaultWorkspace(new File("nix")); ws.initAll(); DefaultResourceIdentifier<FeatureStore> identifier = new DefaultResourceIdentifier<FeatureStore>( FeatureStoreProvider.class, "unknown"); ws.add(new DefaultResourceLocation<FeatureStore>(new File(storeFile), identifier)); ws.prepare(identifier); FeatureStore store = ws.init(identifier, null); AppSchema schema = store.getSchema(); // prepare document out.writeStartDocument(); out.writeStartElement(ns, "deegreeWMS"); out.writeDefaultNamespace(ns); out.writeAttribute("configVersion", "0.5.0"); out.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); out.writeAttribute("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation", "http://www.deegree.org/services/wms http://schemas.deegree.org/wms/0.5.0/wms_configuration.xsd"); out.writeStartElement(ns, "ServiceConfiguration"); HashSet<FeatureType> visited = new HashSet<FeatureType>(); if (schema.getRootFeatureTypes().length == 1) { writeLayer(visited, out, schema.getRootFeatureTypes()[0], storeId); } else { out.writeCharacters("\n"); out.writeStartElement(ns, "UnrequestableLayer"); XMLAdapter.writeElement(out, ns, "Title", "Root Layer"); for (FeatureType ft : schema.getRootFeatureTypes()) { writeLayer(visited, out, ft, storeId); } out.writeEndElement(); out.writeCharacters("\n"); } out.writeEndElement(); out.writeEndElement(); out.writeEndDocument(); } catch (ParseException exp) { System.err.println(Messages.getMessage("TOOL_COMMANDLINE_ERROR", exp.getMessage())); CommandUtils.printHelp(options, FeatureTypesToLayerTree.class.getSimpleName(), null, null); } catch (ResourceInitException e) { LOG.info("The feature store could not be loaded: '{}'", e.getLocalizedMessage()); LOG.trace("Stack trace:", e); } catch (FileNotFoundException e) { LOG.info("A file could not be found: '{}'", e.getLocalizedMessage()); LOG.trace("Stack trace:", e); } catch (XMLStreamException e) { LOG.info("The XML output could not be written: '{}'", e.getLocalizedMessage()); LOG.trace("Stack trace:", e); } catch (FactoryConfigurationError e) { LOG.info("The XML system could not be initialized: '{}'", e.getLocalizedMessage()); LOG.trace("Stack trace:", e); } finally { if (out != null) { try { out.close(); } catch (XMLStreamException e) { LOG.trace("Stack trace:", e); } } } }