Source Code Cross Referenced for StylesSelectAction.java in  » GIS » GeoServer » org » vfny » geoserver » action » data » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » GeoServer » org.vfny.geoserver.action.data 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org.  All rights reserved.
002:         * This code is licensed under the GPL 2.0 license, availible at the root
003:         * application directory.
004:         */
005:        package org.vfny.geoserver.action.data;
006:
007:        import org.apache.struts.Globals;
008:        import org.apache.struts.action.ActionError;
009:        import org.apache.struts.action.ActionErrors;
010:        import org.apache.struts.action.ActionForm;
011:        import org.apache.struts.action.ActionForward;
012:        import org.apache.struts.action.ActionMapping;
013:        import org.apache.struts.util.MessageResources;
014:        import org.vfny.geoserver.action.ConfigAction;
015:        import org.vfny.geoserver.action.HTMLEncoder;
016:        import org.vfny.geoserver.config.CoverageConfig;
017:        import org.vfny.geoserver.config.CoverageStoreConfig;
018:        import org.vfny.geoserver.config.DataConfig;
019:        import org.vfny.geoserver.config.DataStoreConfig;
020:        import org.vfny.geoserver.config.FeatureTypeConfig;
021:        import org.vfny.geoserver.config.StyleConfig;
022:        import org.vfny.geoserver.form.data.StylesSelectForm;
023:        import org.vfny.geoserver.global.UserContainer;
024:        import java.io.File;
025:        import java.io.IOException;
026:        import java.util.ArrayList;
027:        import java.util.Iterator;
028:        import java.util.List;
029:        import java.util.Locale;
030:        import java.util.Map;
031:        import javax.servlet.ServletException;
032:        import javax.servlet.http.HttpServletRequest;
033:        import javax.servlet.http.HttpServletResponse;
034:
035:        /**
036:         * Edit selected style
037:         *
038:         * @author jgarnett, Refractions Research, Inc.
039:         * @author $Author: dmzwiers $ (last modification)
040:         * @version $Id: StylesSelectAction.java 8470 2008-02-27 10:51:54Z aaime $
041:         */
042:        public class StylesSelectAction extends ConfigAction {
043:            public ActionForward execute(ActionMapping mapping,
044:                    ActionForm form, UserContainer user,
045:                    HttpServletRequest request, HttpServletResponse response)
046:                    throws IOException, ServletException {
047:                final StylesSelectForm selectForm = (StylesSelectForm) form;
048:                final String action = selectForm.getAction();
049:                String styleId = selectForm.getSelectedStyle();
050:
051:                if (styleId.endsWith("*")) {
052:                    styleId = styleId.substring(0, styleId.lastIndexOf("*"));
053:                }
054:
055:                Locale locale = (Locale) request.getLocale();
056:
057:                DataConfig config = getDataConfig();
058:                MessageResources messages = getResources(request);
059:
060:                // Need locale wording for edit and delete
061:                final String EDIT = HTMLEncoder.decode(messages.getMessage(
062:                        locale, "label.edit"));
063:                final String DELETE = HTMLEncoder.decode(messages.getMessage(
064:                        locale, "label.delete"));
065:                final String DEFAULT = HTMLEncoder.decode(messages.getMessage(
066:                        locale, "label.default"));
067:
068:                StyleConfig style = config.getStyle(styleId);
069:
070:                if (style == null) {
071:                    ActionErrors errors = new ActionErrors();
072:                    errors.add("selectedStyle", new ActionError(
073:                            "error.style.invalid", styleId));
074:                    request.setAttribute(Globals.ERROR_KEY, errors);
075:
076:                    return mapping.findForward("config.data.style");
077:                }
078:
079:                // Something is selected lets do the requested action
080:                //
081:                if (action.equals(DELETE)) {
082:                    // check if the style has any users
083:                    List userNames = getStyleUsers(config, styleId);
084:
085:                    if (userNames.size() > 0) {
086:                        doFileExistsError(styleId, userNames, request);
087:
088:                        return mapping.findForward("config.data.style");
089:                    }
090:
091:                    config.removeStyle(styleId);
092:                    getApplicationState().notifyConfigChanged();
093:                    selectForm.setSelectedStyle(null);
094:                    selectForm.reset(mapping, request);
095:
096:                    return mapping.findForward("config.data.style");
097:                }
098:
099:                if (action.equals(DEFAULT)) {
100:                    Map m = config.getStyles();
101:                    Iterator i = m.values().iterator();
102:
103:                    while (i.hasNext()) {
104:                        StyleConfig sc = (StyleConfig) i.next();
105:
106:                        if (sc.isDefault()) {
107:                            if ((sc.getId() != null)
108:                                    && !sc.getId().equals(styleId)) {
109:                                sc.setDefault(false);
110:                                getApplicationState().notifyConfigChanged();
111:                            }
112:                        } else {
113:                            if ((sc.getId() != null)
114:                                    && sc.getId().equals(styleId)) {
115:                                sc.setDefault(true);
116:                                getApplicationState().notifyConfigChanged();
117:                            }
118:                        }
119:                    }
120:
121:                    selectForm.setSelectedStyle(null);
122:                    selectForm.reset(mapping, request);
123:
124:                    return mapping.findForward("config.data.style");
125:                }
126:
127:                if (action.equals(EDIT)) {
128:                    user.setStyle(new StyleConfig(style));
129:
130:                    return mapping.findForward("config.data.style.editor");
131:                }
132:
133:                ActionErrors errors = new ActionErrors();
134:                errors.add("submit", new ActionError("error.action.invalid",
135:                        action));
136:                request.setAttribute(Globals.ERROR_KEY, errors);
137:
138:                return mapping.findForward("config.data.style");
139:            }
140:
141:            /**
142:             * Returns a list of strings, with the name of the layers using the style as the default one
143:             * @param config
144:             * @param styleId
145:             * @return
146:             */
147:            private List getStyleUsers(DataConfig config, String styleId) {
148:                List results = new ArrayList();
149:
150:                for (Iterator it = config.getFeaturesTypes().values()
151:                        .iterator(); it.hasNext();) {
152:                    FeatureTypeConfig ft = (FeatureTypeConfig) it.next();
153:
154:                    if (styleId.equals(ft.getDefaultStyle())
155:                            || ft.getStyles().contains(styleId)) {
156:                        DataStoreConfig ds = config.getDataStore(ft
157:                                .getDataStoreId());
158:
159:                        // misconfigured data stores are not included int the map, ouff...
160:                        if (ds != null) {
161:                            results.add(ds.getNameSpaceId() + ":"
162:                                    + ft.getName());
163:                        } else {
164:                            results.add(ft.getName());
165:                        }
166:                    }
167:                }
168:
169:                for (Iterator it = config.getCoverages().values().iterator(); it
170:                        .hasNext();) {
171:                    CoverageConfig cc = (CoverageConfig) it.next();
172:
173:                    if (styleId.equals(cc.getDefaultStyle())
174:                            || cc.getStyles().contains(styleId)) {
175:                        CoverageStoreConfig cs = config.getDataFormat(cc
176:                                .getFormatId());
177:                        results.add(cs.getNameSpaceId() + ":" + cc.getName());
178:                    }
179:                }
180:
181:                return results;
182:            }
183:
184:            /*
185:             * reports an error for an attempt to upload an sld file that is already
186:             * in the system.*/
187:            private void doFileExistsError(String styleId, List styleUsers,
188:                    HttpServletRequest request) {
189:                StringBuffer sb = new StringBuffer();
190:
191:                for (Iterator it = styleUsers.iterator(); it.hasNext();) {
192:                    String user = (String) it.next();
193:                    sb.append(user);
194:
195:                    if (it.hasNext()) {
196:                        sb.append(", ");
197:                    }
198:                }
199:
200:                ActionErrors errors = new ActionErrors();
201:                errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
202:                        "error.style.sldInUse", new String[] { styleId,
203:                                sb.toString() }));
204:                saveErrors(request, errors);
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.