Source Code Cross Referenced for AddRepositoryHandler.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » console » car » 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 » EJB Server geronimo » plugins » org.apache.geronimo.console.car 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.console.car;
017:
018:        import org.apache.commons.logging.Log;
019:        import org.apache.commons.logging.LogFactory;
020:        import org.apache.geronimo.console.MultiPageModel;
021:        import org.apache.geronimo.console.util.PortletManager;
022:        import org.apache.geronimo.system.plugin.PluginRepositoryList;
023:
024:        import javax.portlet.ActionRequest;
025:        import javax.portlet.ActionResponse;
026:        import javax.portlet.PortletException;
027:        import javax.portlet.RenderRequest;
028:        import javax.portlet.RenderResponse;
029:        import java.io.IOException;
030:        import java.io.InputStream;
031:        import java.net.ConnectException;
032:        import java.net.HttpURLConnection;
033:        import java.net.MalformedURLException;
034:        import java.net.UnknownHostException;
035:        import java.net.URL;
036:        import java.net.URLConnection;
037:        import java.util.ArrayList;
038:        import java.util.Arrays;
039:        import java.util.List;
040:
041:        /**
042:         * Handler for the import export main screen.
043:         *
044:         * @version $Rev: 612567 $ $Date: 2008-01-16 12:49:35 -0800 (Wed, 16 Jan 2008) $
045:         */
046:        public class AddRepositoryHandler extends BaseImportExportHandler {
047:            private final static Log log = LogFactory
048:                    .getLog(AddRepositoryHandler.class);
049:
050:            public AddRepositoryHandler() {
051:                super (ADD_REPO_MODE, "/WEB-INF/view/car/addRepository.jsp");
052:            }
053:
054:            public String actionBeforeView(ActionRequest request,
055:                    ActionResponse response, MultiPageModel model)
056:                    throws PortletException, IOException {
057:                return getMode();
058:            }
059:
060:            public void renderView(RenderRequest request,
061:                    RenderResponse response, MultiPageModel model)
062:                    throws PortletException, IOException {
063:                List<PluginRepositoryList> lists = ManagementHelper
064:                        .getManagementHelper(request)
065:                        .getPluginRepositoryLists();
066:                List<URL> list = new ArrayList<URL>();
067:                for (PluginRepositoryList repo : lists) {
068:                    list.addAll(repo.getRepositories());
069:                }
070:                String error = request.getParameter("repoError");
071:                if (error != null && !error.equals("")) {
072:                    request.setAttribute("repoError", error);
073:                }
074:                request.setAttribute("repositories", list);
075:            }
076:
077:            public String actionAfterView(ActionRequest request,
078:                    ActionResponse response, MultiPageModel model)
079:                    throws PortletException, IOException {
080:                String repo = request.getParameter("newRepository");
081:                if (repo != null && !repo.equals("")) {
082:                    if (!addRepository(repo, request, response)) {
083:                        return getMode();
084:                    }
085:                }
086:                return INDEX_MODE + BEFORE_ACTION;
087:            }
088:
089:            private boolean addRepository(String repo, ActionRequest request,
090:                    ActionResponse response) throws IOException {
091:                repo = repo.trim();
092:                repo = repo.replaceAll(" ", "%20");
093:                if (!repo.endsWith("/")) {
094:                    repo = repo + "/";
095:                }
096:
097:                List<PluginRepositoryList> lists = ManagementHelper
098:                        .getManagementHelper(request)
099:                        .getPluginRepositoryLists();
100:
101:                // Check for duplicates
102:                for (PluginRepositoryList test : lists) {
103:                    List<URL> all = test.getRepositories();
104:                    for (URL url : all) {
105:                        String existing = url.toString();
106:                        if (repo.equals(existing)) {
107:                            response.setRenderParameter("repoError",
108:                                    "Already have an entry for repository "
109:                                            + repo);
110:                            return false;
111:                        }
112:                    }
113:                }
114:
115:                // Verify the repository and add it if valid
116:                if (lists.size() > 0) {
117:                    URL url;
118:                    try {
119:                        url = new URL(repo);
120:                    } catch (MalformedURLException e) {
121:                        response.setRenderParameter("repoError",
122:                                "Invalid repository URL " + repo);
123:                        return false;
124:                    }
125:                    URL test = new URL(repo + "geronimo-plugins.xml");
126:                    log.debug("Checking repository " + test);
127:                    URLConnection urlConnection = test.openConnection();
128:                    if (urlConnection instanceof  HttpURLConnection) {
129:                        HttpURLConnection con = (HttpURLConnection) urlConnection;
130:                        try {
131:                            con.connect();
132:                        } catch (ConnectException e) {
133:                            response.setRenderParameter("repoError",
134:                                    "Unable to connect to " + url + " ("
135:                                            + e.getMessage() + ")");
136:                            return false;
137:                        } catch (UnknownHostException e) {
138:                            response.setRenderParameter("repoError",
139:                                    "Unknown host: " + url.getHost());
140:                            return false;
141:                        }
142:                        int result = con.getResponseCode();
143:                        log.debug("Repository check response: " + result);
144:                        if (result == 404) {
145:                            response.setRenderParameter("repoError",
146:                                    "Not a valid repository; no plugin list found at "
147:                                            + test);
148:                            return false;
149:                        } else if (result == 401) {
150:                            log
151:                                    .warn("Unable to validate repository -- it requires authentication.  Assuming you know what you're doing.");
152:                        } else if (result != 200) {
153:                            log
154:                                    .warn("Unexpected response code while validating repository ("
155:                                            + result
156:                                            + " "
157:                                            + con.getResponseMessage()
158:                                            + ").  Assuming you know what you're doing.");
159:                        }
160:                        con.disconnect();
161:                    } else {
162:                        try {
163:                            urlConnection.connect();
164:                            InputStream in = urlConnection.getInputStream();
165:                            in.read();
166:                            in.close();
167:                        } catch (IOException e) {
168:                            response.setRenderParameter("repoError",
169:                                    "Not a valid repository; no plugin list found at "
170:                                            + test);
171:                            return false;
172:                        }
173:                    }
174:                    lists.get(0).addUserRepository(url);
175:                    request.setAttribute("repository", repo);
176:                    return true;
177:                }
178:                response
179:                        .setRenderParameter("repoError",
180:                                "No repository list found; unable to store new repository");
181:                return false;
182:            }
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.