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