use of org.w3._2005.atom.TextType 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;
}
use of org.w3._2005.atom.TextType 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;
}
use of org.w3._2005.atom.TextType 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:*");
}
use of org.w3._2005.atom.TextType 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));
}
}
use of org.w3._2005.atom.TextType in project geotoolkit by Geomatys.
the class OwcXmlIO method read.
private static MapLayers read(final FeedType feed) throws JAXBException, FactoryException, DataStoreException {
final MapLayers context = MapBuilder.createContext();
for (Object o : feed.getAuthorOrCategoryOrContributor()) {
if (o instanceof JAXBElement) {
o = ((JAXBElement) o).getValue();
}
if (o instanceof TextType) {
final TextType title = (TextType) o;
title.getContent();
} else if (o instanceof WhereType) {
final WhereType where = (WhereType) o;
final EnvelopeType envelopeType = where.getEnvelope();
context.setAreaOfInterest(envelopeType);
} else if (o instanceof EntryType) {
final EntryType entry = (EntryType) o;
final MapItem item = readEntry(entry);
// find insert parent
final String[] path = item.getIdentifier().split("/");
MapLayers parent = context;
for (int i = 0; i < path.length - 1; i++) {
parent = (MapLayers) findItem(parent, path[i]);
}
item.setIdentifier(path[path.length - 1]);
parent.getComponents().add(item);
}
}
return context;
}
Aggregations