Search in sources :

Example 1 with FeedType

use of org.w3._2005.atom.FeedType in project geotoolkit by Geomatys.

the class OwcXmlIO method write.

public static void write(final Object output, final MapLayers context) throws PropertyException, JAXBException, FactoryException {
    final FeedType feed = write(context);
    final MarshallerPool pool = OwcMarshallerPool.getPool();
    final Marshaller marshaller = pool.acquireMarshaller();
    try {
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        if (output instanceof ContentHandler)
            marshaller.marshal(feed, (ContentHandler) output);
        else if (output instanceof File)
            marshaller.marshal(feed, (File) output);
        else if (output instanceof Node)
            marshaller.marshal(feed, (Node) output);
        else if (output instanceof OutputStream)
            marshaller.marshal(feed, (OutputStream) output);
        else if (output instanceof Result)
            marshaller.marshal(feed, (Result) output);
        else if (output instanceof Writer)
            marshaller.marshal(feed, (Writer) output);
        else if (output instanceof XMLEventWriter)
            marshaller.marshal(feed, (XMLEventWriter) output);
        else if (output instanceof XMLStreamWriter)
            marshaller.marshal(feed, (XMLStreamWriter) output);
        else {
            throw new JAXBException("Unsupported output type : " + output);
        }
    } finally {
        pool.recycle(marshaller);
    }
}
Also used : FeedType(org.w3._2005.atom.FeedType) Marshaller(javax.xml.bind.Marshaller) XMLEventWriter(javax.xml.stream.XMLEventWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Node(org.w3c.dom.Node) OutputStream(java.io.OutputStream) JAXBException(javax.xml.bind.JAXBException) MarshallerPool(org.apache.sis.xml.MarshallerPool) OwcMarshallerPool(org.geotoolkit.owc.xml.OwcMarshallerPool) File(java.io.File) ContentHandler(org.xml.sax.ContentHandler) XMLEventWriter(javax.xml.stream.XMLEventWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Writer(java.io.Writer) Result(javax.xml.transform.Result)

Example 2 with FeedType

use of org.w3._2005.atom.FeedType in project geotoolkit by Geomatys.

the class OwcXmlIO method read.

public static MapLayers read(final Object input) throws JAXBException, FactoryException, DataStoreException {
    final MarshallerPool pool = OwcMarshallerPool.getPool();
    final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
    final FeedType feed;
    try {
        final Object jax;
        if (input instanceof File)
            jax = unmarshaller.unmarshal((File) input);
        else if (input instanceof Node)
            jax = unmarshaller.unmarshal((Node) input);
        else if (input instanceof InputSource)
            jax = unmarshaller.unmarshal((InputSource) input);
        else if (input instanceof InputStream)
            jax = unmarshaller.unmarshal((InputStream) input);
        else if (input instanceof Source)
            jax = unmarshaller.unmarshal((Source) input);
        else if (input instanceof Reader)
            jax = unmarshaller.unmarshal((Reader) input);
        else if (input instanceof XMLEventReader)
            jax = unmarshaller.unmarshal((XMLEventReader) input);
        else if (input instanceof XMLStreamReader)
            jax = unmarshaller.unmarshal((XMLStreamReader) input);
        else {
            throw new JAXBException("Unsupported input type : " + input);
        }
        feed = (FeedType) ((JAXBElement) jax).getValue();
    } finally {
        pool.recycle(unmarshaller);
    }
    return read(feed);
}
Also used : InputSource(org.xml.sax.InputSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) XMLStreamReader(javax.xml.stream.XMLStreamReader) Reader(java.io.Reader) XMLEventReader(javax.xml.stream.XMLEventReader) MarshallerPool(org.apache.sis.xml.MarshallerPool) OwcMarshallerPool(org.geotoolkit.owc.xml.OwcMarshallerPool) JAXBElement(javax.xml.bind.JAXBElement) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource) FeedType(org.w3._2005.atom.FeedType) XMLEventReader(javax.xml.stream.XMLEventReader) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Example 3 with FeedType

use of org.w3._2005.atom.FeedType in project geotoolkit by Geomatys.

the class OwcXmlIO method write.

private static FeedType write(final MapLayers context) throws FactoryException {
    final FeedType feed = ATOM_FACTORY.createFeedType();
    final LinkType link = ATOM_FACTORY.createLinkType();
    link.setRel("profile");
    link.setHref("http://www.opengis.net/spec/owc-atom/1.0/req/core");
    link.setTitle(context.getIdentifier() == null ? "" : context.getIdentifier());
    feed.getAuthorOrCategoryOrContributor().add(ATOM_FACTORY.createFeedTypeLink(link));
    final TextType title = ATOM_FACTORY.createTextType();
    title.getContent().add(context.getIdentifier() == null ? "" : context.getIdentifier());
    feed.getAuthorOrCategoryOrContributor().add(ATOM_FACTORY.createFeedTypeTitle(title));
    final Envelope aoi = context.getAreaOfInterest();
    if (aoi != null) {
        final String ogc = IdentifiedObjects.lookupURN(aoi.getCoordinateReferenceSystem(), null);
        final WhereType where = GEORSS_FACTORY.createWhereType();
        final DirectPositionType lowerCorner = new DirectPositionType(aoi.getLowerCorner());
        final DirectPositionType upperCorner = new DirectPositionType(aoi.getUpperCorner());
        final EnvelopeType envelopeType = new EnvelopeType(null, lowerCorner, upperCorner, ogc);
        envelopeType.setSrsDimension(2);
        where.setEnvelope(envelopeType);
        feed.getAuthorOrCategoryOrContributor().add(GEORSS_FACTORY.createWhere(where));
    }
    for (final MapItem mapItem : context.getComponents()) {
        toEntry(null, mapItem, feed.getAuthorOrCategoryOrContributor());
    }
    return feed;
}
Also used : WhereType(org.geotoolkit.georss.xml.v100.WhereType) FeedType(org.w3._2005.atom.FeedType) EnvelopeType(org.geotoolkit.gml.xml.v311.EnvelopeType) DirectPositionType(org.geotoolkit.gml.xml.v311.DirectPositionType) LinkType(org.w3._2005.atom.LinkType) Envelope(org.opengis.geometry.Envelope) MapItem(org.apache.sis.portrayal.MapItem) TextType(org.w3._2005.atom.TextType)

Example 4 with FeedType

use of org.w3._2005.atom.FeedType in project geotoolkit by Geomatys.

the class OWCTest method owcMarshallTest.

@Test
public void owcMarshallTest() throws JAXBException, IOException, ParserConfigurationException, SAXException {
    final FeedType feed = new FeedType();
    final List<Object> entriesToSet = feed.getAuthorOrCategoryOrContributor();
    final IdType idFeed = new IdType();
    idFeed.setValue("Test id");
    entriesToSet.add(OBJ_ATOM_FACT.createEntryTypeId(idFeed));
    final TextType title = new TextType();
    title.getContent().add("Test");
    entriesToSet.add(OBJ_ATOM_FACT.createEntryTypeTitle(title));
    final String layerName = "testlayer";
    final String url = "http://myhost.com/constellation/WS/wms/test";
    final DirectPositionType lowerCorner = new DirectPositionType(-180.0, -90.0);
    final DirectPositionType upperCorner = new DirectPositionType(180.0, 90.0);
    final EnvelopeType envelope = new EnvelopeType(null, lowerCorner, upperCorner, "CRS:84");
    final WhereType where = new WhereType();
    where.setEnvelope(envelope);
    entriesToSet.add(OBJ_GEORSS_FACT.createWhere(where));
    final EntryType newEntry = new EntryType();
    final List<Object> entryThings = newEntry.getAuthorOrCategoryOrContent();
    final IdType idNewEntry = new IdType();
    idNewEntry.setValue("Web Map Service Layer");
    entryThings.add(OBJ_ATOM_FACT.createEntryTypeId(idNewEntry));
    final TextType titleNewEntry = new TextType();
    titleNewEntry.getContent().add(layerName);
    entryThings.add(OBJ_ATOM_FACT.createEntryTypeTitle(title));
    final org.w3._2005.atom.ContentType content = new org.w3._2005.atom.ContentType();
    content.setType("html");
    entryThings.add(OBJ_ATOM_FACT.createEntryTypeContent(content));
    final CategoryType category = new CategoryType();
    category.setScheme("http://www.opengis.net/spec/owc/active");
    category.setTerm("true");
    entryThings.add(OBJ_ATOM_FACT.createEntryTypeCategory(category));
    final OfferingType offering = new OfferingType();
    offering.setCode("http://www.opengis.net/spec/owc-atom/1.0/req/wms");
    final OperationType opCaps = new OperationType();
    opCaps.setCode("GetCapabilities");
    opCaps.setMethod(MethodCodeType.GET);
    final StringBuilder capsUrl = new StringBuilder();
    capsUrl.append(url).append("?REQUEST=GetCapabilities&SERVICE=WMS");
    opCaps.setHref(capsUrl.toString());
    offering.getOperationOrContentOrStyleSet().add(OBJ_OWC_FACT.createOfferingTypeOperation(opCaps));
    final OperationType opGetMap = new OperationType();
    opGetMap.setCode("GetMap");
    opGetMap.setMethod(MethodCodeType.GET);
    final String defStyle = "default";
    final StringBuilder getMapUrl = new StringBuilder();
    getMapUrl.append(url).append("?REQUEST=GetMap&SERVICE=WMS&FORMAT=image/png&TRANSPARENT=true&WIDTH=1024&HEIGHT=768&CRS=CRS:84&BBOX=").append("-5,40,15,60").append("&LAYERS=").append(layerName).append("&STYLES=").append(defStyle);
    opGetMap.setHref(getMapUrl.toString());
    offering.getOperationOrContentOrStyleSet().add(OBJ_OWC_FACT.createOfferingTypeOperation(opGetMap));
    entryThings.add(OBJ_OWC_FACT.createOffering(offering));
    entriesToSet.add(OBJ_ATOM_FACT.createEntry(newEntry));
    final Marshaller marsh = OwcMarshallerPool.getPool().acquireMarshaller();
    final StringWriter sw = new StringWriter();
    marsh.marshal(feed, sw);
    OwcMarshallerPool.getPool().recycle(marsh);
    assertXmlEquals(EXP_RESULT, sw.toString(), "xmlns:*");
}
Also used : EnvelopeType(org.geotoolkit.gml.xml.v311.EnvelopeType) Marshaller(javax.xml.bind.Marshaller) DirectPositionType(org.geotoolkit.gml.xml.v311.DirectPositionType) WhereType(org.geotoolkit.georss.xml.v100.WhereType) StringWriter(java.io.StringWriter) org.w3._2005.atom(org.w3._2005.atom) Test(org.junit.Test)

Example 5 with FeedType

use of org.w3._2005.atom.FeedType in project geotoolkit by Geomatys.

the class OpenSearchXmlFactory method buildFeed.

public static FeedType buildFeed(String id, String title, PersonType author, String source, Long totalResults, Long startIndex, Long itemsPerPage) {
    FeedType feed = new FeedType(id, title, author, source);
    final ObjectFactory factory = new ObjectFactory();
    feed.getPagingAttributes().add(factory.createTotalResults(totalResults));
    feed.getPagingAttributes().add(factory.createStartIndex(startIndex));
    feed.getPagingAttributes().add(factory.createItemsPerPage(itemsPerPage));
    return feed;
}
Also used : FeedType(org.w3._2005.atom.FeedType) ObjectFactory(org.geotoolkit.ops.xml.v110.ObjectFactory)

Aggregations

FeedType (org.w3._2005.atom.FeedType)5 WhereType (org.geotoolkit.georss.xml.v100.WhereType)3 EnvelopeType (org.geotoolkit.gml.xml.v311.EnvelopeType)3 File (java.io.File)2 JAXBElement (javax.xml.bind.JAXBElement)2 JAXBException (javax.xml.bind.JAXBException)2 Marshaller (javax.xml.bind.Marshaller)2 MapItem (org.apache.sis.portrayal.MapItem)2 MarshallerPool (org.apache.sis.xml.MarshallerPool)2 DirectPositionType (org.geotoolkit.gml.xml.v311.DirectPositionType)2 OwcMarshallerPool (org.geotoolkit.owc.xml.OwcMarshallerPool)2 EntryType (org.w3._2005.atom.EntryType)2 TextType (org.w3._2005.atom.TextType)2 Node (org.w3c.dom.Node)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Reader (java.io.Reader)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Unmarshaller (javax.xml.bind.Unmarshaller)1