001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/model/metadata/iso19115/ISO19115Document.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.model.metadata.iso19115;
045:
046: import java.net.MalformedURLException;
047: import java.net.URI;
048: import java.net.URL;
049: import java.util.ArrayList;
050: import java.util.List;
051:
052: import org.deegree.datatypes.Code;
053: import org.deegree.framework.xml.XMLFragment;
054: import org.deegree.framework.xml.XMLParsingException;
055: import org.deegree.framework.xml.XMLTools;
056: import org.deegree.ogcbase.CommonNamespaces;
057: import org.w3c.dom.Element;
058:
059: /**
060: * Parser class that can parse various elements defined in the OWS subset of the ISO 19115
061: * specification.
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: 9343 $, $Date: 2007-12-27 05:30:32 -0800 (Thu, 27 Dec 2007) $
067: *
068: * @since 2.0
069: */
070:
071: public class ISO19115Document extends XMLFragment {
072:
073: private static final long serialVersionUID = -5536802360612196021L;
074:
075: private static final String POWS = CommonNamespaces.OWS_PREFIX
076: + ":";
077:
078: private static final String PXLINK = CommonNamespaces.XLINK_PREFIX
079: + ":";
080:
081: /**
082: * @param root
083: * an element of type ows:ResponsiblePartySubsetType
084: * @return the data object
085: * @throws XMLParsingException
086: */
087: public CitedResponsibleParty parseCitedResponsibleParty(Element root)
088: throws XMLParsingException {
089: String individualName = XMLTools.getNodeAsString(root, POWS
090: + "IndividualName", nsContext, null);
091:
092: String positionName = XMLTools.getNodeAsString(root, POWS
093: + "PositionName", nsContext, null);
094:
095: Element roleElement = (Element) XMLTools.getNode(root, POWS
096: + "Role", nsContext);
097: RoleCode role = null;
098: if (roleElement != null)
099: role = parseRoleCode(roleElement);
100:
101: Element contactElement = (Element) XMLTools.getNode(root, POWS
102: + "ContactInfo", nsContext);
103: ContactInfo contactInfo = null;
104: if (contactElement != null)
105: contactInfo = parseContactInfo(contactElement);
106:
107: // why Lists/Arrays are necessary here is beyond my knowledge
108: List<String> name = new ArrayList<String>();
109: name.add(individualName);
110: List<String> pName = new ArrayList<String>();
111: pName.add(positionName);
112: List<RoleCode> roles = new ArrayList<RoleCode>();
113: roles.add(role);
114: List<ContactInfo> contactInfos = new ArrayList<ContactInfo>();
115: contactInfos.add(contactInfo);
116:
117: CitedResponsibleParty result = new CitedResponsibleParty(
118: contactInfos, name, null, pName, roles);
119: return result;
120: }
121:
122: /**
123: * @param root
124: * the ContactInfo element
125: * @return the <code>ContactInfo</code> data object
126: * @throws XMLParsingException
127: */
128: public ContactInfo parseContactInfo(Element root)
129: throws XMLParsingException {
130: Element phoneElement = (Element) XMLTools.getNode(root, POWS
131: + "Phone", nsContext);
132: Phone phone = null;
133: if (phoneElement != null)
134: phone = parsePhone(phoneElement);
135:
136: Address address = null;
137: Element addressElement = (Element) XMLTools.getNode(root, POWS
138: + "Address", nsContext);
139: if (addressElement != null)
140: address = parseAddress(addressElement);
141:
142: OnlineResource onlineResource = null;
143: Element onlineResourceElement = (Element) XMLTools.getNode(
144: root, POWS + "OnlineResource", nsContext);
145: if (onlineResourceElement != null)
146: onlineResource = parseOnlineResource(onlineResourceElement);
147:
148: String hoursOfService = XMLTools.getNodeAsString(root, POWS
149: + "HoursOfService", nsContext, null);
150: String contactInstructions = XMLTools.getNodeAsString(root,
151: POWS + "ContactInstructions", nsContext, null);
152:
153: ContactInfo result = new ContactInfo(address,
154: contactInstructions, hoursOfService, onlineResource,
155: phone);
156: return result;
157: }
158:
159: /**
160: * @param root
161: * the Address element
162: * @return the <code>Address</code> data object
163: * @throws XMLParsingException
164: */
165: public Address parseAddress(Element root)
166: throws XMLParsingException {
167: String[] deliveryPoint = XMLTools.getNodesAsStrings(root, POWS
168: + "DeliveryPoint", nsContext);
169: String city = XMLTools.getNodeAsString(root, POWS + "City",
170: nsContext, null);
171: String administrativeArea = XMLTools.getNodeAsString(root, POWS
172: + "AdministrativeArea", nsContext, null);
173: String postalCode = XMLTools.getNodeAsString(root, POWS
174: + "PostalCode", nsContext, null);
175: String country = XMLTools.getNodeAsString(root, POWS
176: + "Country", nsContext, null);
177: String[] emails = XMLTools.getNodesAsStrings(root, POWS
178: + "ElectronicMailAddress", nsContext);
179:
180: Address result = new Address(administrativeArea, city, country,
181: deliveryPoint, emails, postalCode);
182: return result;
183: }
184:
185: /**
186: * @param root
187: * the Phone element
188: * @return a <code>Phone</code> data object
189: * @throws XMLParsingException
190: */
191: public Phone parsePhone(Element root) throws XMLParsingException {
192: String[] voice = XMLTools.getNodesAsStrings(root, POWS
193: + "Voice", nsContext);
194:
195: String[] facsimile = XMLTools.getNodesAsStrings(root, POWS
196: + "Facsimile", nsContext);
197:
198: Phone result = new Phone(facsimile, voice);
199: return result;
200: }
201:
202: /**
203: * @param root
204: * the element containing the xlink attributes
205: * @return the <code>OnlineResource</data> data object
206: * @throws XMLParsingException
207: */
208: public OnlineResource parseOnlineResource(Element root)
209: throws XMLParsingException {
210: // This is just a preview version, not sure how to handle all the xlink attributes
211: // correctly.
212:
213: URL href = null;
214: String url = null;
215:
216: try {
217: url = XMLTools.getNodeAsString(root, "@" + PXLINK + "href",
218: nsContext, null);
219: if (url != null)
220: href = new URL(url);
221: } catch (MalformedURLException e) {
222: throw new XMLParsingException("'" + url
223: + "' is not a valid URL.");
224: }
225:
226: Linkage linkage = new Linkage(href);
227: OnlineResource result = new OnlineResource(linkage);
228: return result;
229: }
230:
231: /**
232: * @param root
233: * the Code element
234: * @return a <code>Code</code> data object
235: */
236: public Code parseCode(Element root) {
237: URI codeSpace = null;
238: try {
239: codeSpace = new URI(XMLTools.getAttrValue(root, null,
240: "codeSpace", null));
241: } catch (Exception e) {
242: // ignore codeSpace
243: }
244:
245: String code = XMLTools.getStringValue(root);
246:
247: if (codeSpace != null)
248: return new Code(code, codeSpace);
249: return new Code(code);
250: }
251:
252: /**
253: * @param root
254: * the Type element
255: * @return the <code>TypeCode</code> data object
256: */
257: public TypeCode parseTypeCode(Element root) {
258: Code code = parseCode(root);
259: // since the TypeCode class already existed, it is used. Deleting the TypeCode class and
260: // just using the Code class would be the better solution, though.
261: return new TypeCode(code.getCode(), code.getCodeSpace());
262: }
263:
264: /**
265: * @param root
266: * the Role element
267: * @return the <code>RoleCode</code> data object
268: */
269: public RoleCode parseRoleCode(Element root) {
270: Code code = parseCode(root);
271: // since the RoleCode class already existed, it is used. Deleting the RoleCode class and
272: // just using the Code class would be the better solution, though.
273: return new RoleCode(code.getCode());
274: }
275:
276: /**
277: * @param root
278: * the AccessConstraints element
279: * @param fee
280: * @return the <code>Constraints</code> object containing the parsed data
281: * @throws XMLParsingException
282: */
283: public Constraints parseConstraint(Element root, String fee)
284: throws XMLParsingException {
285: // please note that the same fee is used for all constraints
286:
287: List<String> constr = new ArrayList<String>();
288: String str = XMLTools.getRequiredNodeAsString(root, ".",
289: nsContext);
290: constr.add(str);
291:
292: Constraints result = new Constraints(fee, null, null, null,
293: constr, null, null, null);
294: return result;
295: }
296:
297: /**
298: * @param root
299: * the Keywords element
300: * @return the <code>Keywords</code> object
301: * @throws XMLParsingException
302: */
303: public Keywords parseKeywords(Element root)
304: throws XMLParsingException {
305: String[] keywords = XMLTools.getRequiredNodesAsStrings(root,
306: POWS + "Keyword", nsContext);
307: Element codeElem = (Element) XMLTools.getNode(root, POWS
308: + "Type", nsContext);
309: TypeCode type = null;
310: if (codeElem != null)
311: type = parseTypeCode(codeElem);
312:
313: Keywords result = null;
314:
315: // the thesaurus name is ignored at the moment, as it is omitted by the OWS specification as
316: // well
317: if (type != null)
318: result = new Keywords(keywords);
319: else
320: result = new Keywords(keywords, "", type);
321:
322: return result;
323: }
324:
325: }
|