1 <%@ page import="org.wso2.carbon.context.CarbonContext" %>
2 <%@ page import="org.wso2.carbon.context.RegistryType" %>
3 <%@ page import="org.wso2.carbon.registry.api.Registry" %>
4 <%@ page import="org.wso2.carbon.registry.api.Resource" %>
5
6 <h2>WSO2 Carbon Registry Usage Demo</h2>
7
8 <hr/>
9 <p>
10
11 <h3>Add New Resource</h3>
12 <p>
13 <form action="index.jsp" method="POST">
14 <table border="0">
15 <tr>
16 <td>Registry Type</td>
17 <td>
18 <select name="registryType">
19 <option selected="true"><%= RegistryType.SYSTEM_CONFIGURATION.toString() %></option>
20 <option><%= RegistryType.SYSTEM_GOVERNANCE.toString() %></option>
21 </select>
22 </td>
23 </tr>
24 <tr>
25 <td>Resource Path</td>
26 <td><input type="text" name="resourcePath" value="foo/bar"/></td>
27 </tr>
28 <tr>
29 <td>Value</td>
30 <td><input type="text" name="value" value="WSO2 Carbon"/></td>
31 </tr>
32 <tr>
33 <td> </td>
34 <td><input type="submit" value="Add" name="add"></td>
35 </tr>
36 </table>
37 </form>
38 </p>
39 <hr/>
40 <p>
41
42 <h3>View Resource</h3>
43 <p>
44 <form action="index.jsp" method="POST">
45 <table border="0">
46 <tr>
47 <td>Registry Type</td>
48 <td>
49 <select name="registryType">
50 <option selected="true"><%= RegistryType.SYSTEM_CONFIGURATION.toString() %></option>
51 <option><%= RegistryType.SYSTEM_GOVERNANCE.toString() %></option>
52 </select>
53 </td>
54 </tr>
55 <tr>
56 <td>Resource Path</td>
57 <td><input type="text" name="resourcePath" value="foo/bar"/></td>
58 </tr>
59 <tr>
60 <td> </td>
61 <td><input type="submit" value="View" name="view"></td>
62 </tr>
63 </table>
64 </form>
65 </p>
66 <hr/>
67
68 <%
69 // Obtain the reference to the registry from the CarbonContext
70 CarbonContext cCtx = CarbonContext.getCurrentContext();
71
72 Registry registry = cCtx.getRegistry(RegistryType.SYSTEM_CONFIGURATION);
73 String registryType = request.getParameter("registryType");
74 if(registryType != null) {
75 registry = cCtx.getRegistry(RegistryType.valueOf(registryType));
76 }
77
78 if (request.getParameter("add") != null) {
79 Resource resource = registry.newResource();
80 resource.setContent(request.getParameter("value"));
81 String resourcePath = request.getParameter("resourcePath");
82 registry.put(resourcePath, resource);
83 %>
84 <p>
85 Added resource: <%= resourcePath %>
86 </p>
87 <%
88 } else if (request.getParameter("view") != null) {
89 String resourcePath = request.getParameter("resourcePath");
90 if (registry.resourceExists(resourcePath)) {
91 Resource resource = registry.get(resourcePath);
92 String content = new String((byte[]) resource.getContent());
93 %>
94 <p>
95 Resource at in Registry <%= registryType%> path <%= resourcePath%> : <%= content %>
96 </p>
97 <%
98 } else {
99 %>
100 <p>
101 Resource at path <%= resourcePath%> does not exist in Registry <%= registryType%>!
102 </p>
103 <%
104 }
105 }
106 %>