1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.tools.registration; |
18 |
|
|
19 |
|
import java.io.File; |
20 |
|
import java.io.FileReader; |
21 |
|
|
22 |
|
import org.apache.commons.configuration.PropertiesConfiguration; |
23 |
|
import org.apache.jetspeed.components.portletregistry.PortletRegistry; |
24 |
|
import org.apache.jetspeed.engine.JetspeedEngineConstants; |
25 |
|
import org.apache.jetspeed.om.common.portlet.MutablePortletApplication; |
26 |
|
import org.apache.jetspeed.om.common.portlet.PortletApplication; |
27 |
|
import org.apache.jetspeed.om.common.servlet.MutableWebApplication; |
28 |
|
import org.apache.jetspeed.util.descriptor.ExtendedPortletMetadata; |
29 |
|
import org.apache.jetspeed.util.descriptor.PortletApplicationDescriptor; |
30 |
|
import org.apache.jetspeed.util.descriptor.WebApplicationDescriptor; |
31 |
|
import org.springframework.context.ApplicationContext; |
32 |
|
import org.springframework.context.support.ClassPathXmlApplicationContext; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
public class RegistrationTool |
47 |
|
{ |
48 |
|
private PortletRegistry registry; |
49 |
|
|
50 |
|
public static void main(String args[]) |
51 |
|
{ |
52 |
0 |
String fileName = System.getProperty("org.apache.jetspeed.portletregistry.configuration", "registration.properties"); |
53 |
0 |
PropertiesConfiguration configuration = new PropertiesConfiguration(); |
54 |
|
try |
55 |
|
{ |
56 |
0 |
File appRootDir = new File("./src/webapp"); |
57 |
0 |
System.setProperty(JetspeedEngineConstants.APPLICATION_ROOT_KEY, appRootDir.getAbsolutePath()); |
58 |
0 |
configuration.load(fileName); |
59 |
0 |
String [] bootAssemblies = configuration.getStringArray("boot.assemblies"); |
60 |
0 |
String [] assemblies = configuration.getStringArray("assemblies"); |
61 |
|
ClassPathXmlApplicationContext ctx; |
62 |
|
|
63 |
0 |
if (bootAssemblies != null) |
64 |
|
{ |
65 |
0 |
ApplicationContext bootContext = new ClassPathXmlApplicationContext(bootAssemblies, true); |
66 |
0 |
ctx = new ClassPathXmlApplicationContext(assemblies, true, bootContext); |
67 |
0 |
} |
68 |
|
else |
69 |
|
{ |
70 |
0 |
ctx = new ClassPathXmlApplicationContext(assemblies, true); |
71 |
|
} |
72 |
|
|
73 |
0 |
boolean overwriteApps = configuration.getBoolean("overwrite.apps", true); |
74 |
0 |
String registryBean = configuration.getString("registry.component", ""); |
75 |
0 |
String[] appNames = configuration.getStringArray("apps"); |
76 |
0 |
String[] appDescriptors = configuration.getStringArray("descriptors"); |
77 |
0 |
String[] webappDescriptors = configuration.getStringArray("webapp.descriptors"); |
78 |
0 |
String[] extendedDescriptors = configuration.getStringArray("extended.descriptors"); |
79 |
0 |
PortletRegistry registry = (PortletRegistry)ctx.getBean(registryBean); |
80 |
0 |
RegistrationTool tool = new RegistrationTool(registry, overwriteApps); |
81 |
|
|
82 |
0 |
for (int ix=0; ix < appNames.length; ix++) |
83 |
|
{ |
84 |
0 |
if (overwriteApps) |
85 |
|
{ |
86 |
0 |
tool.unregister(appNames[ix]); |
87 |
|
} |
88 |
0 |
tool.register(appNames[ix], appDescriptors[ix], webappDescriptors[ix], extendedDescriptors[ix]); |
89 |
|
} |
90 |
|
} |
91 |
0 |
catch (Exception e) |
92 |
|
{ |
93 |
0 |
System.err.println("Failed to import: " + e); |
94 |
0 |
e.printStackTrace(); |
95 |
0 |
} |
96 |
|
|
97 |
0 |
} |
98 |
|
|
99 |
|
public RegistrationTool(PortletRegistry registry, boolean overwriteApps) |
100 |
0 |
{ |
101 |
0 |
this.registry = registry; |
102 |
0 |
} |
103 |
|
|
104 |
|
public void unregister(String appName) |
105 |
|
throws Exception |
106 |
|
{ |
107 |
0 |
if (registry.portletApplicationExists(appName)) |
108 |
|
{ |
109 |
0 |
PortletApplication app = registry.getPortletApplication(appName); |
110 |
0 |
if (app != null) |
111 |
|
{ |
112 |
0 |
registry.removeApplication(app); |
113 |
|
} |
114 |
|
} |
115 |
0 |
} |
116 |
|
|
117 |
|
public void register(String appName, String appDescriptor, String webappDescriptor, String extendedDescriptor) |
118 |
|
throws Exception |
119 |
|
{ |
120 |
0 |
WebApplicationDescriptor wad = new WebApplicationDescriptor(class="keyword">new FileReader(webappDescriptor), "/" + appName); |
121 |
0 |
MutableWebApplication webapp = wad.createWebApplication(); |
122 |
0 |
PortletApplicationDescriptor pad = new PortletApplicationDescriptor(class="keyword">new FileReader(appDescriptor), appName); |
123 |
0 |
MutablePortletApplication app = pad.createPortletApplication(); |
124 |
0 |
app.setWebApplicationDefinition(webapp); |
125 |
0 |
ExtendedPortletMetadata extMetaData = new ExtendedPortletMetadata(class="keyword">new FileReader(extendedDescriptor), app); |
126 |
0 |
extMetaData.load(); |
127 |
0 |
registry.registerPortletApplication(app); |
128 |
0 |
} |
129 |
|
} |