KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > webapps_deployer > JahiaJBossWebAppsDeployerBaseService


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12
//
13
//
14
// JahiaJBossWebAppsDeployerBaseService
15
//
16
//
17
//
18

19
20 package org.jahia.services.webapps_deployer;
21
22
23 import org.jahia.data.applications.ApplicationBean;
24 import org.jahia.exceptions.JahiaException;
25 import org.jahia.services.sites.JahiaSite;
26 import org.jahia.utils.JahiaTools;
27
28 import java.io.File JavaDoc;
29 import java.util.Vector JavaDoc;
30
31 /**
32  * This Service Register new Application Definition,
33  * deploy webApps packaged in a .war or .ear file.
34  *
35  * @author thomas draier
36  * @version 1.0
37  */

38 public class JahiaJBossWebAppsDeployerBaseService
39         extends JahiaTomcatWebAppsDeployerBaseService {
40
41     private static JahiaJBossWebAppsDeployerBaseService m_Instance = null;
42
43     /**
44      * Use this method to get an instance of this class
45      */

46     public static synchronized JahiaTomcatWebAppsDeployerBaseService getInstance () {
47
48         if (m_Instance == null) {
49             m_Instance = new JahiaJBossWebAppsDeployerBaseService ();
50         }
51         return m_Instance;
52     }
53
54
55
56     //-------------------------------------------------------------------------
57
/**
58      * Deploy a single .war web component file
59      *
60      * @param site the site
61      * @param webContext , the web context
62      * @param filePath , the full path to the war file
63      */

64     protected boolean deployWarFile (JahiaSite site, String JavaDoc webContext, String JavaDoc filePath)
65             throws JahiaException {
66         Vector JavaDoc webApps = new Vector JavaDoc ();
67         StringBuffer JavaDoc webContextDiskPath = new StringBuffer JavaDoc (m_ServerHomeDiskPath);
68         webContextDiskPath.append (File.separator);
69         webContextDiskPath.append ("deploy");
70         webContextDiskPath.append (File.separator);
71         webContextDiskPath.append (webContext);
72         webContextDiskPath.append ("_");
73         webContextDiskPath.append (site.getSiteKey ());
74         webContextDiskPath.append (".war");
75
76         //StringBuffer webContextBuff = new StringBuffer(site.getSiteKey());
77
StringBuffer JavaDoc webContextBuff = new StringBuffer JavaDoc (webContext);
78         webContextBuff.append ("_");
79         webContextBuff.append (site.getSiteKey ());
80
81         webApps = handleWarFile (webContextDiskPath.toString (), filePath);
82
83         // Activate the Web App in Tomcat
84
// activateWebApp(webContextBuff.toString(),webContextDiskPath.toString());
85

86         // register Web Apps in Jahia
87
File JavaDoc f = new File JavaDoc (filePath);
88         registerWebApps (site, webContextBuff.toString (), f.getName (), webApps);
89
90         // move the war to the context
91
File JavaDoc warFile = new File JavaDoc (filePath);
92         warFile.delete ();
93
94         /*
95         webContextDiskPath.append(File.separator);
96         webContextDiskPath.append(warFile.getName());
97
98         File newPos = new File(webContextDiskPath.toString()+File.separator+m_WEB_INF);
99         if ( !warFile.renameTo(newPos) ){
100             warFile.delete();
101         }
102         */

103
104         return true;
105
106     }
107
108
109     //-------------------------------------------------------------------------
110
/**
111      * Undeploy a web application. Delete the web component from disk.
112      *
113      * @param (ApplicationBean) the application bean object
114      *
115      * @return (boolean) true if successfull
116      */

117
118     public boolean undeploy (ApplicationBean app) throws JahiaException {
119         if (app != null) {
120
121             // try to delete physically the directory on disk
122
StringBuffer JavaDoc webContextDiskPath = new StringBuffer JavaDoc (m_ServerHomeDiskPath);
123             webContextDiskPath.append (File.separator);
124             webContextDiskPath.append ("deploy");
125             webContextDiskPath.append (File.separator);
126             webContextDiskPath.append (app.getContext ());
127             webContextDiskPath.append (".war");
128             JahiaTools.deleteFile (new File JavaDoc (webContextDiskPath.toString ()));
129
130             return true;
131         }
132
133         return false;
134     }
135
136
137     protected boolean activateWebApp (
138             String JavaDoc context,
139             String JavaDoc webAppDiskPath
140             ) throws JahiaException {
141         return true;
142     }
143
144     protected boolean undeployWebApp (String JavaDoc context
145                                       ) throws JahiaException {
146         return true;
147     }
148
149     protected boolean addManagerUser (String JavaDoc docPath) {
150         return true;
151     }
152
153     public boolean canDeploy () {
154         return true;
155     }
156 }
157
Popular Tags