    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/portal/owswatch/configs/ServiceRequest.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.portal.owswatch.configs;
    038
    039    import java.io.BufferedReader;
    040    import java.io.File;
    041    import java.io.FileReader;
    042    import java.io.IOException;
    043    import java.io.Serializable;
    044    import java.util.List;
    045
    046    /**
    047     * Holds the information about a certain request of a certain service, which http methods, this request cn use and what
    048     * are its htmlKeys
    049     *
    050     * @author <a href="mailto:elmasry@lat-lon.de">Moataz Elmasry</a>
    051     * @author last edited by: $Author: jmays $
    052     *
    053     * @version $Revision: 20271 $, $Date: 2009-10-21 13:07:15 +0200 (Mi, 21. Okt 2009) $
    054     */
    055    public class ServiceRequest implements Serializable {
    056
    057        /**
    058         *
    059         */
    060        private static final long serialVersionUID = -7463404275670442560L;
    061
    062        private String name = null;
    063
    064        private String getSnippetPath = null;
    065
    066        private boolean canPOST = true;
    067
    068        private boolean canGET = true;
    069
    070        private String htmlText = null;
    071
    072        private List<String> htmlKeys = null;
    073
    074        // Reads an example xml file for a post request, will be used mainly for GetCapabilities. but its also possbible
    075        // to assign it to any request type
    076        private String postRequest = null;
    077
    078        /**
    079         * A constructor to instantate a class describing the service name and its corresponding html code that accepts
    080         * specific paramters for this request
    081         *
    082         * @param name
    083         * @param getSnippetPath
    084         * @param postSnippetPath
    085         * @param canPOST
    086         * @param canGET
    087         * @param htmlKeys
    088         * @throws IOException
    089         */
    090        public ServiceRequest( String name, String getSnippetPath, String postSnippetPath, boolean canPOST, boolean canGET,
    091                               List<String> htmlKeys ) throws IOException {
    092            this.name = name;
    093            this.canPOST = canPOST;
    094            this.canGET = canGET;
    095            this.htmlText = readFileToString( getSnippetPath );
    096            this.postRequest = readFileToString( postSnippetPath );
    097            this.htmlKeys = htmlKeys;
    098
    099        }
    100
    101        /**
    102         * Reads the html snippet file and save it as a String variable to be used later by the DHTML
    103         *
    104         * @param filePath
    105         * @return String
    106         * @throws IOException
    107         */
    108        protected String readFileToString( String filePath )
    109                                throws IOException {
    110
    111            if ( filePath == null || filePath.length() == 0 ) {
    112                // A Html Text is not necessary in all cases, ex. in case GetCapabilities there
    113                // are no extra fields
    114                return "";
    115            }
    116
    117            File file = new File( filePath );
    118            BufferedReader reader = new BufferedReader( new FileReader( file.getCanonicalFile() ) );
    119            String line = reader.readLine();
    120            StringBuilder builder = new StringBuilder( 500 );
    121            while ( line != null ) {
    122                builder.append( line );
    123                line = reader.readLine();
    124            }
    125            return builder.toString();
    126        }
    127
    128        /**
    129         * @return Request name, ex GetCapabilities
    130         */
    131        public String getName() {
    132            return name;
    133        }
    134
    135        /**
    136         * @return path to html code describing the parameters for this service
    137         */
    138        public String getValue() {
    139            return getSnippetPath;
    140        }
    141
    142        /**
    143         * @return can send GET Requests
    144         */
    145        public boolean isCanGET() {
    146            return canGET;
    147        }
    148
    149        /**
    150         * @return can send POST requests
    151         */
    152        public boolean isCanPOST() {
    153            return canPOST;
    154        }
    155
    156        /**
    157         * @return String
    158         */
    159        public String getHtmlText() {
    160            return htmlText;
    161        }
    162
    163        /**
    164         * @return List of HTML keys
    165         */
    166        public List<String> getHtmlKeys() {
    167            return htmlKeys;
    168        }
    169
    170        /**
    171         * Reads an example xml file for a post request, will be used mainly for GetCapabilities. but its also possbible to
    172         * assign it to any request type
    173         *
    174         * @return String
    175         */
    176        public String getPostRequest() {
    177            return postRequest;
    178        }
    179    }