001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/portal/portlet/modules/map/actions/portlets/ToolbarPortletPerform.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    package org.deegree.portal.portlet.modules.map.actions.portlets;
037    
038    import java.io.InputStream;
039    import java.util.Properties;
040    
041    import javax.servlet.http.HttpServletRequest;
042    
043    import org.apache.jetspeed.portal.Portlet;
044    import org.apache.jetspeed.portal.PortletConfig;
045    import org.deegree.framework.util.BootLogger;
046    import org.deegree.framework.util.StringTools;
047    import org.deegree.i18n.Messages;
048    import org.deegree.portal.PortalException;
049    import org.deegree.portal.portlet.modules.actions.AbstractPortletPerform;
050    
051    /**
052     *
053     *
054     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
055     * @author last edited by: $Author: mschneider $
056     *
057     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
058     */
059    public class ToolbarPortletPerform extends AbstractPortletPerform {
060    
061        // init parameter of the portlet
062        public static final String INIT_BUTTONS = "buttons";
063    
064        public static final String INIT_ORIENTATION = "orientation";
065    
066        public static final String INIT_COLS = "columns";
067    
068        public static final String INIT_ROWS = "rows";
069    
070        private String imageBase = "./igeoportal/images/";
071    
072        private static Properties props = new Properties();
073        static {
074            try {
075                InputStream is = ToolbarPortletPerform.class.getResourceAsStream( "toolbar.properties" );
076                props.load( is );
077                is.close();
078            } catch ( Exception e ) {
079                BootLogger.logError( e.getMessage(), e );
080            }
081        }
082    
083        /**
084         * private constructor
085         *
086         * @param request
087         * @param portlet
088         */
089        private ToolbarPortletPerform( HttpServletRequest request, Portlet portlet ) {
090            super( request, portlet );
091        }
092    
093        /**
094         * returns an instance of
095         *
096         * @see MapWindowPortletPerform
097         * @param request
098         * @param portlet
099         * @return an instance of
100         * @see MapWindowPortletPerform
101         */
102        static ToolbarPortletPerform getInstance( HttpServletRequest request, Portlet portlet ) {
103            return new ToolbarPortletPerform( request, portlet );
104        }
105    
106        /**
107         * reads the init parameters of the ToolbarPortlet and writes them into the requests attributes.
108         *
109         * @throws PortalException
110         *
111         */
112        void readInitParameter()
113                                throws PortalException {
114            PortletConfig pc = portlet.getPortletConfig();
115            String tmp = pc.getInitParameter( INIT_BUTTONS );
116            if ( tmp == null ) {
117                throw new PortalException( "buttons init parameter must be set" );
118            }
119            String[] ar = StringTools.toArray( tmp, ";", false );
120            String[][] buttonList = new String[ar.length][];
121            for ( int i = 0; i < buttonList.length; i++ ) {
122                buttonList[i] = getButtonSrc( ar[i] );
123            }
124    
125            request.setAttribute( INIT_BUTTONS, buttonList );
126    
127            tmp = pc.getInitParameter( INIT_COLS );
128            if ( tmp != null ) {
129                request.setAttribute( INIT_COLS, new Integer( tmp ) );
130            } else {
131                request.setAttribute( INIT_COLS, new Integer( 99999 ) );
132            }
133            tmp = pc.getInitParameter( INIT_ROWS );
134            if ( tmp != null ) {
135                request.setAttribute( INIT_ROWS, new Integer( tmp ) );
136            } else {
137                request.setAttribute( INIT_ROWS, new Integer( 99999 ) );
138            }
139    
140            tmp = pc.getInitParameter( INIT_ORIENTATION );
141            if ( tmp == null || tmp.equals( "FLOW" ) ) {
142                request.setAttribute( INIT_ORIENTATION, "FLOW" );
143            } else if ( tmp.equals( "VERTICAL" ) ) {
144                request.setAttribute( INIT_ORIENTATION, "VERTICAL" );
145            } else if ( tmp.equals( "HORIZONTAL" ) ) {
146                request.setAttribute( INIT_ORIENTATION, "HORIZONTAL" );
147            } else {
148                throw new PortalException( "init parameter orientation must be " + "VERTICAL, HORIZONTAL or FLOW" );
149            }
150            request.setAttribute( "PORTLETID", portlet.getID() );
151        }
152    
153        /**
154         *
155         * @param button
156         * @return
157         */
158        private String[] getButtonSrc( String button ) {
159            String[] tmp = StringTools.toArray( button, "|", false );
160            button = tmp[0];
161            String[] src = new String[5];
162            src[3] = button;
163            src[4] = tmp[1];
164    
165            src[0] = imageBase + props.getProperty( button + ".released" );
166            src[1] = imageBase + props.getProperty( button + ".pressed" );
167            src[2] = props.getProperty( button + ".type" );
168    
169            if ( src[0] == null || src[1] == null || src[2] == null ) {
170                throw new RuntimeException( Messages.getMessage( "IGEO_PORTLET_MISSING_TOOLBAR_BT", button ) );
171            }
172    
173            return src;
174        }
175    
176    }