001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/owscommon_new/XMLFactory.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 by:
006: EXSE, Department of Geography, University of Bonn
007: http://www.giub.uni-bonn.de/deegree/
008: lat/lon GmbH
009: http://www.lat-lon.de
010:
011: This library is free software; you can redistribute it and/or
012: modify it under the terms of the GNU Lesser General Public
013: License as published by the Free Software Foundation; either
014: version 2.1 of the License, or (at your option) any later version.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: Contact:
026:
027: Andreas Poth
028: lat/lon GmbH
029: Aennchenstr. 19
030: 53115 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Prof. Dr. Klaus Greve
035: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: greve@giub.uni-bonn.de
041:
042:
043: ---------------------------------------------------------------------------*/
044: package org.deegree.owscommon_new;
045:
046: import java.net.URI;
047: import java.util.List;
048:
049: import org.deegree.datatypes.Code;
050: import org.deegree.datatypes.values.TypedLiteral;
051: import org.deegree.framework.xml.XMLTools;
052: import org.deegree.model.metadata.iso19115.CitedResponsibleParty;
053: import org.deegree.model.metadata.iso19115.Constraints;
054: import org.deegree.model.metadata.iso19115.Keywords;
055: import org.deegree.model.metadata.iso19115.OnlineResource;
056: import org.deegree.ogcbase.CommonNamespaces;
057: import org.w3c.dom.Element;
058:
059: /**
060: * <code>XMLFactory</code> for generation of Capabilities XML documents according to the OWS
061: * common specification 1.0.0.
062: *
063: * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
064: * @author last edited by: $Author: apoth $
065: *
066: * @version 2.0, $Revision: 9346 $, $Date: 2007-12-27 08:39:07 -0800 (Thu, 27 Dec 2007) $
067: *
068: * @since 2.0
069: */
070:
071: public class XMLFactory extends org.deegree.ogcbase.XMLFactory {
072:
073: private static URI OWS = CommonNamespaces.OWSNS;
074:
075: private static String POWS = CommonNamespaces.OWS_PREFIX + ":";
076:
077: /**
078: * Exports the given capabilities as XML.
079: *
080: * @param root
081: * the root capabilities element according to the specification of the service
082: * @param caps
083: */
084: public static void appendBaseCapabilities(Element root,
085: OWSCommonCapabilities caps) {
086: ServiceIdentification identification = caps
087: .getServiceIdentification();
088: if (identification != null)
089: appendServiceIdentification(root, identification);
090:
091: ServiceProvider provider = caps.getServiceProvider();
092: if (provider != null)
093: appendServiceProvider(root, provider);
094:
095: OperationsMetadata metadata = caps.getOperationsMetadata();
096: if (metadata != null)
097: appendOperationsMetadata(root, metadata);
098:
099: root.setAttribute("version", caps.getVersion());
100:
101: String updateSequence = caps.getUpdateSequence();
102: if (updateSequence != null)
103: root.setAttribute("updateSequence", updateSequence);
104: }
105:
106: /**
107: * Appends a <code>ServiceIdentification</code> object as XML.
108: *
109: * @param root
110: * @param identification
111: */
112: public static void appendServiceIdentification(Element root,
113: ServiceIdentification identification) {
114: Element elem = XMLTools.appendElement(root, OWS, POWS
115: + "ServiceIdentification");
116:
117: String title = identification.getTitle();
118: if (title != null)
119: XMLTools.appendElement(elem, OWS, POWS + "Title", title);
120:
121: String abstractString = identification.getAbstractString();
122: if (abstractString != null)
123: XMLTools.appendElement(elem, OWS, POWS + "Abstract",
124: abstractString);
125:
126: List<Keywords> keywords = identification.getKeywords();
127: for (Keywords keys : keywords)
128: org.deegree.model.metadata.iso19115.XMLFactory
129: .appendKeywords(elem, keys);
130:
131: Code serviceType = identification.getServiceType();
132: if (serviceType != null)
133: org.deegree.model.metadata.iso19115.XMLFactory.appendCode(
134: elem, "Code", serviceType);
135:
136: List<String> versions = identification.getServiceTypeVersions();
137: for (String version : versions)
138: XMLTools.appendElement(elem, OWS, POWS
139: + "ServiceTypeVersion", version);
140:
141: List<Constraints> accessConstraints = identification
142: .getAccessConstraints();
143: if (accessConstraints.size() > 0) {
144: // append the first fee data from the constraints, ignore the rest
145: String fees = accessConstraints.get(0).getFees();
146: XMLTools.appendElement(elem, OWS, POWS + "Fees", fees);
147:
148: for (Constraints constraints : accessConstraints)
149: org.deegree.model.metadata.iso19115.XMLFactory
150: .appendAccessConstraint(elem, constraints);
151: }
152: }
153:
154: /**
155: * Appends a <code>ServiceProvider</code> object as XML.
156: *
157: * @param root
158: * where to append
159: * @param provider
160: * the object to append
161: */
162: public static void appendServiceProvider(Element root,
163: ServiceProvider provider) {
164: Element elem = XMLTools.appendElement(root, OWS, POWS
165: + "ServiceProvider");
166:
167: String name = provider.getProviderName();
168: if (name != null)
169: XMLTools.appendElement(elem, OWS, POWS + "ProviderName",
170: name);
171:
172: OnlineResource resource = provider.getProviderSite();
173: if (resource != null) {
174: Element resElement = XMLTools.appendElement(elem, OWS, POWS
175: + "ProviderSite");
176: org.deegree.model.metadata.iso19115.XMLFactory
177: .appendOnlineResource(resElement, resource);
178: }
179:
180: CitedResponsibleParty party = provider.getServiceContact();
181: org.deegree.model.metadata.iso19115.XMLFactory
182: .appendCitedResponsibleParty(elem, party);
183: }
184:
185: /**
186: * Appends an <code>OperationsMetadata</code> object as XML.
187: *
188: * @param root
189: * where to append
190: * @param data
191: * what to append
192: */
193: public static void appendOperationsMetadata(Element root,
194: OperationsMetadata data) {
195: Element elem = XMLTools.appendElement(root, OWS, POWS
196: + "OperationsMetadata");
197:
198: List<Operation> operations = data.getOperations();
199: for (Operation operation : operations)
200: appendOperation(elem, operation);
201:
202: List<Parameter> parameters = data.getParameters();
203: for (Parameter parameter : parameters) {
204: if (parameter instanceof DomainType)
205: appendDomainType(elem, "Parameter",
206: (DomainType) parameter);
207: }
208:
209: List<DomainType> constraints = data.getConstraints();
210: for (DomainType constraint : constraints)
211: appendDomainType(elem, "Constraint", constraint);
212:
213: // extended capabilities are ignored
214: }
215:
216: /**
217: * Appends an <code>Operation</code> object as XML.
218: *
219: * @param root
220: * where to append
221: * @param operation
222: * what to append
223: */
224: public static void appendOperation(Element root, Operation operation) {
225: Element elem = XMLTools.appendElement(root, OWS, POWS
226: + "Operation");
227:
228: List<DCP> dcps = operation.getDCP();
229: for (DCP dcp : dcps)
230: appendDCP(elem, dcp);
231:
232: List<Parameter> parameters = operation.getParameters();
233: for (Parameter parameter : parameters) {
234: if (parameter instanceof DomainType)
235: appendDomainType(elem, "Parameter",
236: (DomainType) parameter);
237: }
238:
239: List<DomainType> constraints = operation.getConstraints();
240: for (DomainType constraint : constraints)
241: appendDomainType(elem, "Constraint", constraint);
242:
243: Object md = operation.getMetadata();
244: if (md instanceof List) {
245: List<?> metadata = (List) md;
246: for (Object obj : metadata) {
247: if (obj instanceof Metadata)
248: appendMetadata(elem, (Metadata) obj);
249: }
250: }
251:
252: elem
253: .setAttribute("name", operation.getName()
254: .getPrefixedName());
255: }
256:
257: /**
258: * Appends a <code>DCP</code> object as XML.
259: *
260: * @param root
261: * where to append
262: * @param dcp
263: * what to append
264: */
265: public static void appendDCP(Element root, DCP dcp) {
266: Element dcpElem = XMLTools.appendElement(root, OWS, POWS
267: + "DCP");
268:
269: if (dcp instanceof HTTP)
270: appendHTTP(dcpElem, (HTTP) dcp);
271: }
272:
273: /**
274: * Appends a <code>HTTP</code> object as XML.
275: *
276: * @param root
277: * where to append
278: * @param http
279: * what to append
280: */
281: public static void appendHTTP(Element root, HTTP http) {
282: Element elem = XMLTools.appendElement(root, OWS, POWS + "HTTP");
283:
284: List<HTTP.Type> types = http.getTypes();
285: List<List<DomainType>> constraints = http.getConstraints();
286: List<OnlineResource> links = http.getLinks();
287:
288: for (int i = 0; i < types.size(); ++i) {
289: String type = (types.get(i) == HTTP.Type.Get) ? "Get"
290: : "Post";
291: Element getpost = XMLTools.appendElement(elem, OWS, POWS
292: + type);
293: org.deegree.model.metadata.iso19115.XMLFactory
294: .appendOnlineResource(getpost, links.get(i));
295: List<DomainType> constraintList = constraints.get(i);
296: for (DomainType constraint : constraintList)
297: appendDomainType(getpost, "Constraint", constraint);
298: }
299: }
300:
301: /**
302: * Appends a <code>DomainType</code> object as XML.
303: *
304: * @param root
305: * where to append
306: * @param tagName
307: * under which name to append
308: * @param data
309: * what to append
310: */
311: public static void appendDomainType(Element root, String tagName,
312: DomainType data) {
313: Element elem = XMLTools
314: .appendElement(root, OWS, POWS + tagName);
315:
316: List<TypedLiteral> values = data.getValues();
317: for (TypedLiteral value : values)
318: XMLTools.appendElement(elem, OWS, POWS + "Value", value
319: .getValue());
320:
321: Object md = data.getMetadata();
322: if (md instanceof List) {
323: List<?> metadata = (List) md;
324: for (Object obj : metadata) {
325: if (obj instanceof Metadata)
326: appendMetadata(elem, (Metadata) obj);
327: }
328: }
329:
330: elem.setAttribute("name", data.getName().getPrefixedName());
331: }
332:
333: /**
334: * Appends a <code>Metadata</code> object as XML.
335: *
336: * @param root
337: * where to append
338: * @param data
339: * what to append
340: */
341: public static void appendMetadata(Element root, Metadata data) {
342: Element elem = XMLTools.appendElement(root, OWS, POWS
343: + "Metadata");
344: elem.setAttribute("about", data.getAbout().toASCIIString());
345: appendSimpleLinkAttributes(elem, data.getLink());
346: }
347:
348: }
|