Source Code Cross Referenced for JetspeedPortletDeployer.java in  » Portal » jetspeed-2.1.3 » org » apache » jetspeed » portlets » rpad » portlet » deployer » impl » 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 » Portal » jetspeed 2.1.3 » org.apache.jetspeed.portlets.rpad.portlet.deployer.impl 
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:         */
017:        package org.apache.jetspeed.portlets.rpad.portlet.deployer.impl;
018:
019:        import java.io.File;
020:        import java.io.FileInputStream;
021:        import java.io.FileNotFoundException;
022:        import java.io.FileOutputStream;
023:        import java.io.IOException;
024:        import java.io.InputStream;
025:        import java.io.OutputStream;
026:        import java.net.MalformedURLException;
027:        import java.net.URL;
028:        import java.util.Calendar;
029:
030:        import javax.faces.context.FacesContext;
031:
032:        import org.apache.commons.logging.Log;
033:        import org.apache.commons.logging.LogFactory;
034:        import org.apache.jetspeed.CommonPortletServices;
035:        import org.apache.jetspeed.deployment.DeploymentException;
036:        import org.apache.jetspeed.deployment.DeploymentManager;
037:        import org.apache.jetspeed.deployment.DeploymentStatus;
038:        import org.apache.jetspeed.portlets.rpad.PortletApplication;
039:        import org.apache.jetspeed.portlets.rpad.portlet.deployer.PortletDeployer;
040:        import org.apache.jetspeed.portlets.rpad.portlet.util.FacesMessageUtil;
041:
042:        public class JetspeedPortletDeployer implements  PortletDeployer {
043:            /**
044:             * Logger for this class
045:             */
046:            private static final Log log = LogFactory
047:                    .getLog(JetspeedPortletDeployer.class);
048:
049:            private int status;
050:
051:            private long startTime = 0;
052:
053:            public JetspeedPortletDeployer() {
054:                status = READY;
055:            }
056:
057:            public int getStatus() {
058:                return status;
059:            }
060:
061:            synchronized public void deploy(PortletApplication portlet) {
062:                if (status != READY) {
063:                    //TODO check timeout
064:
065:                    //TODO i18n
066:                    FacesMessageUtil
067:                            .addWarnMessage("Other deployment process is running.");
068:                    return;
069:                }
070:                DeployerThread deployer = new DeployerThread();
071:                deployer
072:                        .setDeploymentManager((DeploymentManager) FacesContext
073:                                .getCurrentInstance()
074:                                .getExternalContext()
075:                                .getApplicationMap()
076:                                .get(
077:                                        CommonPortletServices.CPS_DEPLOYMENT_MANAGER_COMPONENT));
078:                deployer.setPortletApplication(portlet);
079:                try {
080:                    deployer.start();
081:                    //TODO i18n
082:                    FacesMessageUtil
083:                            .addInfoMessage("Started a deployment process.");
084:                } catch (Exception e) {
085:                    //TODO i18n
086:                    FacesMessageUtil
087:                            .addErrorMessage("Could not start deployment process.");
088:                    log.error("Could not start deployment process.", e);
089:                }
090:            }
091:
092:            public class DeployerThread extends Thread {
093:                private DeploymentManager deploymentManager;
094:
095:                private PortletApplication portletApplication;
096:
097:                /* (non-Javadoc)
098:                 * @see java.lang.Thread#run()
099:                 */
100:                public void run() {
101:                    status = DEPLOYING;
102:                    try {
103:                        startTime = Calendar.getInstance().getTimeInMillis();
104:                        if (getDeploymentManager() != null) {
105:                            String binaryUrl = portletApplication
106:                                    .getBinaryUrl();
107:                            if (binaryUrl != null && !binaryUrl.equals("")) {
108:                                File targetFile = null;
109:                                try {
110:                                    File tempFile = File.createTempFile(
111:                                            "rpad_", "."
112:                                                    + portletApplication
113:                                                            .getPackaging());
114:                                    FileOutputStream out = new FileOutputStream(
115:                                            tempFile);
116:                                    drain(getInputStream(portletApplication
117:                                            .getBinaryUrl()), out);
118:                                    try {
119:                                        targetFile = new File(tempFile
120:                                                .getParentFile(),
121:                                                portletApplication
122:                                                        .getArtifactId()
123:                                                        + "."
124:                                                        + portletApplication
125:                                                                .getPackaging());
126:                                        tempFile.renameTo(targetFile);
127:                                    } catch (Exception e) {
128:                                        targetFile = tempFile;
129:                                    }
130:                                    if (getDeploymentManager().deploy(
131:                                            targetFile).getStatus() == DeploymentStatus.STATUS_OKAY) {
132:                                        log.info(portletApplication.getName()
133:                                                + " was deployed.");
134:                                    } else {
135:                                        log.error("Could not deploy "
136:                                                + portletApplication.getName());
137:                                    }
138:                                } catch (FileNotFoundException e) {
139:                                    log.error(e);
140:                                } catch (IOException e) {
141:                                    log.error(e);
142:                                } catch (DeploymentException e) {
143:                                    log.error(e);
144:                                }
145:                                if (targetFile != null && targetFile.exists()) {
146:                                    targetFile.delete();
147:                                }
148:                            } else {
149:                                log
150:                                        .error("The target url is invalid. The path is "
151:                                                + binaryUrl);
152:                            }
153:                        } else {
154:                            log.error("Could not find the deployment manager.");
155:                        }
156:                    } catch (Exception e) {
157:                        log.error("Unexpected exception.", e);
158:                    } finally {
159:                        status = READY;
160:                    }
161:                }
162:
163:                /**
164:                 * @return the portletApplication
165:                 */
166:                public PortletApplication getPortletApplication() {
167:                    return portletApplication;
168:                }
169:
170:                /**
171:                 * @param portletApplication the portletApplication to set
172:                 */
173:                public void setPortletApplication(
174:                        PortletApplication portletApplication) {
175:                    this .portletApplication = portletApplication;
176:                }
177:
178:                /**
179:                 * @return the startTime
180:                 */
181:                public long getStartTime() {
182:                    return startTime;
183:                }
184:
185:                /**
186:                 * @return the deploymentManager
187:                 */
188:                public DeploymentManager getDeploymentManager() {
189:                    return deploymentManager;
190:                }
191:
192:                /**
193:                 * @param deploymentManager the deploymentManager to set
194:                 */
195:                public void setDeploymentManager(
196:                        DeploymentManager deploymentManager) {
197:                    this .deploymentManager = deploymentManager;
198:                }
199:
200:            }
201:
202:            protected void drain(InputStream in, OutputStream out)
203:                    throws IOException {
204:                try {
205:                    byte[] buf = new byte[8192];
206:                    int len = in.read(buf);
207:
208:                    while (len != -1) {
209:                        out.write(buf, 0, len);
210:                        len = in.read(buf);
211:                    }
212:                    out.flush();
213:                } catch (IOException e) {
214:                    throw e;
215:                } finally {
216:                    try {
217:                        out.close();
218:                    } catch (IOException e) {
219:                    }
220:                    try {
221:                        in.close();
222:                    } catch (IOException e) {
223:                    }
224:                }
225:            }
226:
227:            protected InputStream getInputStream(String path) {
228:                if (path.startsWith("http:") || path.startsWith("https:")) {
229:                    try {
230:                        URL url = new URL(path);
231:                        return url.openStream();
232:                    } catch (MalformedURLException e) {
233:                        log.error("Wrong url: " + path, e);
234:                    } catch (IOException e) {
235:                        log.error("Could not load " + path, e);
236:                    }
237:                } else if (path.startsWith("file:")) {
238:                    try {
239:                        return new FileInputStream(new File(path.substring(5)));
240:                    } catch (FileNotFoundException e) {
241:                        log.error("Could not load " + path, e);
242:                    }
243:                }
244:                return null;
245:            }
246:
247:        }
www___._j_a__v___a2_s__._c_om | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.