Search in sources :

Example 1 with EntryType

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

the class OwcXmlIO method readEntry.

private static MapItem readEntry(final EntryType entry) throws JAXBException, FactoryException, DataStoreException {
    final List<Object> entryContent = entry.getAuthorOrCategoryOrContent();
    String layerName = "";
    String layerTitle = "";
    String layerAbstract = "";
    boolean visible = true;
    boolean selectable = true;
    double layerOpacity = 1.0;
    MapItem mapItem = null;
    MutableStyle baseStyle = null;
    MutableStyle selectionStyle = null;
    final List<MapItem> children = new ArrayList<>();
    for (Object o : entryContent) {
        QName name = null;
        if (o instanceof JAXBElement) {
            final JAXBElement jax = (JAXBElement) o;
            name = jax.getName();
            o = jax.getValue();
            if (GEOTK_FACTORY._Visible_QNAME.equals(name)) {
                visible = (Boolean) o;
            } else if (GEOTK_FACTORY._Selectable_QNAME.equals(name)) {
                selectable = (Boolean) o;
            } else if (GEOTK_FACTORY._Opacity_QNAME.equals(name)) {
                layerOpacity = (Double) o;
            }
        }
        if (o instanceof OfferingType) {
            final OfferingType offering = (OfferingType) o;
            for (OwcExtension ext : getExtensions()) {
                if (ext.getCode().equals(offering.getCode())) {
                    mapItem = ext.createLayer(offering);
                    break;
                }
            }
            // search for styles
            baseStyle = readStyle(offering, true);
            selectionStyle = readStyle(offering, false);
        } else if (o instanceof ContentType) {
            // decode children
            final ContentType content = (ContentType) o;
            final List<Object> contentContent = content.getContent();
            for (Object co : contentContent) {
                if (co instanceof JAXBElement) {
                    co = ((JAXBElement) o).getValue();
                }
                if (co instanceof EntryType) {
                    children.add(readEntry((EntryType) co));
                }
            }
        } else if (o instanceof IdType) {
            final IdType idType = (IdType) o;
            final String value = idType.getValue();
            layerName = value;
        } else if (o instanceof TextType) {
            final TextType tt = (TextType) o;
            if (ATOM_FACTORY._EntryTypeTitle_QNAME.equals(name)) {
                if (!tt.getContent().isEmpty()) {
                    layerTitle = (String) tt.getContent().get(0);
                }
            } else if (ATOM_FACTORY._EntryTypeSummary_QNAME.equals(name)) {
                if (!tt.getContent().isEmpty()) {
                    layerAbstract = (String) tt.getContent().get(0);
                }
            }
        }
    }
    if (mapItem == null) {
        mapItem = MapBuilder.createItem();
    } else if (mapItem instanceof MapLayer) {
        if (baseStyle != null) {
            ((MapLayer) mapItem).setStyle(baseStyle);
        }
        ((MapLayer) mapItem).setOpacity(layerOpacity);
    }
    mapItem.setIdentifier(layerName);
    mapItem.setTitle(layerTitle);
    mapItem.setAbstract(layerAbstract);
    mapItem.setVisible(visible);
    if (mapItem instanceof MapLayers) {
        ((MapLayers) mapItem).getComponents().addAll(children);
    } else if (!children.isEmpty()) {
        throw new IllegalArgumentException("MapLayer can not have children layers.");
    }
    return mapItem;
}
Also used : ContentType(org.geotoolkit.owc.xml.v10.ContentType) QName(javax.xml.namespace.QName) MapLayer(org.apache.sis.portrayal.MapLayer) ArrayList(java.util.ArrayList) JAXBElement(javax.xml.bind.JAXBElement) IdType(org.w3._2005.atom.IdType) TextType(org.w3._2005.atom.TextType) OfferingType(org.geotoolkit.owc.xml.v10.OfferingType) EntryType(org.w3._2005.atom.EntryType) MutableStyle(org.geotoolkit.style.MutableStyle) List(java.util.List) ArrayList(java.util.ArrayList) MapItem(org.apache.sis.portrayal.MapItem) MapLayers(org.apache.sis.portrayal.MapLayers)

Example 2 with EntryType

use of org.w3._2005.atom.EntryType 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 3 with EntryType

use of org.w3._2005.atom.EntryType in project ARLAS-server by gisaia.

the class AtomRecordMessageBodyWriter method writeTo.

@Override
public void writeTo(AbstractRecordType abstractRecordType, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> multivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException {
    FeedType feedType = new FeedType();
    ObjectFactory objectFactory = new ObjectFactory();
    EntryType entryType = new EntryType();
    AtomBuilder.setEntryType(abstractRecordType, feedType, entryType);
    JAXB.marshal(objectFactory.createEntry(entryType), outputStream);
}
Also used : FeedType(org.w3._2005.atom.FeedType) EntryType(org.w3._2005.atom.EntryType) ObjectFactory(org.w3._2005.atom.ObjectFactory)

Example 4 with EntryType

use of org.w3._2005.atom.EntryType in project airavata by apache.

the class StorageCreator method findServerName.

protected String findServerName(String besUrl, EndpointReferenceType smsEpr) throws Exception {
    int besIndex = besUrl.indexOf("StorageFactory?res");
    String ss = besUrl.substring(0, besIndex);
    ss = ss + "Registry";
    EndpointReferenceType eprt = WSUtilities.makeServiceEPR(ss, "default_registry", Registry.REGISTRY_PORT);
    RegistryClient registry = new RegistryClient(eprt, secProps);
    // first, check if server name is already in the EPR...
    String dn = WSUtilities.extractServerIDFromEPR(smsEpr);
    if (dn != null) {
        return dn;
    }
    // otherwise find a matching service in the registry
    String url = smsEpr.getAddress().getStringValue();
    if (url.contains("/services/"))
        url = url.substring(0, url.indexOf("/services"));
    if (log.isDebugEnabled())
        log.debug("Checking for services at " + url);
    for (EntryType entry : registry.listEntries()) {
        if (entry.getMemberServiceEPR().getAddress().getStringValue().startsWith(url)) {
            dn = WSUtilities.extractServerIDFromEPR(entry.getMemberServiceEPR());
            if (dn != null) {
                return dn;
            }
        }
    }
    return null;
}
Also used : EndpointReferenceType(org.w3.x2005.x08.addressing.EndpointReferenceType) EntryType(org.oasisOpen.docs.wsrf.sg2.EntryType) RegistryClient(de.fzj.unicore.wsrflite.xmlbeans.client.RegistryClient)

Example 5 with EntryType

use of org.w3._2005.atom.EntryType in project airavata by apache.

the class StorageCreator method findServerName.

protected String findServerName(String besUrl, EndpointReferenceType smsEpr) throws Exception {
    int besIndex = besUrl.indexOf("StorageFactory?res");
    String ss = besUrl.substring(0, besIndex);
    ss = ss + "Registry";
    EndpointReferenceType eprt = WSUtilities.makeServiceEPR(ss, "default_registry", Registry.REGISTRY_PORT);
    RegistryClient registry = new RegistryClient(eprt, secProps);
    // first, check if server name is already in the EPR...
    String dn = WSUtilities.extractServerIDFromEPR(smsEpr);
    if (dn != null) {
        return dn;
    }
    // otherwise find a matching service in the registry
    String url = smsEpr.getAddress().getStringValue();
    if (url.contains("/services/"))
        url = url.substring(0, url.indexOf("/services"));
    if (log.isDebugEnabled())
        log.debug("Checking for services at " + url);
    for (EntryType entry : registry.listEntries()) {
        if (entry.getMemberServiceEPR().getAddress().getStringValue().startsWith(url)) {
            dn = WSUtilities.extractServerIDFromEPR(entry.getMemberServiceEPR());
            if (dn != null) {
                return dn;
            }
        }
    }
    return null;
}
Also used : EndpointReferenceType(org.w3.x2005.x08.addressing.EndpointReferenceType) EntryType(org.oasisOpen.docs.wsrf.sg2.EntryType) RegistryClient(de.fzj.unicore.wsrflite.xmlbeans.client.RegistryClient)

Aggregations

EntryType (org.w3._2005.atom.EntryType)4 MapItem (org.apache.sis.portrayal.MapItem)3 MapLayers (org.apache.sis.portrayal.MapLayers)3 TextType (org.w3._2005.atom.TextType)3 RegistryClient (de.fzj.unicore.wsrflite.xmlbeans.client.RegistryClient)2 JAXBElement (javax.xml.bind.JAXBElement)2 MapLayer (org.apache.sis.portrayal.MapLayer)2 WhereType (org.geotoolkit.georss.xml.v100.WhereType)2 EnvelopeType (org.geotoolkit.gml.xml.v311.EnvelopeType)2 ContentType (org.geotoolkit.owc.xml.v10.ContentType)2 OfferingType (org.geotoolkit.owc.xml.v10.OfferingType)2 EntryType (org.oasisOpen.docs.wsrf.sg2.EntryType)2 IdType (org.w3._2005.atom.IdType)2 EndpointReferenceType (org.w3.x2005.x08.addressing.EndpointReferenceType)2 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Marshaller (javax.xml.bind.Marshaller)1 QName (javax.xml.namespace.QName)1 DirectPositionType (org.geotoolkit.gml.xml.v311.DirectPositionType)1