    001    //$HeadURL:
    002    /*----------------------------------------------------------------------------
    003     This file is part of deegree, http://deegree.org/
    004     Copyright (C) 2001-2010 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    package org.deegree.portal.cataloguemanager.control;
    037
    038    import java.io.IOException;
    039    import java.net.MalformedURLException;
    040    import java.net.URI;
    041    import java.net.URL;
    042    import java.util.ArrayList;
    043    import java.util.HashMap;
    044    import java.util.Iterator;
    045    import java.util.List;
    046    import java.util.Map;
    047
    048    import org.deegree.framework.xml.NamespaceContext;
    049    import org.deegree.framework.xml.XMLFragment;
    050    import org.deegree.framework.xml.XMLParsingException;
    051    import org.deegree.framework.xml.XMLTools;
    052    import org.deegree.ogcbase.CommonNamespaces;
    053    import org.w3c.dom.Element;
    054    import org.xml.sax.SAXException;
    055
    056    /**
    057     *
    058     *
    059     *
    060     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
    061     * @author last edited by: $Author: apoth $
    062     *
    063     * @version $Revision: 25557 $, $Date: 2010-07-27 18:00:13 +0200 (Di, 27. Jul 2010) $
    064     */
    065    public class CatalogueManagerConfiguration extends XMLFragment {
    066
    067        private static final long serialVersionUID = -4330651238416870990L;
    068
    069        private String catalogueURL;
    070
    071        private Map<String, String> templateURL = new HashMap<String, String>();
    072
    073        private String metadataSchema;
    074
    075        private Map<String, String> xPathes = new HashMap<String, String>();
    076
    077        private List<SpatialExtent> spatialExtents;
    078
    079        private List<String> searchableProperties = new ArrayList<String>();
    080
    081        private List<String> dateProperties = new ArrayList<String>();
    082
    083        private List<String> searchableCSW = new ArrayList<String>();
    084
    085        private List<RespPartyConfiguration> respParties;
    086
    087        private char[] ignoreCharacters;
    088
    089        private int stepSize;
    090
    091        private URL briefHTMLXSL;
    092
    093        private URL fullHTMLXSL;
    094
    095        private URL pdfXSL;
    096
    097        private static NamespaceContext nsContext = null;
    098        static {
    099            if ( nsContext == null ) {
    100                nsContext = CommonNamespaces.getNamespaceContext();
    101                nsContext.addNamespace( "md", URI.create( "http://www.deegree.org/cataloguemanager" ) );
    102            }
    103        }
    104
    105        /**
    106         * @param url
    107         * @throws IOException
    108         * @throws SAXException
    109         * @throws XMLParsingException
    110         */
    111        CatalogueManagerConfiguration( URL url ) throws IOException, SAXException, XMLParsingException {
    112            super( url );
    113            parseConfiguration();
    114        }
    115
    116        /**
    117         * @throws XMLParsingException
    118         * @throws MalformedURLException
    119         */
    120        private void parseConfiguration()
    121                                throws XMLParsingException, MalformedURLException {
    122            catalogueURL = XMLTools.getRequiredNodeAsString( getRootElement(),
    123                                                             "./md:CatalogueService/md:onlineResource/@xlink:href",
    124                                                             nsContext );
    125            metadataSchema = XMLTools.getRequiredNodeAsString( getRootElement(), "./md:CatalogueService/md:metadataSchema",
    126                                                               nsContext );
    127            List<Element> list = XMLTools.getElements( getRootElement(), "./md:Templates/md:Template", nsContext );
    128            for ( Element element : list ) {
    129                String level = XMLTools.getRequiredNodeAsString( element, "./@hierarchyLevel", nsContext );
    130                String template = XMLTools.getRequiredNodeAsString( element, "./md:onlineResource/@xlink:href", nsContext );
    131                templateURL.put( level, template );
    132            }
    133            list = XMLTools.getElements( getRootElement(), "./md:MD_Elements/md:element", nsContext );
    134            for ( Element element : list ) {
    135                String name = XMLTools.getRequiredNodeAsString( element, "./@name", nsContext );
    136                String value = XMLTools.getRequiredNodeAsString( element, "./text()", nsContext );
    137                xPathes.put( name, value );
    138            }
    139
    140            list = XMLTools.getElements( getRootElement(), "./md:BoundingBoxes/md:BBOX", nsContext );
    141            spatialExtents = new ArrayList<SpatialExtent>( list.size() );
    142            for ( Element element : list ) {
    143                String id = XMLTools.getRequiredNodeAsString( element, "./@id", nsContext );
    144                String name = XMLTools.getRequiredNodeAsString( element, "./@name", nsContext );
    145                String bbox = XMLTools.getStringValue( element );
    146                SpatialExtent se = new SpatialExtent();
    147                se.setBbox( bbox );
    148                se.setId( id );
    149                se.setName( name );
    150                spatialExtents.add( se );
    151            }
    152            parseResponsibleParties();
    153            parseSearchSection();
    154        }
    155
    156        /**
    157         * @throws XMLParsingException
    158         *
    159         */
    160        private void parseResponsibleParties()
    161                                throws XMLParsingException {
    162            List<Element> list = XMLTools.getElements( getRootElement(), "./md:ResponsibleParties/md:ResponsibleParty",
    163                                                       nsContext );
    164            respParties = new ArrayList<RespPartyConfiguration>( list.size() );
    165            for ( Element el : list ) {
    166                RespPartyConfiguration respParty = new RespPartyConfiguration();
    167                respParty.setDisplayName(  XMLTools.getRequiredNodeAsString( el, "md:DisplayName", nsContext ) );
    168                respParty.setIndividualName(  XMLTools.getRequiredNodeAsString( el, "md:IndividualName", nsContext ) );
    169                respParty.setOrganisationName(  XMLTools.getRequiredNodeAsString( el, "md:OrganisationName", nsContext ) );
    170                respParty.setStreet(  XMLTools.getRequiredNodeAsString( el, "md:Street", nsContext ) );
    171                respParty.setCity(  XMLTools.getRequiredNodeAsString( el, "md:City", nsContext ) );
    172                respParty.setCountry(  XMLTools.getRequiredNodeAsString( el, "md:Country", nsContext ) );
    173                respParty.setPostalCode(  XMLTools.getRequiredNodeAsString( el, "md:PostalCode", nsContext ) );
    174                respParty.setVoice( XMLTools.getRequiredNodeAsString( el, "md:Voice", nsContext ) );
    175                respParty.setFacsimile( XMLTools.getNodeAsString( el, "md:Facsimile", nsContext, "" ) );
    176                respParty.setEmail( XMLTools.getRequiredNodeAsString( el, "md:EMail", nsContext ) );
    177                respParties.add( respParty );
    178            }
    179        }
    180
    181        /**
    182         * @throws XMLParsingException
    183         * @throws MalformedURLException
    184         *
    185         */
    186        private void parseSearchSection()
    187                                throws XMLParsingException, MalformedURLException {
    188            String xpath = "md:Search/md:searchableProperties/md:Property";
    189            List<Element> elements = XMLTools.getRequiredElements( getRootElement(), xpath, nsContext );
    190            for ( Element element : elements ) {
    191                String s = '{' + element.getAttribute( "namespace" ) + "}:" + element.getAttribute( "name" );
    192                searchableProperties.add( s );
    193            }
    194            xpath = "md:Search/md:dateProperties/md:Property";
    195            elements = XMLTools.getRequiredElements( getRootElement(), xpath, nsContext );
    196            for ( Element element : elements ) {
    197                String s = '{' + element.getAttribute( "namespace" ) + "}:" + element.getAttribute( "name" );
    198                dateProperties.add( s );
    199            }
    200            xpath = "md:Search/md:ignoreCharacters";
    201            String s = XMLTools.getNodeAsString( getRootElement(), xpath, nsContext, "" );
    202            ignoreCharacters = new char[s.length()];
    203            for ( int i = 0; i < s.length(); i++ ) {
    204                ignoreCharacters[i] = s.charAt( i );
    205            }
    206            xpath = "md:Search/md:stepSize";
    207            stepSize = XMLTools.getRequiredNodeAsInt( getRootElement(), xpath, nsContext );
    208
    209            xpath = "md:Search/md:searchableCSW/md:CSW";
    210            elements = XMLTools.getElements( getRootElement(), xpath, nsContext );
    211            for ( Element element : elements ) {
    212                searchableCSW.add( element.getAttribute( "xlink:href" ) );
    213            }
    214
    215            xpath = "md:Search/md:briefHTMLFormat/@xlink:href";
    216            s = XMLTools.getRequiredNodeAsString( getRootElement(), xpath, nsContext );
    217            briefHTMLXSL = resolve( s );
    218
    219            xpath = "md:Search/md:fullHTMLFormat/@xlink:href";
    220            s = XMLTools.getRequiredNodeAsString( getRootElement(), xpath, nsContext );
    221            fullHTMLXSL = resolve( s );
    222
    223            xpath = "md:Search/md:pdfFormat/@xlink:href";
    224            s = XMLTools.getNodeAsString( getRootElement(), xpath, nsContext, null );
    225            if ( s != null ) {
    226                pdfXSL = resolve( s );
    227            }
    228        }
    229
    230        /**
    231         *
    232         * @return list of available responsible parties
    233         */
    234        List<RespPartyConfiguration> getResponsibleParties() {
    235            return respParties;
    236        }
    237
    238        /**
    239         *
    240         * @return base URL to CSW
    241         */
    242        String getCatalogueURL() {
    243            return catalogueURL;
    244        }
    245
    246        /**
    247         *
    248         * @return metadata schema editing is performed on
    249         */
    250        String getMetadataSchema() {
    251            return metadataSchema;
    252        }
    253
    254        /**
    255         *
    256         * @param hierarchyLevel
    257         * @return URL to metadata template depending on hierarchy level
    258         */
    259        String getTemplateURL( String hierarchyLevel ) {
    260            return templateURL.get( hierarchyLevel );
    261        }
    262
    263        /**
    264         *
    265         * @param name
    266         * @return xPath assinged to the passed name
    267         */
    268        String getXPath( String name ) {
    269            return xPathes.get( name );
    270        }
    271
    272        /**
    273         *
    274         * @return list of names of all available xpath expressions
    275         */
    276        List<String> getXPathNames() {
    277            List<String> list = new ArrayList<String>( 50 );
    278            Iterator<String> iterator = xPathes.keySet().iterator();
    279            while ( iterator.hasNext() ) {
    280                list.add( iterator.next() );
    281            }
    282            return list;
    283        }
    284
    285        /**
    286         *
    287         * @return available spatial extents
    288         */
    289        List<SpatialExtent> getSpatialExtents() {
    290            return spatialExtents;
    291        }
    292
    293        public List<String> getSearchableCSW() {
    294            return searchableCSW;
    295        }
    296
    297        public List<String> getSearchableProperties() {
    298            return searchableProperties;
    299        }
    300
    301        public List<String> getDateProperties() {
    302            return dateProperties;
    303        }
    304
    305        public char[] getIgnoreCharacters() {
    306            return ignoreCharacters;
    307        }
    308
    309        public int getStepSize() {
    310            return stepSize;
    311        }
    312
    313        /**
    314         * @return the briefHTMLXSL
    315         */
    316        public URL getBriefHTMLXSL() {
    317            return briefHTMLXSL;
    318        }
    319
    320        /**
    321         * @return the fullHTMLXSL
    322         */
    323        public URL getFullHTMLXSL() {
    324            return fullHTMLXSL;
    325        }
    326
    327        /**
    328         * @return the pdfXSL
    329         */
    330        public URL getPdfXSL() {
    331            return pdfXSL;
    332        }
    333
    334    }