Search in sources :

Example 1 with OfferingType

use of org.geotoolkit.owc.xml.v10.OfferingType in project geotoolkit by Geomatys.

the class OwcXmlIO method readStyle.

private static MutableStyle readStyle(OfferingType offering, boolean def) throws JAXBException, FactoryException {
    final List<Object> content = offering.getOperationOrContentOrStyleSet();
    for (Object co : content) {
        if (co instanceof JAXBElement)
            co = ((JAXBElement) co).getValue();
        if (!(co instanceof StyleSetType))
            continue;
        final StyleSetType sst = (StyleSetType) co;
        if (sst.isDefault() != def)
            continue;
        final List<Object> ssc = sst.getNameOrTitleOrAbstract();
        for (Object ss : ssc) {
            if (ss instanceof JAXBElement)
                ss = ((JAXBElement) ss).getValue();
            if (!(ss instanceof ContentType))
                continue;
            final ContentType ct = (ContentType) ss;
            final List<Object> subcs = ct.getContent();
            for (Object subc : subcs) {
                if (subc instanceof JAXBElement)
                    subc = ((JAXBElement) subc).getValue();
                if (!(subc instanceof UserStyle))
                    continue;
                final StyleXmlIO io = new StyleXmlIO();
                return io.readStyle(subc, Specification.SymbologyEncoding.V_1_1_0);
            }
        }
    }
    return null;
}
Also used : UserStyle(org.geotoolkit.sld.xml.v110.UserStyle) ContentType(org.geotoolkit.owc.xml.v10.ContentType) StyleSetType(org.geotoolkit.owc.xml.v10.StyleSetType) StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO) JAXBElement(javax.xml.bind.JAXBElement)

Example 2 with OfferingType

use of org.geotoolkit.owc.xml.v10.OfferingType 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 3 with OfferingType

use of org.geotoolkit.owc.xml.v10.OfferingType in project geotoolkit by Geomatys.

the class OwcDataStoreExtension method createOffering.

@Override
public OfferingType createOffering(MapLayer mapLayer) {
    final OfferingType offering = new OfferingType();
    offering.setCode(getCode());
    // write the type name
    final List<Object> fieldList = offering.getOperationOrContentOrStyleSet();
    final String typeName = getTypeName(mapLayer);
    if (typeName != null) {
        fieldList.add(new ParameterType(KEY_DATANAME, String.class.getName(), typeName));
    }
    final String factoryName = getStoreFactoryName(mapLayer);
    if (factoryName != null) {
        fieldList.add(new ParameterType(KEY_STOREFACTORY, String.class.getName(), factoryName));
    }
    // write store creation parameters
    final Parameters params = Parameters.castOrWrap(getParams(mapLayer));
    final ParameterDescriptorGroup desc = params.getDescriptor();
    for (GeneralParameterDescriptor pdesc : desc.descriptors()) {
        if (pdesc instanceof ParameterDescriptor) {
            final Object value = params.getValue((ParameterDescriptor) pdesc);
            if (value != null) {
                fieldList.add(new ParameterType(pdesc.getName().getCode(), ((ParameterDescriptor) pdesc).getValueClass().getName(), String.valueOf(value)));
            }
        }
    }
    return offering;
}
Also used : OfferingType(org.geotoolkit.owc.xml.v10.OfferingType) Parameters(org.apache.sis.parameter.Parameters) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) ParameterDescriptor(org.opengis.parameter.ParameterDescriptor) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor)

Example 4 with OfferingType

use of org.geotoolkit.owc.xml.v10.OfferingType in project geotoolkit by Geomatys.

the class OwcXmlIO method toEntry.

private static void toEntry(String parentPath, final MapItem item, List entries) {
    final EntryType entry = ATOM_FACTORY.createEntryType();
    entries.add(ATOM_FACTORY.createFeedTypeEntry(entry));
    // store other informations
    final String name = ((parentPath != null) ? parentPath : "") + item.getIdentifier();
    final CharSequence title = item.getTitle();
    final CharSequence abstrat = item.getAbstract();
    if (name != null) {
        final IdType atom = new IdType();
        atom.setValue(name);
        entry.getAuthorOrCategoryOrContent().add(ATOM_FACTORY.createEntryTypeId(atom));
    }
    if (title != null) {
        final TextType atom = new TextType();
        atom.setType(TextTypeType.TEXT);
        atom.getContent().add(title.toString());
        entry.getAuthorOrCategoryOrContent().add(ATOM_FACTORY.createEntryTypeTitle(atom));
    }
    if (abstrat != null) {
        final TextType atom = new TextType();
        atom.setType(TextTypeType.TEXT);
        atom.getContent().add(abstrat.toString());
        entry.getAuthorOrCategoryOrContent().add(ATOM_FACTORY.createEntryTypeSummary(atom));
    }
    if (item instanceof MapLayer) {
        final MapLayer layer = (MapLayer) item;
        entry.getAuthorOrCategoryOrContent().add(GEOTK_FACTORY.createVisible(layer.isVisible()));
        entry.getAuthorOrCategoryOrContent().add(GEOTK_FACTORY.createOpacity(layer.getOpacity()));
        OfferingType offering = null;
        for (OwcExtension ext : getExtensions()) {
            if (ext.canHandle(layer)) {
                offering = ext.createOffering(layer);
                entry.getAuthorOrCategoryOrContent().add(OWC_FACTORY.createOffering(offering));
                break;
            }
        }
        // store styles
        if (offering != null) {
            if (layer.getStyle() != null) {
                final StyleSetType styleBase = toStyleSet(layer.getStyle(), true);
                offering.getOperationOrContentOrStyleSet().add(OWC_FACTORY.createOfferingTypeStyleSet(styleBase));
            }
        }
    } else if (item instanceof MapLayers) {
        final MapLayers mc = (MapLayers) item;
        final ContentType content = OWC_FACTORY.createContentType();
        content.setType(mc.getIdentifier());
        // encode children
        for (MapItem child : mc.getComponents()) {
            toEntry(name + "/", child, entries);
        }
        entry.getAuthorOrCategoryOrContent().add(OWC_FACTORY.createOfferingTypeContent(content));
    }
}
Also used : OfferingType(org.geotoolkit.owc.xml.v10.OfferingType) EntryType(org.w3._2005.atom.EntryType) ContentType(org.geotoolkit.owc.xml.v10.ContentType) StyleSetType(org.geotoolkit.owc.xml.v10.StyleSetType) MapLayer(org.apache.sis.portrayal.MapLayer) MapItem(org.apache.sis.portrayal.MapItem) IdType(org.w3._2005.atom.IdType) TextType(org.w3._2005.atom.TextType) MapLayers(org.apache.sis.portrayal.MapLayers)

Aggregations

ContentType (org.geotoolkit.owc.xml.v10.ContentType)3 OfferingType (org.geotoolkit.owc.xml.v10.OfferingType)3 JAXBElement (javax.xml.bind.JAXBElement)2 MapItem (org.apache.sis.portrayal.MapItem)2 MapLayer (org.apache.sis.portrayal.MapLayer)2 MapLayers (org.apache.sis.portrayal.MapLayers)2 StyleSetType (org.geotoolkit.owc.xml.v10.StyleSetType)2 EntryType (org.w3._2005.atom.EntryType)2 IdType (org.w3._2005.atom.IdType)2 TextType (org.w3._2005.atom.TextType)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 QName (javax.xml.namespace.QName)1 Parameters (org.apache.sis.parameter.Parameters)1 StyleXmlIO (org.geotoolkit.sld.xml.StyleXmlIO)1 UserStyle (org.geotoolkit.sld.xml.v110.UserStyle)1 MutableStyle (org.geotoolkit.style.MutableStyle)1 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)1 ParameterDescriptor (org.opengis.parameter.ParameterDescriptor)1 ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)1