private static void writeNamespacesAndNamespaceDeclaration( GetRecords getRecords, XMLStreamWriter writer ) throws XMLStreamException { writer.writeNamespace( CSW_202_PREFIX, CSW_202_NS ); writer.writeNamespace( XSI_PREFIX, XSINS ); writer.writeAttribute( XSINS, "schemaLocation", CSW_202_NS + " " + CSW_202_DISCOVERY_SCHEMA ); for ( QName tn : getRecords.getTypeNames() ) { writeNamespaceDeclaration( tn, writer ); } }
private static void writeQueryElementWithFilter( GetRecords getRecords, XMLStreamWriter writer ) throws XMLStreamException, UnknownCRSException, TransformationException { writer.writeStartElement( CSW_202_PREFIX, "Query", CSW_202_NS ); writer.writeAttribute( "typeNames", appendTypeNamesToString( getRecords ) ); writeElementSetNameElement( getRecords, writer ); writeFilterFilter( getRecords, writer ); }
private static String appendTypeNamesToString( GetRecords getRecords ) { String typeNames = ""; boolean isFirst = true; for ( QName tn : getRecords.getTypeNames() ) { if ( !isFirst ) typeNames += ','; if ( tn.getNamespaceURI() != null ) { typeNames += tn.getPrefix() + ":"; } typeNames += tn.getLocalPart(); isFirst = false; } return typeNames; }
/** * Writes a {@link GetRecords} request as XML, valid to http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd. * * @param getRecords * never <code>null</code> * @param writer * never <code>null</code> * @throws XMLStreamException * @throws UnknownCRSException * @throws TransformationException */ public static void export( GetRecords getRecords, XMLStreamWriter writer ) throws XMLStreamException, UnknownCRSException, TransformationException { writer.writeStartDocument(); writer.writeStartElement( CSW_202_PREFIX, "GetRecords", CSW_202_NS ); writeNamespacesAndNamespaceDeclaration( getRecords, writer ); writer.writeAttribute( "service", "CSW" ); writer.writeAttribute( "version", VERSION_202_STRING ); writer.writeAttribute( "outputSchema", getRecords.getOutputSchema() ); writer.writeAttribute( "outputFormat", getRecords.getOutputFormat() ); writer.writeAttribute( "resultType", getRecords.getResultType().toString() ); writer.writeAttribute( "startPosition", Integer.toString( getRecords.getStartPosition() ) ); writer.writeAttribute( "maxRecords", Integer.toString( getRecords.getMaxRecords() ) ); writeDistributedSearch( getRecords, writer ); writeQueryElementWithFilter( getRecords, writer ); }
public GetRecordsResponse getRecords( GetRecords getRecords ) throws IOException, XMLProcessingException, OWSExceptionReport, XMLStreamException { URL endPoint = getXMLPostUrl(); StreamBufferStore request = new StreamBufferStore(); try { XMLStreamWriter xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter( request ); GetRecordsXMLEncoder.export( getRecords, xmlWriter ); xmlWriter.close(); request.close(); } catch ( Throwable t ) { throw new RuntimeException( "Error creating XML request: " + getRecords, t ); } OwsHttpResponse response = httpClient.doPost( endPoint, "text/xml", request, null ); return new GetRecordsResponse( response ); }
public GetRecordsResponse getIsoRecords( int startPosition, int maxRecords, Filter constraint ) throws XMLProcessingException, IOException, OWSExceptionReport, XMLStreamException { GetRecords getRecords = new GetRecords( new Version( 2, 0, 2 ), startPosition, maxRecords, "application/xml", "http://www.isotc211.org/2005/gmd", Collections.singletonList( new QName(CommonNamespaces.ISOAP10GMDNS, "MD_Metadata", CommonNamespaces.ISOAP10GMD_PREFIX ) ), ResultType.results, ReturnableElement.full, constraint ); return this.getRecords( getRecords ); }
private static void writeDistributedSearch( GetRecords getRecords, XMLStreamWriter writer ) throws XMLStreamException { int hopCount = getRecords.getHopCount(); if ( hopCount > 0 ) { writer.writeStartElement( CSW_202_PREFIX, "DistributedSearch", CSW_202_NS ); writer.writeAttribute( "hopCount", Integer.toString( hopCount ) ); writer.writeEndElement(); } }
private static void writeFilterFilter( GetRecords getRecords, XMLStreamWriter writer ) throws XMLStreamException, UnknownCRSException, TransformationException { if ( getRecords.getConstraint() != null ) { writer.writeStartElement( CSW_202_PREFIX, "Constraint", CSW_202_NS ); writer.writeAttribute( "version", "1.1.0" ); Filter110XMLEncoder.export( getRecords.getConstraint(), writer ); writer.writeEndElement(); } }
private static void writeElementSetNameElement( GetRecords getRecords, XMLStreamWriter writer ) throws XMLStreamException { writer.writeStartElement( CSW_202_PREFIX, "ElementSetName", CSW_202_NS ); writer.writeCharacters( getRecords.getElementSetName().toString() ); writer.writeEndElement(); }
@Override public MetadataRecord next() { if ( !hasNext() ) { throw new NoSuchElementException(); } try { MetadataRecord record = MetadataRecordFactory.create( xmlStream ); return record; } finally { try { nextElement( xmlStream ); } catch ( XMLStreamException e ) { throw new XMLParsingException( xmlStream, e.getMessage() ); } } }
public GetRecordsResponse getIsoRecords( ResultType resultType, ReturnableElement elementSetName, Filter constraint ) throws IOException, XMLProcessingException, OWSExceptionReport, XMLStreamException { GetRecords getRecords = new GetRecords( new Version( 2, 0, 2 ), 10, 15, "application/xml", "http://www.isotc211.org/2005/gmd", Collections.singletonList( new QName( CommonNamespaces.ISOAP10GMDNS, "MD_Metadata", CommonNamespaces.ISOAP10GMD_PREFIX ) ), ResultType.results, ReturnableElement.full, null ); return this.getRecords( getRecords ); }
public GetRecordsResponse getRecords( int startPosition, int maxRecords, String outputFormat, String outputSchema, List<QName> typeNames, ResultType resultType, ReturnableElement elementSetName, Filter constraint ) throws IOException, XMLProcessingException, OWSExceptionReport, XMLStreamException { GetRecords getRecords = new GetRecords( new Version( 2, 0, 2 ), startPosition, maxRecords, outputFormat, outputSchema, typeNames, resultType, elementSetName, constraint ); return getRecords( getRecords ); }
public GetRecordsResponse getIsoRecords( int startPosition, int maxRecords, ResultType resultType, ReturnableElement elementSetName, Filter constraint ) throws IOException, XMLProcessingException, OWSExceptionReport, XMLStreamException { GetRecords getRecords = new GetRecords( new Version( 2, 0, 2 ), startPosition, maxRecords, "application/xml", "http://www.isotc211.org/2005/gmd", Collections.singletonList( new QName( CommonNamespaces.ISOAP10GMDNS, "MD_Metadata", CommonNamespaces.ISOAP10GMD_PREFIX ) ), ResultType.results, ReturnableElement.full, null ); return this.getRecords( getRecords ); }