001: //$HeadURL: $
002: /*---------------- FILE HEADER ------------------------------------------
003: This file is part of deegree.
004: Copyright (C) 2001-2008 by:
005: Department of Geography, University of Bonn
006: http://www.giub.uni-bonn.de/deegree/
007: lat/lon GmbH
008: http://www.lat-lon.de
009:
010: This library is free software; you can redistribute it and/or
011: modify it under the terms of the GNU Lesser General Public
012: License as published by the Free Software Foundation; either
013: version 2.1 of the License, or (at your option) any later version.
014: This library is distributed in the hope that it will be useful,
015: but WITHOUT ANY WARRANTY; without even the implied warranty of
016: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: Lesser General Public License for more details.
018: You should have received a copy of the GNU Lesser General Public
019: License along with this library; if not, write to the Free Software
020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: Contact:
022:
023: Andreas Poth
024: lat/lon GmbH
025: Aennchenstr. 19
026: 53177 Bonn
027: Germany
028: E-Mail: poth@lat-lon.de
029:
030: Prof. Dr. Klaus Greve
031: Department of Geography
032: University of Bonn
033: Meckenheimer Allee 166
034: 53115 Bonn
035: Germany
036: E-Mail: greve@giub.uni-bonn.de
037: ---------------------------------------------------------------------------*/
038:
039: package org.deegree.owscommon_1_1_0;
040:
041: import static org.deegree.framework.xml.XMLTools.getElements;
042: import static org.deegree.framework.xml.XMLTools.getNodeAsString;
043: import static org.deegree.framework.xml.XMLTools.getNodesAsStringList;
044: import static org.deegree.framework.xml.XMLTools.getRequiredElements;
045: import static org.deegree.ogcbase.CommonNamespaces.XLINK_PREFIX;
046:
047: import java.util.ArrayList;
048: import java.util.List;
049:
050: import org.deegree.framework.log.ILogger;
051: import org.deegree.framework.log.LoggerFactory;
052: import org.deegree.framework.util.Pair;
053: import org.deegree.framework.xml.XMLParsingException;
054: import org.deegree.i18n.Messages;
055: import org.w3c.dom.Element;
056:
057: /**
058: * <code>ManifestDocument</code> supplies methods for the parsing of a manifest type in ows 1.1.0.
059: *
060: * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
061: *
062: * @author last edited by: $Author:$
063: *
064: * @version $Revision:$, $Date:$
065: *
066: */
067: public class ManifestDocument extends CommonsDocument {
068: /**
069: *
070: */
071: private static final long serialVersionUID = -7314461220886459179L;
072:
073: private static ILogger LOG = LoggerFactory
074: .getLogger(ManifestDocument.class);
075:
076: /**
077: * @param manifestElement
078: * to parse the data from
079: * @return the manifest bean or <code>null</code> if the given element is <code>null</code>.
080: * @throws XMLParsingException
081: * if a parsing error occurred.
082: */
083: public Manifest parseManifestType(Element manifestElement)
084: throws XMLParsingException {
085: if (manifestElement == null) {
086: return null;
087: }
088: BasicIdentification basicManifestIdentification = parseBasicIdentificationType(manifestElement);
089: List<Element> referenceGroupElements = getRequiredElements(
090: manifestElement, PRE_OWS + "ReferenceGroup", nsContext);
091: List<ReferenceGroup> referenceGroup = new ArrayList<ReferenceGroup>();
092: for (Element elem : referenceGroupElements) {
093: ReferenceGroup tmp = parseReferenceGroup(elem);
094: if (tmp != null) {
095: referenceGroup.add(tmp);
096: }
097: }
098: return new Manifest(basicManifestIdentification, referenceGroup);
099: }
100:
101: /**
102: * @param referenceGroup to be parsed
103: * @return the bean representation or <code>null</code> if the given element is <code>null</code>.
104: * @throws XMLParsingException if the element could not be parsed.
105: */
106: protected ReferenceGroup parseReferenceGroup(Element referenceGroup)
107: throws XMLParsingException {
108: if (referenceGroup == null) {
109: return null;
110: }
111: BasicIdentification basicRGId = parseBasicIdentificationType(referenceGroup);
112: List<Element> referenceElements = getElements(referenceGroup,
113: PRE_OWS + "Reference", nsContext);
114: List<Reference> references = new ArrayList<Reference>();
115: if (referenceElements == null || referenceElements.size() == 0) {
116: LOG
117: .logWarning(Messages
118: .getMessage("WCTS_REFERENCE_SUBSTITION_NOT_SUPPORTED"));
119: } else {
120: for (Element refElement : referenceElements) {
121: Reference tmp = parseReferenceType(refElement);
122: if (tmp != null) {
123: references.add(tmp);
124: }
125: }
126: }
127: return new ReferenceGroup(basicRGId, references);
128:
129: }
130:
131: /**
132: * @param referenceElement to be parsed.
133: * @return the bean representation or <code>null</code> if the given element is <code>null</code>.
134: * @throws XMLParsingException if the element could not be parsed.
135: */
136: protected Reference parseReferenceType(Element referenceElement)
137: throws XMLParsingException {
138: if (referenceElement == null) {
139: return null;
140: }
141: String hrefAttribute = referenceElement.getAttributeNS(XLNNS
142: .toASCIIString(), "href");
143: if (hrefAttribute == null || "".equals(hrefAttribute.trim())) {
144: throw new XMLParsingException(Messages.getMessage(
145: "OWS_MISSING_REQUIRED_ATTRIBUTE", XLINK_PREFIX
146: + ":href", PRE_OWS + "Reference"));
147: }
148: String roleAttribute = referenceElement.getAttributeNS(XLNNS
149: .toASCIIString(), "role");
150: String typeAttribute = referenceElement.getAttribute("type");
151: Pair<String, String> identifier = parseIdentifier(referenceElement);
152: List<String> abstracts = getNodesAsStringList(referenceElement,
153: PRE_OWS + "Abstract", nsContext);
154: String format = getNodeAsString(referenceElement, PRE_OWS
155: + "Format", nsContext, null);
156: List<Pair<String, String>> metadatas = parseMetadatas(getElements(
157: referenceElement, PRE_OWS + "Metadata", nsContext));
158: return new Reference(hrefAttribute, roleAttribute,
159: typeAttribute, identifier, abstracts, format, metadatas);
160: }
161:
162: }
|