svnno****@sourc*****
svnno****@sourc*****
2007年 4月 12日 (木) 18:00:20 JST
Revision: 39 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=pal&view=rev&rev=39 Author: shinsuke Date: 2007-04-12 18:00:20 +0900 (Thu, 12 Apr 2007) Log Message: ----------- enable you to deploy uploaded war file. Modified Paths: -------------- pal-admin/trunk/pom.xml pal-admin/trunk/src/main/java/jp/sf/pal/admin/PALAdminConstants.java pal-admin/trunk/src/main/java/jp/sf/pal/admin/entity/PortletApplication.java pal-admin/trunk/src/main/java/jp/sf/pal/admin/filter/PortletManagementFilter.java pal-admin/trunk/src/main/java/jp/sf/pal/admin/util/PALAdminUtil.java pal-admin/trunk/src/main/java/jp/sf/pal/admin/util/PortalComponentUtil.java pal-admin/trunk/src/main/resources/appMessages.properties pal-admin/trunk/src/main/webapp/WEB-INF/portlet.xml pal-admin/trunk/src/main/webapp/view/portletmanager/portletList.html Added Paths: ----------- pal-admin/trunk/src/main/java/jp/sf/pal/admin/deployer/ pal-admin/trunk/src/main/java/jp/sf/pal/admin/deployer/DeploymentStatus.java pal-admin/trunk/src/main/java/jp/sf/pal/admin/deployer/PortletDeployer.java pal-admin/trunk/src/main/java/jp/sf/pal/admin/logic/PortletDeploymentLogic.java pal-admin/trunk/src/main/java/jp/sf/pal/admin/service/PortletDeploymentService.java pal-admin/trunk/src/main/java/jp/sf/pal/admin/util/DeploymentUtil.java pal-admin/trunk/src/main/java/jp/sf/pal/admin/web/deployer/ pal-admin/trunk/src/main/java/jp/sf/pal/admin/web/deployer/DeployerEditPage.java pal-admin/trunk/src/main/resources/jp/sf/pal/admin/web/deployer/ pal-admin/trunk/src/main/resources/jp/sf/pal/admin/web/deployer/label.properties pal-admin/trunk/src/main/webapp/view/deployer/ pal-admin/trunk/src/main/webapp/view/deployer/deployerEdit.html -------------- next part -------------- Modified: pal-admin/trunk/pom.xml =================================================================== --- pal-admin/trunk/pom.xml 2007-04-12 03:19:04 UTC (rev 38) +++ pal-admin/trunk/pom.xml 2007-04-12 09:00:20 UTC (rev 39) @@ -205,12 +205,12 @@ <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> - <version>1.2</version> + <version>1.1.1</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> - <version>1.3.1</version> + <version>1.1</version> </dependency> <dependency> <groupId>log4j</groupId> Modified: pal-admin/trunk/src/main/java/jp/sf/pal/admin/PALAdminConstants.java =================================================================== --- pal-admin/trunk/src/main/java/jp/sf/pal/admin/PALAdminConstants.java 2007-04-12 03:19:04 UTC (rev 38) +++ pal-admin/trunk/src/main/java/jp/sf/pal/admin/PALAdminConstants.java 2007-04-12 09:00:20 UTC (rev 39) @@ -31,6 +31,9 @@ public static final String PORTLET_FACTORY_COMPONENT = PREFIX + "PortletFactory"; + public static final String DEPLOYMENT_MANAGER_COMPONENT = PREFIX + + "DeploymentManager"; + public static final String PREVIOUS_PAGE_NUMBER = "previousPageNumber"; public static final String NEXT_PAGE_NUMBER = "nextPageNumber"; @@ -71,4 +74,9 @@ public static final String PORTLET_MANAGEMENT_ACTION_DELETE = "delete"; + public static final String DEPLOYMENT_STATUS = PREFIX + "DeploymentStatus"; + + public static final String LOCAL_TEMP_FILENAME_PREFIX = "uploadedPortletApplication"; + + public static final String LOCAL_TEMP_FILENAME_SUFFIX = ".war"; } Added: pal-admin/trunk/src/main/java/jp/sf/pal/admin/deployer/DeploymentStatus.java =================================================================== --- pal-admin/trunk/src/main/java/jp/sf/pal/admin/deployer/DeploymentStatus.java 2007-04-12 03:19:04 UTC (rev 38) +++ pal-admin/trunk/src/main/java/jp/sf/pal/admin/deployer/DeploymentStatus.java 2007-04-12 09:00:20 UTC (rev 39) @@ -0,0 +1,73 @@ +package jp.sf.pal.admin.deployer; + +import jp.sf.pal.admin.entity.PortletApplication; + +public class DeploymentStatus +{ + public static final int DEPLOYED = 2; + + public static final int DEPLOYING = 1; + + public static final int READY = 0; + + private long startTime; + + public int status; + + public PortletApplication portletApplication; + + public DeploymentStatus(PortletApplication portletApplication) + { + startTime = 0; + status = READY; + this.portletApplication = portletApplication; + } + + /** + * @return the status + */ + public int getStatus() + { + return status; + } + + /** + * @param status the status to set + */ + public void setStatus(int status) + { + this.status = status; + } + + /** + * @return the portletApplication + */ + public PortletApplication getPortletApplication() + { + return portletApplication; + } + + /** + * @param portletApplication the portletApplication to set + */ + public void setPortletApplication(PortletApplication portletApplication) + { + this.portletApplication = portletApplication; + } + + /** + * @return the startTime + */ + public long getStartTime() + { + return startTime; + } + + /** + * @param startTime the startTime to set + */ + public void setStartTime(long startTime) + { + this.startTime = startTime; + } +} Property changes on: pal-admin/trunk/src/main/java/jp/sf/pal/admin/deployer/DeploymentStatus.java ___________________________________________________________________ Name: svn:eol-style + native Added: pal-admin/trunk/src/main/java/jp/sf/pal/admin/deployer/PortletDeployer.java =================================================================== --- pal-admin/trunk/src/main/java/jp/sf/pal/admin/deployer/PortletDeployer.java 2007-04-12 03:19:04 UTC (rev 38) +++ pal-admin/trunk/src/main/java/jp/sf/pal/admin/deployer/PortletDeployer.java 2007-04-12 09:00:20 UTC (rev 39) @@ -0,0 +1,223 @@ +package jp.sf.pal.admin.deployer; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Calendar; + +import jp.sf.pal.admin.entity.PortletApplication; +import jp.sf.pal.admin.logic.PortletDeploymentLogic; +import jp.sf.pal.admin.util.PALAdminUtil; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jetspeed.deployment.DeploymentException; +import org.apache.jetspeed.deployment.DeploymentManager; + +public class PortletDeployer extends Thread +{ + public static final String FILEPATH_PROTOCOL_HTTPS = "https:"; + + public static final String PATH_PROTOCOL_HTTP = "http:"; + + public static final String FILEPATH_PROTOCOL_FILE = "file:"; + + public static final String FILEPATH_PROTOCOL_TEMP = "temp:"; + + /** + * Logger for this class + */ + private static final Log log = LogFactory + .getLog(PortletDeploymentLogic.class); + + private DeploymentManager deploymentManager; + + private PortletApplication portletApplication; + + private DeploymentStatus deploymentStatus; + + public PortletDeployer(PortletApplication portletApplication) + { + this.portletApplication = portletApplication; + deploymentStatus = new DeploymentStatus(portletApplication); + } + + /* (non-Javadoc) + * @see java.lang.Thread#run() + */ + public void run() + { + deploymentStatus.setStatus(DeploymentStatus.DEPLOYING); + try + { + deploymentStatus.setStartTime(Calendar.getInstance() + .getTimeInMillis()); + if (getDeploymentManager() != null) + { + String binaryUrl = portletApplication.getBinaryUrl(); + if (binaryUrl != null && !binaryUrl.equals("")) + { + File targetFile = null; + try + { + File tempFile = null; + if (binaryUrl.startsWith(FILEPATH_PROTOCOL_TEMP)) + { + tempFile=new File(binaryUrl.substring(FILEPATH_PROTOCOL_TEMP.length())); + } + else + { + tempFile = File.createTempFile("rpad_", "." + + portletApplication.getPackaging()); + FileOutputStream out = new FileOutputStream( + tempFile); + PALAdminUtil.drain(getInputStream(binaryUrl), out); + } + try + { + targetFile = new File(tempFile.getParentFile(), + portletApplication.getArtifactId() + "." + + portletApplication.getPackaging()); + tempFile.renameTo(targetFile); + } + catch (Exception e) + { + targetFile = tempFile; + } + if (getDeploymentManager().deploy(targetFile) + .getStatus() == org.apache.jetspeed.deployment.DeploymentStatus.STATUS_OKAY) + { + log.info(portletApplication.getName() + + " was deployed."); + } + else + { + log.error("Could not deploy " + + portletApplication.getName()); + } + } + catch (FileNotFoundException e) + { + log.error(e); + } + catch (IOException e) + { + log.error(e); + } + catch (DeploymentException e) + { + log.error(e); + } + if (targetFile != null && targetFile.exists()) + { + targetFile.delete(); + } + } + else + { + log.error("The target url is invalid. The path is " + + binaryUrl); + } + } + else + { + log.error("Could not find the deployment manager."); + } + } + catch (Exception e) + { + log.error("Unexpected exception.", e); + } + finally + { + deploymentStatus.setStatus(DeploymentStatus.DEPLOYED); + } + } + + protected InputStream getInputStream(String path) + { + if (path.startsWith(PATH_PROTOCOL_HTTP) + || path.startsWith(FILEPATH_PROTOCOL_HTTPS)) + { + try + { + URL url = new URL(path); + return url.openStream(); + } + catch (MalformedURLException e) + { + log.error("Wrong url: " + path, e); + } + catch (IOException e) + { + log.error("Could not load " + path, e); + } + } + else if (path.startsWith(FILEPATH_PROTOCOL_FILE)) + { + try + { + return new FileInputStream(new File(path.substring(5))); + } + catch (FileNotFoundException e) + { + log.error("Could not load " + path, e); + } + } + return null; + } + + /** + * @return the portletApplication + */ + public PortletApplication getPortletApplication() + { + return portletApplication; + } + + /** + * @param portletApplication the portletApplication to set + */ + public void setPortletApplication(PortletApplication portletApplication) + { + this.portletApplication = portletApplication; + } + + /** + * @return the deploymentManager + */ + public DeploymentManager getDeploymentManager() + { + return deploymentManager; + } + + /** + * @param deploymentManager the deploymentManager to set + */ + public void setDeploymentManager(DeploymentManager deploymentManager) + { + this.deploymentManager = deploymentManager; + } + + /** + * @return the deploymentStatus + */ + public DeploymentStatus getDeploymentStatus() + { + return deploymentStatus; + } + + /** + * @param deploymentStatus the deploymentStatus to set + */ + public void setDeploymentStatus(DeploymentStatus deploymentStatus) + { + this.deploymentStatus = deploymentStatus; + } + +} Property changes on: pal-admin/trunk/src/main/java/jp/sf/pal/admin/deployer/PortletDeployer.java ___________________________________________________________________ Name: svn:eol-style + native Modified: pal-admin/trunk/src/main/java/jp/sf/pal/admin/entity/PortletApplication.java =================================================================== --- pal-admin/trunk/src/main/java/jp/sf/pal/admin/entity/PortletApplication.java 2007-04-12 03:19:04 UTC (rev 38) +++ pal-admin/trunk/src/main/java/jp/sf/pal/admin/entity/PortletApplication.java 2007-04-12 09:00:20 UTC (rev 39) @@ -1,6 +1,10 @@ package jp.sf.pal.admin.entity; import java.io.Serializable; +import java.sql.Date; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; public class PortletApplication implements Serializable { @@ -10,6 +14,10 @@ */ private static final long serialVersionUID = 904304488157108100L; + public static final String PACKAGING_TYPE_WAR = "war"; + + public static final String PACKAGING_TYPE_JAR = "jar"; + private String name; private String path; @@ -20,6 +28,53 @@ private int applicationType; + private Date created = null; + + private Date lastModified = null; + + private String portletSpecVersion = null; + + private String groupId = null; + + private String artifactId = null; + + private String packaging = null; + + private String description = null; + + private List<String> tags = new ArrayList<String>(); + + private String publisherName = null; + + private String publisherUrl = null; + + private String binaryUrl = null; + + private String sourceUrl = null; + + private String imageUrl = null; + + //TODO + // private Map dependencies; + + private String licenseName = null; + + private String licenseUrl = null; + + private String compiledJDKVersion = null; + + private List<Locale> supportedLocales = new ArrayList<Locale>(); + + public void addTag(String category) + { + tags.add(category); + } + + public void addSupportedLocale(Locale locale) + { + supportedLocales.add(locale); + } + /** * @return the name */ @@ -99,4 +154,276 @@ { this.applicationType = applicationType; } + + /** + * @return the artifactId + */ + public String getArtifactId() + { + return artifactId; + } + + /** + * @param artifactId the artifactId to set + */ + public void setArtifactId(String artifactId) + { + this.artifactId = artifactId; + } + + /** + * @return the binaryUrl + */ + public String getBinaryUrl() + { + return binaryUrl; + } + + /** + * @param binaryUrl the binaryUrl to set + */ + public void setBinaryUrl(String binaryUrl) + { + this.binaryUrl = binaryUrl; + } + + /** + * @return the compiledJDKVersion + */ + public String getCompiledJDKVersion() + { + return compiledJDKVersion; + } + + /** + * @param compiledJDKVersion the compiledJDKVersion to set + */ + public void setCompiledJDKVersion(String compiledJDKVersion) + { + this.compiledJDKVersion = compiledJDKVersion; + } + + /** + * @return the created + */ + public Date getCreated() + { + return created; + } + + /** + * @param created the created to set + */ + public void setCreated(Date created) + { + this.created = created; + } + + /** + * @return the description + */ + public String getDescription() + { + return description; + } + + /** + * @param description the description to set + */ + public void setDescription(String description) + { + this.description = description; + } + + /** + * @return the groupId + */ + public String getGroupId() + { + return groupId; + } + + /** + * @param groupId the groupId to set + */ + public void setGroupId(String groupId) + { + this.groupId = groupId; + } + + /** + * @return the imageUrl + */ + public String getImageUrl() + { + return imageUrl; + } + + /** + * @param imageUrl the imageUrl to set + */ + public void setImageUrl(String imageUrl) + { + this.imageUrl = imageUrl; + } + + /** + * @return the lastModified + */ + public Date getLastModified() + { + return lastModified; + } + + /** + * @param lastModified the lastModified to set + */ + public void setLastModified(Date lastModified) + { + this.lastModified = lastModified; + } + + /** + * @return the licenseName + */ + public String getLicenseName() + { + return licenseName; + } + + /** + * @param licenseName the licenseName to set + */ + public void setLicenseName(String licenseName) + { + this.licenseName = licenseName; + } + + /** + * @return the licenseUrl + */ + public String getLicenseUrl() + { + return licenseUrl; + } + + /** + * @param licenseUrl the licenseUrl to set + */ + public void setLicenseUrl(String licenseUrl) + { + this.licenseUrl = licenseUrl; + } + + /** + * @return the packaging + */ + public String getPackaging() + { + return packaging; + } + + /** + * @param packaging the packaging to set + */ + public void setPackaging(String packaging) + { + this.packaging = packaging; + } + + /** + * @return the portletSpecVersion + */ + public String getPortletSpecVersion() + { + return portletSpecVersion; + } + + /** + * @param portletSpecVersion the portletSpecVersion to set + */ + public void setPortletSpecVersion(String portletSpecVersion) + { + this.portletSpecVersion = portletSpecVersion; + } + + /** + * @return the publisherName + */ + public String getPublisherName() + { + return publisherName; + } + + /** + * @param publisherName the publisherName to set + */ + public void setPublisherName(String publisherName) + { + this.publisherName = publisherName; + } + + /** + * @return the publisherUrl + */ + public String getPublisherUrl() + { + return publisherUrl; + } + + /** + * @param publisherUrl the publisherUrl to set + */ + public void setPublisherUrl(String publisherUrl) + { + this.publisherUrl = publisherUrl; + } + + /** + * @return the sourceUrl + */ + public String getSourceUrl() + { + return sourceUrl; + } + + /** + * @param sourceUrl the sourceUrl to set + */ + public void setSourceUrl(String sourceUrl) + { + this.sourceUrl = sourceUrl; + } + + /** + * @return the supportedLocales + */ + public List<Locale> getSupportedLocales() + { + return supportedLocales; + } + + /** + * @param supportedLocales the supportedLocales to set + */ + public void setSupportedLocales(List<Locale> supportedLocales) + { + this.supportedLocales = supportedLocales; + } + + /** + * @return the tags + */ + public List<String> getTags() + { + return tags; + } + + /** + * @param tags the tags to set + */ + public void setTags(List<String> tags) + { + this.tags = tags; + } } Modified: pal-admin/trunk/src/main/java/jp/sf/pal/admin/filter/PortletManagementFilter.java =================================================================== --- pal-admin/trunk/src/main/java/jp/sf/pal/admin/filter/PortletManagementFilter.java 2007-04-12 03:19:04 UTC (rev 38) +++ pal-admin/trunk/src/main/java/jp/sf/pal/admin/filter/PortletManagementFilter.java 2007-04-12 09:00:20 UTC (rev 39) @@ -34,6 +34,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.jetspeed.CommonPortletServices; import org.apache.jetspeed.components.portletregistry.PortletRegistry; +import org.apache.jetspeed.deployment.DeploymentManager; import org.apache.jetspeed.factory.PortletFactory; import org.apache.jetspeed.tools.pamanager.servletcontainer.ApplicationServerManager; import org.apache.portals.bridges.portletfilter.PortletFilter; @@ -60,6 +61,8 @@ private PortletFactory portletFactory; + private DeploymentManager deploymentManager; + public void destroy() { applicationServerManager = null; @@ -86,6 +89,8 @@ .getAttribute(CommonPortletServices.CPS_PORTLET_FACTORY_COMPONENT); applicationServerManager = (ApplicationServerManager) portletContext .getAttribute(CommonPortletServices.CPS_APPLICATION_SERVER_MANAGER_COMPONENT); + deploymentManager = (DeploymentManager) portletContext + .getAttribute(CommonPortletServices.CPS_DEPLOYMENT_MANAGER_COMPONENT); //RPAD initRRPAD(portletConfig); @@ -138,6 +143,8 @@ portletFactory); request.setAttribute(PALAdminConstants.PORTLET_REGISTRY_COMPONENT, portletRegistry); + request.setAttribute(PALAdminConstants.DEPLOYMENT_MANAGER_COMPONENT, + deploymentManager); chain.processActionFilter(request, response); } @@ -152,6 +159,8 @@ portletFactory); request.setAttribute(PALAdminConstants.PORTLET_REGISTRY_COMPONENT, portletRegistry); + request.setAttribute(PALAdminConstants.DEPLOYMENT_MANAGER_COMPONENT, + deploymentManager); chain.renderFilter(request, response); } Added: pal-admin/trunk/src/main/java/jp/sf/pal/admin/logic/PortletDeploymentLogic.java =================================================================== --- pal-admin/trunk/src/main/java/jp/sf/pal/admin/logic/PortletDeploymentLogic.java 2007-04-12 03:19:04 UTC (rev 38) +++ pal-admin/trunk/src/main/java/jp/sf/pal/admin/logic/PortletDeploymentLogic.java 2007-04-12 09:00:20 UTC (rev 39) @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jp.sf.pal.admin.logic; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import jp.sf.pal.admin.PALAdminConstants; +import jp.sf.pal.admin.PALAdminException; +import jp.sf.pal.admin.deployer.PortletDeployer; +import jp.sf.pal.admin.entity.PortletApplication; +import jp.sf.pal.admin.util.DeploymentUtil; +import jp.sf.pal.admin.util.PALAdminUtil; +import jp.sf.pal.admin.util.PortalComponentUtil; + +import org.seasar.framework.log.Logger; + +public class PortletDeploymentLogic +{ + /** + * Logger for this class + */ + private static final Logger logger = Logger + .getLogger(PortletManagementLogic.class); + + synchronized public void deploy(PortletApplication portlet) + throws PALAdminException + { + + if (DeploymentUtil.isDeploying()) + { + //TODO check timeout + + throw new PALAdminException("Other deployment process is running."); + } + + // create deployer + PortletDeployer deployer = new PortletDeployer(portlet); + deployer.setDeploymentManager(PortalComponentUtil + .getDeploymentManager()); + + // set deployment status to application context + DeploymentUtil.setDeploymentStatus(deployer.getDeploymentStatus()); + + try + { + // start deployer + deployer.start(); + } + catch (Exception e) + { + logger.error("Could not start deployment process.", e); + throw new PALAdminException("Could not start deployment process.", + e); + } + } + + public File storeLocalFile(InputStream inputStream) + throws PALAdminException + { + File localTempFile = null; + OutputStream outputStream = null; + try + { + localTempFile = File.createTempFile( + PALAdminConstants.LOCAL_TEMP_FILENAME_PREFIX, + PALAdminConstants.LOCAL_TEMP_FILENAME_SUFFIX); + outputStream = new FileOutputStream(localTempFile); + PALAdminUtil.drain(inputStream, outputStream); + outputStream.flush(); + } + catch (FileNotFoundException e) + { + logger + .error( + "Could not store the uploaded file. Could not find a local temp file.", + e); + throw new PALAdminException( + "Could not store the uploaded file. Could not find a local temp file.", + e); + } + catch (IOException e) + { + logger.error("Could not store the uploaded file.", e); + throw new PALAdminException("Could not store the uploaded file.", e); + } + finally + { + if (inputStream != null) + { + try + { + inputStream.close(); + } + catch (IOException e) + { + logger.error("Could not close the input stream.", e); + throw new PALAdminException( + "Could not close the input stream.", e); + } + } + if (outputStream != null) + { + try + { + outputStream.close(); + } + catch (IOException e) + { + logger.error("Could not close the output stream.", e); + throw new PALAdminException( + "Could not close the output stream.", e); + + } + } + } + + return localTempFile; + } + +} Property changes on: pal-admin/trunk/src/main/java/jp/sf/pal/admin/logic/PortletDeploymentLogic.java ___________________________________________________________________ Name: svn:eol-style + native Added: pal-admin/trunk/src/main/java/jp/sf/pal/admin/service/PortletDeploymentService.java =================================================================== --- pal-admin/trunk/src/main/java/jp/sf/pal/admin/service/PortletDeploymentService.java 2007-04-12 03:19:04 UTC (rev 38) +++ pal-admin/trunk/src/main/java/jp/sf/pal/admin/service/PortletDeploymentService.java 2007-04-12 09:00:20 UTC (rev 39) @@ -0,0 +1,82 @@ +package jp.sf.pal.admin.service; + +import java.io.File; +import java.io.IOException; + +import org.apache.myfaces.custom.fileupload.UploadedFile; + +import jp.sf.pal.admin.PALAdminException; +import jp.sf.pal.admin.deployer.PortletDeployer; +import jp.sf.pal.admin.entity.PortletApplication; +import jp.sf.pal.admin.logic.PortletDeploymentLogic; +import jp.sf.pal.admin.web.deployer.DeployerEditPage; + +public class PortletDeploymentService +{ + private PortletDeploymentLogic portletDeploymentLogic; + + /** + * @return the portletDeploymentLogic + */ + public PortletDeploymentLogic getPortletDeploymentLogic() + { + return portletDeploymentLogic; + } + + /** + * @param portletDeploymentLogic the portletDeploymentLogic to set + */ + public void setPortletDeploymentLogic( + PortletDeploymentLogic portletDeploymentLogic) + { + this.portletDeploymentLogic = portletDeploymentLogic; + } + + public void deploy(DeployerEditPage page) throws PALAdminException + { + // store uploaded file + File localFile = null; + UploadedFile uploadedFile = page.getPortletApplicationFile(); + try + { + localFile = portletDeploymentLogic.storeLocalFile(uploadedFile + .getInputStream()); + } + catch (IOException e) + { + throw new PALAdminException( + "Could not get the input stream for the uploaded file.", e); + } + + String name = removeExtension(uploadedFile.getName()); + PortletApplication portlet = new PortletApplication(); + portlet.setName(name); + portlet.setArtifactId(name); + portlet.setBinaryUrl(PortletDeployer.FILEPATH_PROTOCOL_TEMP + + localFile.getAbsolutePath()); + portlet.setPackaging(getExtension(uploadedFile.getName())); + + portletDeploymentLogic.deploy(portlet); + + } + + private String removeExtension(String name) + { + int pos = name.lastIndexOf("."); + if (pos != -1) + { + return name.substring(0, pos); + } + return name; + } + + private String getExtension(String name) + { + int pos = name.lastIndexOf("."); + if (pos != -1 && pos <= name.length()) + { + return name.substring(pos + 1); + } + return ""; + } +} Property changes on: pal-admin/trunk/src/main/java/jp/sf/pal/admin/service/PortletDeploymentService.java ___________________________________________________________________ Name: svn:eol-style + native Added: pal-admin/trunk/src/main/java/jp/sf/pal/admin/util/DeploymentUtil.java =================================================================== --- pal-admin/trunk/src/main/java/jp/sf/pal/admin/util/DeploymentUtil.java 2007-04-12 03:19:04 UTC (rev 38) +++ pal-admin/trunk/src/main/java/jp/sf/pal/admin/util/DeploymentUtil.java 2007-04-12 09:00:20 UTC (rev 39) @@ -0,0 +1,57 @@ +package jp.sf.pal.admin.util; + +import javax.faces.context.FacesContext; + +import jp.sf.pal.admin.PALAdminConstants; +import jp.sf.pal.admin.deployer.DeploymentStatus; + +public class DeploymentUtil +{ + /** + * @return the facesContext + */ + private static FacesContext getFacesContext() + { + return FacesContext.getCurrentInstance(); + } + + public static DeploymentStatus getDeploymentStatus() + { + return (DeploymentStatus) getFacesContext().getExternalContext() + .getApplicationMap().get(PALAdminConstants.DEPLOYMENT_STATUS); + } + + public static void setDeploymentStatus(DeploymentStatus deploymentStatus) + { + getFacesContext().getExternalContext().getApplicationMap().put( + PALAdminConstants.DEPLOYMENT_STATUS, deploymentStatus); + } + + public static boolean isDeploying() + { + DeploymentStatus deploymentStatus = getDeploymentStatus(); + if (deploymentStatus == null) + { + return false; + } + if (deploymentStatus.getStatus() == DeploymentStatus.DEPLOYING) + { + return true; + } + return false; + } + + public static boolean isReady() + { + DeploymentStatus deploymentStatus = getDeploymentStatus(); + if (deploymentStatus == null) + { + return true; + } + if (deploymentStatus.getStatus() != DeploymentStatus.DEPLOYING) + { + return true; + } + return false; + } +} Property changes on: pal-admin/trunk/src/main/java/jp/sf/pal/admin/util/DeploymentUtil.java ___________________________________________________________________ Name: svn:eol-style + native Modified: pal-admin/trunk/src/main/java/jp/sf/pal/admin/util/PALAdminUtil.java =================================================================== --- pal-admin/trunk/src/main/java/jp/sf/pal/admin/util/PALAdminUtil.java 2007-04-12 03:19:04 UTC (rev 38) +++ pal-admin/trunk/src/main/java/jp/sf/pal/admin/util/PALAdminUtil.java 2007-04-12 09:00:20 UTC (rev 39) @@ -1,5 +1,8 @@ package jp.sf.pal.admin.util; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.security.Principal; import java.util.ArrayList; import java.util.HashMap; @@ -84,4 +87,42 @@ } return buf.toString(); } + + public static void drain(InputStream in, OutputStream out) + throws IOException + { + try + { + byte[] buf = new byte[8192]; + int len = in.read(buf); + + while (len != -1) + { + out.write(buf, 0, len); + len = in.read(buf); + } + out.flush(); + } + catch (IOException e) + { + throw e; + } + finally + { + try + { + out.close(); + } + catch (IOException e) + { + } + try + { + in.close(); + } + catch (IOException e) + { + } + } + } } Modified: pal-admin/trunk/src/main/java/jp/sf/pal/admin/util/PortalComponentUtil.java =================================================================== --- pal-admin/trunk/src/main/java/jp/sf/pal/admin/util/PortalComponentUtil.java 2007-04-12 03:19:04 UTC (rev 38) +++ pal-admin/trunk/src/main/java/jp/sf/pal/admin/util/PortalComponentUtil.java 2007-04-12 09:00:20 UTC (rev 39) @@ -5,6 +5,7 @@ import jp.sf.pal.admin.PALAdminConstants; import org.apache.jetspeed.components.portletregistry.PortletRegistry; +import org.apache.jetspeed.deployment.DeploymentManager; import org.apache.jetspeed.factory.PortletFactory; import org.apache.jetspeed.page.PageManager; import org.apache.jetspeed.profiler.Profiler; @@ -81,4 +82,11 @@ .getRequestMap().get( PALAdminConstants.PORTLET_FACTORY_COMPONENT); } + + public static DeploymentManager getDeploymentManager() + { + return (DeploymentManager) getFacesContext().getExternalContext() + .getRequestMap().get( + PALAdminConstants.DEPLOYMENT_MANAGER_COMPONENT); + } } Added: pal-admin/trunk/src/main/java/jp/sf/pal/admin/web/deployer/DeployerEditPage.java =================================================================== --- pal-admin/trunk/src/main/java/jp/sf/pal/admin/web/deployer/DeployerEditPage.java 2007-04-12 03:19:04 UTC (rev 38) +++ pal-admin/trunk/src/main/java/jp/sf/pal/admin/web/deployer/DeployerEditPage.java 2007-04-12 09:00:20 UTC (rev 39) @@ -0,0 +1,78 @@ +package jp.sf.pal.admin.web.deployer; + +import javax.faces.internal.FacesMessageUtil; + +import org.apache.myfaces.custom.fileupload.UploadedFile; +import org.seasar.teeda.extension.annotation.validator.Required; + +import jp.sf.pal.admin.PALAdminException; +import jp.sf.pal.admin.service.PortletDeploymentService; +import jp.sf.pal.admin.web.AbstractCrudPage; + +public class DeployerEditPage extends AbstractCrudPage +{ + @Required + private UploadedFile portletApplicationFile; + + private PortletDeploymentService portletDeploymentService; + + public UploadedFile getPortletApplicationFile() + { + return portletApplicationFile; + } + + public void setPortletApplicationFile(UploadedFile portletApplicationFile) + { + this.portletApplicationFile = portletApplicationFile; + } + + /** + * @return the portletDeploymentService + */ + public PortletDeploymentService getPortletDeploymentService() + { + return portletDeploymentService; + } + + /** + * @param portletDeploymentService the portletDeploymentService to set + */ + public void setPortletDeploymentService( + PortletDeploymentService portletDeploymentService) + { + this.portletDeploymentService = portletDeploymentService; + } + + public String initialize() + { + return null; + } + + public String prerender() + { + return null; + } + + public String doFinish() + { + if (portletApplicationFile != null) + { + try + { + portletDeploymentService.deploy(this); + FacesMessageUtil + .addInfoMessage("started.portlet.application.deployment"); + } + catch (PALAdminException e) + { + FacesMessageUtil + .addErrorMessage("failed.to.start.portlet.application.deployment"); + } + } + else + { + FacesMessageUtil.addErrorMessage("invalid.upload.file"); + } + return null; + } +} Property changes on: pal-admin/trunk/src/main/java/jp/sf/pal/admin/web/deployer/DeployerEditPage.java ___________________________________________________________________ Name: svn:eol-style + native Modified: pal-admin/trunk/src/main/resources/appMessages.properties =================================================================== --- pal-admin/trunk/src/main/resources/appMessages.properties 2007-04-12 03:19:04 UTC (rev 38) +++ pal-admin/trunk/src/main/resources/appMessages.properties 2007-04-12 09:00:20 UTC (rev 39) @@ -48,4 +48,6 @@ deleted.portlet.application=Deleted the portlet application. failed.to.delete.portlet.application=Failed to delete the portlet application. - +invalid.upload.file=Invalid upload file. +started.portlet.application.deployment=Started the portlet application deployment. +failed.to.start.portlet.application.deployment=Failed to start the portlet application deployment. Added: pal-admin/trunk/src/main/resources/jp/sf/pal/admin/web/deployer/label.properties =================================================================== --- pal-admin/trunk/src/main/resources/jp/sf/pal/admin/web/deployer/label.properties 2007-04-12 03:19:04 UTC (rev 38) +++ pal-admin/trunk/src/main/resources/jp/sf/pal/admin/web/deployer/label.properties 2007-04-12 09:00:20 UTC (rev 39) @@ -0,0 +1,5 @@ +localTab=Local +remoteTab=Remote + +deployPortlet=Deploy Portlet Application +portletApplicationFile=Portlet Application File \ No newline at end of file Property changes on: pal-admin/trunk/src/main/resources/jp/sf/pal/admin/web/deployer/label.properties ___________________________________________________________________ Name: svn:eol-style + native Modified: pal-admin/trunk/src/main/webapp/WEB-INF/portlet.xml =================================================================== --- pal-admin/trunk/src/main/webapp/WEB-INF/portlet.xml 2007-04-12 03:19:04 UTC (rev 38) +++ pal-admin/trunk/src/main/webapp/WEB-INF/portlet.xml 2007-04-12 09:00:20 UTC (rev 39) @@ -61,7 +61,7 @@ </init-param> <init-param> <name>portlet-filters</name> - <value>org.seasar.portlet.filter.RequestDumpFilter,jp.sf.pal.admin.filter.PortletManagementFilter,jp.sf.pal.facesresponse.FacesResponseFilter,jp.sf.pal.pooptimizer.OptimizerFilter,org.seasar.portlet.filter.S2PortletFilter,org.seasar.portlet.filter.HotdeployPortletFilter</value> + <value>org.seasar.portlet.filter.RequestDumpFilter,jp.sf.pal.admin.filter.PortletManagementFilter,jp.sf.pal.facesresponse.FacesResponseFilter,jp.sf.pal.pooptimizer.OptimizerFilter,org.seasar.portlet.filter.S2PortletFilter,org.seasar.portlet.filter.HotdeployPortletFilter,jp.sf.pal.tomahawk.filter.ExtensionsPortletFilter</value> </init-param> <init-param> <name>view-page</name> Added: pal-admin/trunk/src/main/webapp/view/deployer/deployerEdit.html =================================================================== --- pal-admin/trunk/src/main/webapp/view/deployer/deployerEdit.html 2007-04-12 03:19:04 UTC (rev 38) +++ pal-admin/trunk/src/main/webapp/view/deployer/deployerEdit.html 2007-04-12 09:00:20 UTC (rev 39) @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xmlns:t="http://myfaces.apache.org/tomahawk"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<link rel="stylesheet" type="text/css" href="../../css/global.css"/> +</head> +<body> +<form id="DeployerEditForm" enctype="multipart/form-data"><input type="hidden" id="crudType" /> +<!-- tab: BEGIN --> +<div style="padding: 0px 0px 3px 10px; margin:5px 0px;border-bottom:1px solid #000000;"> + <a id="jumpPortletList" href="../portletmanager/portletList.html" style="text-decoration: none;"> + <span id="portletsTabLabel" style="font-weight: bold;color:#ffffff;background-color:#999999;border:1px solid #000000; padding: 3px 5px 3px 5px; margin: 0px 0px;">Portlets</span> + </a> + <label id="deployerTabLabel" style="border-top:1px solid #000000;border-right:1px solid #000000;border-bottom:1px solid #ffffff;border-left:1px solid #000000;padding: 3px 5px 3px 5px; margin: 0px 0px;">Deployer</label> +</div> +<!-- tab: END --> + +<div> + <span id="allMessages" fatalClass="portlet-msg-error" errorClass="portlet-msg-error" warnClass="portlet-msg-alert" infoClass="portlet-msg-info"></span> +</div> + +<!-- content: BEGIN --> +<div style="padding:5px 0px;"> + <div class="portlet-section-header"> + <label id="deployPortletLabel">Deploy Portlet</label> + </div> + + <div> + <label id="localTabLabel">Local</label> + | + <a id="jumpRemotePortletList" href="remotePortletList.html" style="text-decoration: none;"> + <span id="remoteTabLabel">Remote</span> + </a> + </div> + + <table class="tablebg"> + <tr> + <td class="portlet-section-subheader"><label id="portletApplicationFileLabel">Portlet Application File</label></td> + <td class="portlet-section-body"> + <t:inputFileUpload id="portletApplicationFile" value="#{deployer_deployerEditPage.portletApplicationFile}"></t:inputFileUpload> + </td> + <td><span id="portletApplicationFileMessage"></span></td> + </tr> + </table> + + <div> + <input type="button" id="doFinish" value="Deploy" + onclick="location.href='deployEdit.html'" class="portlet-form-button"/> + </div> +</div> +<!-- content: BEGIN --> +</form> +</body></html> Property changes on: pal-admin/trunk/src/main/webapp/view/deployer/deployerEdit.html ___________________________________________________________________ Name: svn:eol-style + native Modified: pal-admin/trunk/src/main/webapp/view/portletmanager/portletList.html =================================================================== --- pal-admin/trunk/src/main/webapp/view/portletmanager/portletList.html 2007-04-12 03:19:04 UTC (rev 38) +++ pal-admin/trunk/src/main/webapp/view/portletmanager/portletList.html 2007-04-12 09:00:20 UTC (rev 39) @@ -10,7 +10,7 @@ <!-- tab: BEGIN --> <div style="padding: 0px 0px 3px 10px; margin:5px 0px;border-bottom:1px solid #000000;"> <label id="portletsTabLabel" style="border-top:1px solid #000000;border-right:1px solid #000000;border-bottom:1px solid #ffffff;border-left:1px solid #000000;padding: 3px 5px 3px 5px; margin: 0px 0px;">Portlets</label> - <a id="jumpGroupList" href="../deployer/deployerList.html" style="text-decoration: none;"> + <a id="jumpDeployerEdit" href="../deployer/deployerEdit.html" style="text-decoration: none;"> <span id="deployerTabLabel" style="font-weight: bold;color:#ffffff;background-color:#999999;border:1px solid #000000; padding: 3px 5px 3px 5px; margin: 0px 0px;">Deployer</span> </a> </div>