[Registry-dev] svn commit r18863 - in trunk/registry/modules: core/src/main/java/org/wso2/registry/jdbc/handlers extensions/src/org/wso2/registry/servlet samples/handler-sample/resources
chathura at wso2.com
chathura at wso2.com
Fri Jul 4 03:39:14 PDT 2008
Author: chathura
Date: Fri Jul 4 03:39:14 2008
New Revision: 18863
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=18863
Log:
Implemented the XSLT support for custom UIs.
Now it is possible to generate view and edit UIs with XSLTs (for XML resource contents) without writting java code.
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/XSLTBasedUIEnabledHandler.java
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/UIEnabledHandler.java
trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml
trunk/registry/modules/samples/handler-sample/resources/registry.xml
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/UIEnabledHandler.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/UIEnabledHandler.java?rev=18863&r1=18862&r2=18863&view=diff
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/UIEnabledHandler.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/UIEnabledHandler.java Fri Jul 4 03:39:14 2008
@@ -30,9 +30,16 @@
(String) requestContext.getProperty(RegistryConstants.UI_CONTENT_PROPERTY);
if (UIAction != null) {
if (RegistryConstants.VIEW_PROPERTY.equals(UIAction)) {
- return getView(requestContext);
+ Resource resource = getView(requestContext);
+ resource.setProperty(
+ RegistryConstants.UI_CONTENT_PROPERTY, RegistryConstants.UI_HTML);
+ return resource;
+
} else if (RegistryConstants.EDIT_PROPERTY.equals(UIAction)) {
- return getEdit(requestContext);
+ Resource resource = getEdit(requestContext);
+ resource.setProperty(
+ RegistryConstants.UI_CONTENT_PROPERTY, RegistryConstants.UI_HTML);
+ return resource;
}
}
Added: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/XSLTBasedUIEnabledHandler.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/XSLTBasedUIEnabledHandler.java?pathrev=18863
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/XSLTBasedUIEnabledHandler.java Fri Jul 4 03:39:14 2008
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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 org.wso2.registry.jdbc.handlers;
+
+import org.wso2.registry.Resource;
+import org.wso2.registry.exceptions.RegistryException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.File;
+import java.io.ByteArrayOutputStream;
+
+public class XSLTBasedUIEnabledHandler extends UIEnabledHandler {
+
+ private static Log log = LogFactory.getLog(XSLTBasedUIEnabledHandler.class);
+
+ protected String viewXSLT;
+ protected Transformer viewTransformer;
+
+ protected String editXSLT;
+ protected Transformer editTransformer;
+
+ private TransformerFactory transformerFactory;
+
+ public XSLTBasedUIEnabledHandler() {
+ transformerFactory = TransformerFactory.newInstance();
+ }
+
+ public void setViewXSLT(String viewXSLT) throws RegistryException {
+ this.viewXSLT = viewXSLT;
+ File viewXSLTFile = new File(viewXSLT);
+
+ try {
+ viewTransformer = transformerFactory.newTransformer(new StreamSource(viewXSLTFile));
+
+ } catch (TransformerConfigurationException e) {
+ String msg = "Failed to create transformer for the view UI XSLT. " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ }
+
+ public void setEditXSLT(String editXSLT) throws RegistryException {
+ this.editXSLT = editXSLT;
+ File editXSLTFile = new File(editXSLT);
+
+ try {
+ editTransformer = transformerFactory.newTransformer(new StreamSource(editXSLTFile));
+
+ } catch (TransformerConfigurationException e) {
+ String msg = "Failed to create transformer for the edit UI XSLT. " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ }
+
+ public Resource getView(RequestContext requestContext) throws RegistryException {
+
+ if (viewTransformer == null) {
+ return getRawResource(requestContext);
+ }
+
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+ Resource resource = requestContext.getRegistry().get(requestContext.getResourcePath());
+
+ try {
+ viewTransformer.setParameter("resourcePath", requestContext.getResourcePath());
+ viewTransformer.transform(
+ new StreamSource(resource.getContentStream()), new StreamResult(byteOut));
+
+ } catch (TransformerException e) {
+ String msg = "Failed to generate the view UI for resource " +
+ requestContext.getResourcePath() + ". XSLT transformation failed for XSLT " +
+ viewXSLT + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+
+ String content = byteOut.toString();
+ resource.setContent(content);
+
+ return resource;
+ }
+
+ public Resource getEdit(RequestContext requestContext) throws RegistryException {
+
+ if (editTransformer == null) {
+ return getRawResource(requestContext);
+ }
+
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+ Resource resource = requestContext.getRegistry().get(requestContext.getResourcePath());
+
+ try {
+ editTransformer.setParameter("resourcePath", requestContext.getResourcePath());
+ editTransformer.transform(
+ new StreamSource(resource.getContentStream()), new StreamResult(byteOut));
+
+ } catch (TransformerException e) {
+ String msg = "Failed to generate the edit UI for resource " +
+ requestContext.getResourcePath() + ". XSLT transformation failed for XSLT " +
+ viewXSLT + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+
+ String content = byteOut.toString();
+ resource.setContent(content);
+
+ return resource;
+ }
+
+ public Resource getRawResource(RequestContext requestContext) throws RegistryException {
+ return null;
+ }
+
+ public void put(RequestContext requestContext) throws RegistryException {
+ }
+
+ public void importResource(RequestContext requestContext) throws RegistryException {
+ }
+
+ public void delete(RequestContext requestContext) throws RegistryException {
+ }
+
+ public void putChild(RequestContext requestContext) throws RegistryException {
+ }
+
+ public void importChild(RequestContext requestContext) throws RegistryException {
+ }
+}
Modified: trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml?rev=18863&r1=18862&r2=18863&view=diff
==============================================================================
--- trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml (original)
+++ trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml Fri Jul 4 03:39:14 2008
@@ -88,6 +88,18 @@
</filter>
</handler>
+ <!--<handler class="org.wso2.registry.jdbc.handlers.XSLTBasedUIEnabledHandler">-->
+
+ <!--<property name="viewXSLT">/home/chathura/projects/reg-work/samples/affview.xslt</property>-->
+ <!--<property name="editXSLT">/home/chathura/projects/reg-work/samples/affedit.xslt</property>-->
+
+ <!--<filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">-->
+ <!--<property name="mediaType">application/aff+xml</property>-->
+ <!--</filter>-->
+
+ <!--<edit processor="application/aff+xml">org.wso2.registry.jdbc.handlers.samples.custom.AFEditProcessor</edit>-->
+ <!--</handler>-->
+
<!--<handler class="org.wso2.registry.jdbc.handlers.samples.custom.AFHandler">-->
<!--<filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">-->
<!--<property name="mediaType">application/aff+xml</property>-->
Modified: trunk/registry/modules/samples/handler-sample/resources/registry.xml
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/samples/handler-sample/resources/registry.xml?rev=18863&r1=18862&r2=18863&view=diff
==============================================================================
--- trunk/registry/modules/samples/handler-sample/resources/registry.xml (original)
+++ trunk/registry/modules/samples/handler-sample/resources/registry.xml Fri Jul 4 03:39:14 2008
@@ -68,6 +68,18 @@
</filter>
</handler>
+ <!--<handler class="org.wso2.registry.jdbc.handlers.XSLTBasedUIEnabledHandler">-->
+
+ <!--<property name="viewXSLT">/home/chathura/projects/reg-work/samples/affview.xslt</property>-->
+ <!--<property name="editXSLT">/home/chathura/projects/reg-work/samples/affedit.xslt</property>-->
+
+ <!--<filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">-->
+ <!--<property name="mediaType">application/aff+xml</property>-->
+ <!--</filter>-->
+
+ <!--<edit processor="application/aff+xml">org.wso2.registry.jdbc.handlers.samples.custom.AFEditProcessor</edit>-->
+ <!--</handler>-->
+
<!--<handler class="org.wso2.registry.jdbc.handlers.samples.custom.AFHandler">-->
<!--<filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">-->
<!--<property name="mediaType">application/aff+xml</property>-->
More information about the Registry-dev
mailing list