List of usage examples for javax.xml.stream XMLStreamWriter writeEndElement
public void writeEndElement() throws XMLStreamException;
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHandler.java
private void writeGetRecordsConstraints(XMLStreamWriter writer, String owsNS) throws XMLStreamException { writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "CONSTRAINTLANGUAGE"); writer.writeStartElement(owsNS, "Value"); writer.writeCharacters("Filter"); writer.writeEndElement();// Value writer.writeEndElement();// Parameter writer.writeStartElement(owsNS, "Constraint"); writer.writeAttribute("name", "SupportedISOQueryables"); for (String s : isoQueryables) { writer.writeStartElement(owsNS, "Value"); writer.writeCharacters(s);//from www.j a v a 2 s . c o m writer.writeEndElement();// Value } writer.writeEndElement();// Constraint writer.writeStartElement(owsNS, "Constraint"); writer.writeAttribute("name", "AdditionalQueryables"); for (String val : additionalQueryables) { writeElement(writer, owsNS, "Value", val); } writer.writeEndElement();// Constraint }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java
public void exportServiceIdentification(XMLStreamWriter writer, ServiceIdentificationType identification, String serviceType, String serviceTypeVersion, String serviceTypeCodeSpace) throws XMLStreamException { writer.writeStartElement("http://www.opengis.net/ows", Sections.ServiceIdentification.toString()); for (String oneTitle : identification.getTitle()) { writeElement(writer, "http://www.opengis.net/ows", "Title", oneTitle); }//from www.j av a 2s. co m for (String oneAbstract : identification.getAbstract()) { writeElement(writer, "http://www.opengis.net/ows", "Abstract", oneAbstract); } // keywords [0,n] exportKeywords(writer, identification.getKeywords()); if (serviceTypeCodeSpace != null) { writeElement(writer, "http://www.opengis.net/ows", "ServiceType", serviceType, null, null, "codeSpace", serviceTypeCodeSpace); } else { writeElement(writer, "http://www.opengis.net/ows", "ServiceType", serviceType); } writeElement(writer, "http://www.opengis.net/ows", "ServiceTypeVersion", serviceTypeVersion); // fees [1] String fees = identification.getFees(); if (fees == null || fees.length() == 0) { identification.setFees("NONE"); } fees = identification.getFees(); // fees = fees.replaceAll( "\\W", " " ); writeElement(writer, "http://www.opengis.net/ows", "Fees", fees); // accessConstraints [0,n] exportAccessConstraints(writer, identification); writer.writeEndElement(); }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java
/** * Writes the parameter and attributes for the mandatory DescribeRecord operation to the output. * // ww w. j a va 2s . c om * @param writer * to write the output * @param owsNS * the OWS namespace * @throws XMLStreamException */ public void writeDescribeRecordParameters(XMLStreamWriter writer, String owsNS, String[] typeNames, String[] outputFormats, String schemaLanguage) throws XMLStreamException { if (typeNames != null && typeNames.length > 0) { writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "typeName"); for (String typeName : typeNames) { writeValue(writer, owsNS, typeName); } writer.writeEndElement();// Parameter } writeOutputFormat(writer, owsNS, outputFormats); writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "schemaLanguage"); writeValue(writer, owsNS, schemaLanguage); writer.writeEndElement();// Parameter }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java
private void writeOutputFormat(XMLStreamWriter writer, String owsNS, String[] outputFormats) throws XMLStreamException { writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "outputFormat"); for (String outputFormat : outputFormats) { writeValue(writer, owsNS, outputFormat); }//w w w . ja va 2 s .com writer.writeEndElement();// Parameter }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java
/** * Writes the parameter and attributes for the mandatory GetCapabilities operation to the output. * //from www . j a v a 2 s. c om * @param writer * to write the output * @param owsNS * the OWS namespace * @throws XMLStreamException */ public void writeGetCapabilitiesParameters(XMLStreamWriter writer, String owsNS) throws XMLStreamException { writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "sections"); for (String value : parameterValues) { writer.writeStartElement(owsNS, "Value"); writer.writeCharacters(value); writer.writeEndElement();// Value } writer.writeEndElement();// Parameter // Constraints... }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java
/** * Writes the parameter and attributes for the mandatory GetRecords operation to the output. * //w ww . ja v a 2s . c o m * @param writer * @param owsNS * @param typeNames * the typeNames to write * @param outputFormats * the outputFormats to write * @param outputSchemas * the outputSchemas to write * @param elementSetNames * the elementSetNames to write, if null this parameter will be ignored, can be <code>null</code> * @throws XMLStreamException */ public void writeGetRecordsParameters(XMLStreamWriter writer, String owsNS, String[] typeNames, String[] outputFormats, String[] outputSchemas, String[] elementSetNames) throws XMLStreamException { writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "typeNames"); for (String typeName : typeNames) { writeValue(writer, owsNS, typeName); } writer.writeEndElement();// Parameter writeOutputFormat(writer, owsNS, outputFormats); writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "outputSchema"); for (String outputSchema : outputSchemas) { writeValue(writer, owsNS, outputSchema); } writer.writeEndElement();// Parameter writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "resultType"); writeValue(writer, owsNS, "hits"); writeValue(writer, owsNS, "results"); writeValue(writer, owsNS, "validate"); writer.writeEndElement();// Parameter if (elementSetNames != null && elementSetNames.length > 0) { writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "ElementSetName"); for (String elementSetName : elementSetNames) { writeValue(writer, owsNS, elementSetName); } writer.writeEndElement();// Parameter } }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java
/** * Writes the parameter and attributes for the mandatory GetRecordById operation to the output.<br> * In this case the optional transaction operation uses this writing to the output, as well. * /*from w w w. j a v a 2 s. c o m*/ * @param writer * @param owsNS * @param outputFormats * the outpurFormats to write * @param outputSchemas * the outputSChemas to write * @throws XMLStreamException */ public void writeGetRecordByIdParameters(XMLStreamWriter writer, String owsNS, String[] outputFormats, String[] outputSchemas) throws XMLStreamException { writeOutputFormat(writer, owsNS, outputFormats); writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "outputSchema"); for (String outputSchema : outputSchemas) { writeValue(writer, owsNS, outputSchema); } writer.writeEndElement(); // Parameter }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java
/** * write a list of keywords in csw 2.0.2 style. * // w w w.j a va 2 s . c o m * @param writer * @param keywords * @throws XMLStreamException */ private void exportKeywords(XMLStreamWriter writer, List<KeywordsType> keywords) throws XMLStreamException { if (!keywords.isEmpty()) { for (KeywordsType kwt : keywords) { if (kwt != null) { writer.writeStartElement("http://www.opengis.net/ows", "Keywords"); List<LanguageStringType> keyword = kwt.getKeyword(); for (LanguageStringType lst : keyword) { if (lst != null) { writeElement(writer, "http://www.opengis.net/ows", "Keyword", lst.getValue()); } // -> keyword [1, n] } // -> type [0,1] // exportCodeType( writer, kwt.getType() ); writer.writeEndElement();// WCS_100_NS, "keywords" ); } } } }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java
/** * @param writer/*from ww w . ja v 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); } } }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java
private void writeTemplateElement(XMLStreamWriter writer, XMLStreamReader inStream, Map<String, String> varToValue) throws XMLStreamException { if (inStream.getEventType() != XMLStreamConstants.START_ELEMENT) { throw new XMLStreamException("Input stream does not point to a START_ELEMENT event."); }// www . java 2s. c o m int openElements = 0; boolean firstRun = true; while (firstRun || openElements > 0) { firstRun = false; int eventType = inStream.getEventType(); switch (eventType) { case CDATA: { writer.writeCData(inStream.getText()); break; } case CHARACTERS: { String s = new String(inStream.getTextCharacters(), inStream.getTextStart(), inStream.getTextLength()); // TODO optimize for (String param : varToValue.keySet()) { String value = varToValue.get(param); s = s.replace(param, value); } writer.writeCharacters(s); break; } case END_ELEMENT: { writer.writeEndElement(); openElements--; break; } case START_ELEMENT: { if (inStream.getNamespaceURI() == "" || inStream.getPrefix() == DEFAULT_NS_PREFIX || inStream.getPrefix() == null) { writer.writeStartElement(inStream.getLocalName()); } else { if (writer.getNamespaceContext().getPrefix(inStream.getPrefix()) == "") { // TODO handle special cases for prefix binding, see // http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/javax/xml/namespace/NamespaceContext.html#getNamespaceURI(java.lang.String) writer.setPrefix(inStream.getPrefix(), inStream.getNamespaceURI()); } writer.writeStartElement(inStream.getPrefix(), inStream.getLocalName(), inStream.getNamespaceURI()); } // copy all namespace bindings for (int i = 0; i < inStream.getNamespaceCount(); i++) { String nsPrefix = inStream.getNamespacePrefix(i); String nsURI = inStream.getNamespaceURI(i); writer.writeNamespace(nsPrefix, nsURI); } // copy all attributes for (int i = 0; i < inStream.getAttributeCount(); i++) { String localName = inStream.getAttributeLocalName(i); String nsPrefix = inStream.getAttributePrefix(i); String value = inStream.getAttributeValue(i); String nsURI = inStream.getAttributeNamespace(i); if (nsURI == null) { writer.writeAttribute(localName, value); } else { writer.writeAttribute(nsPrefix, nsURI, localName, value); } } openElements++; break; } default: { break; } } if (openElements > 0) { inStream.next(); } } }