Author: dkuleshov
Date: 2010-11-16 09:54:25 -0500 (Tue, 16 Nov 2010)
New Revision: 3463
Modified:
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/resources/xslt/get-method.xsl
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestGet.java
jcr/trunk/exo.jcr.component.webdav/src/test/resources/conf/standalone/test-configuration.xml
Log:
EXOJCR-994: modified WebDavServiceImpl to pass XSLT parameters as initial parameters,
modified GetCommand, added constructor to receive XSLT parameters Map
Modified:
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java 2010-11-16
14:51:45 UTC (rev 3462)
+++
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java 2010-11-16
14:54:25 UTC (rev 3463)
@@ -137,6 +137,8 @@
private HashMap<MediaType, String> cacheControlMap = new HashMap<MediaType,
String>();
+ public static final String FOLDER_ICON_PATH = "folder-icon-path";
+
/**
* Logger.
*/
@@ -183,6 +185,11 @@
private String autoVersionType = "checkout-checkin";
/**
+ * XSLT parameters.
+ */
+ private Map<String, String> xsltParams = new HashMap<String, String>();
+
+ /**
* The list of allowed methods.
*/
private static final String ALLOW;
@@ -223,6 +230,13 @@
this.repositoryService = repositoryService;
this.nullResourceLocks = new NullResourceLocksHolder();
+ ValueParam pXSLTParam = params.getValueParam(FOLDER_ICON_PATH);
+ if (pXSLTParam != null)
+ {
+ xsltParams.put(FOLDER_ICON_PATH, pXSLTParam.getValue());
+ log.info(FOLDER_ICON_PATH + " = " + pXSLTParam.getValue());
+ }
+
ValueParam pDefFolderNodeType =
params.getValueParam(INIT_PARAM_DEF_FOLDER_NODE_TYPE);
if (pDefFolderNodeType != null)
{
@@ -300,9 +314,16 @@
this.repositoryService = repositoryService;
this.nullResourceLocks = new NullResourceLocksHolder();
- String paramValue = params.get(INIT_PARAM_DEF_FOLDER_NODE_TYPE);
+ String paramValue = params.get(FOLDER_ICON_PATH);
if (paramValue != null)
{
+ xsltParams.put(FOLDER_ICON_PATH, paramValue);
+ log.info(FOLDER_ICON_PATH + " = " + paramValue);
+ }
+
+ paramValue = params.get(INIT_PARAM_DEF_FOLDER_NODE_TYPE);
+ if (paramValue != null)
+ {
defaultFolderNodeType = paramValue;
log.info(INIT_PARAM_DEF_FOLDER_NODE_TYPE + " = " +
defaultFolderNodeType);
}
@@ -634,7 +655,8 @@
String uri =
uriInfo.getBaseUriBuilder().path(getClass()).path(repoName).path(workspaceName(repoPath)).build()
.toString();
- return new GetCommand().get(session, path(repoPath), version, uri, ranges,
ifModifiedSince, cacheControlMap);
+ return new GetCommand(xsltParams).get(session, path(repoPath), version, uri,
ranges, ifModifiedSince,
+ cacheControlMap);
}
catch (PathNotFoundException exc)
Modified:
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java 2010-11-16
14:51:45 UTC (rev 3462)
+++
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java 2010-11-16
14:54:25 UTC (rev 3463)
@@ -18,26 +18,6 @@
*/
package org.exoplatform.services.jcr.webdav.command;
-import java.io.InputStream;
-import java.net.URI;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-
-import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.xml.transform.stream.StreamSource;
-
import org.exoplatform.common.http.HTTPStatus;
import org.exoplatform.common.util.HierarchicalProperty;
import org.exoplatform.services.jcr.webdav.Range;
@@ -59,6 +39,27 @@
import org.exoplatform.services.rest.ext.provider.XSLTStreamingOutput;
import org.exoplatform.services.rest.impl.header.MediaTypeHelper;
+import java.io.InputStream;
+import java.net.URI;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.xml.transform.stream.StreamSource;
+
/**
* Created by The eXo Platform SAS Author : <a
* href="gavrikvetal(a)gmail.com">Vitaly Guly</a>.
@@ -74,6 +75,17 @@
*/
private static Log log =
ExoLogger.getLogger("exo.jcr.component.webdav.GetCommand");
+ private Map<String, String> xsltParams;
+
+ public GetCommand()
+ {
+ }
+
+ public GetCommand(Map<String, String> xsltParams)
+ {
+ this.xsltParams = xsltParams;
+ }
+
/**
* GET content of the resource. Can be return content of the file. The content
* returns in the XML type. If version parameter is present, returns the
@@ -207,7 +219,8 @@
resource = new CollectionResource(uri, node, nsContext);
istream = ((CollectionResource)resource).getContentAsStream(baseURI);
- XSLTStreamingOutput entity = new
XSLTStreamingOutput("get.method.template", new StreamSource(istream));
+ XSLTStreamingOutput entity =
+ new XSLTStreamingOutput("get.method.template", new
StreamSource(istream), xsltParams);
return Response.ok(entity, MediaType.TEXT_HTML).build();
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/resources/xslt/get-method.xsl
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/resources/xslt/get-method.xsl 2010-11-16
14:51:45 UTC (rev 3462)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/resources/xslt/get-method.xsl 2010-11-16
14:54:25 UTC (rev 3463)
@@ -2,6 +2,7 @@
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
exclude-result-prefixes="xlink">
<xsl:output method="html" encoding="UTF-8" />
+ <xsl:param name="folder-icon-path"></xsl:param>
<xsl:template match="/sv:node">
<html>
<head>
@@ -27,7 +28,9 @@
<xsl:attribute name="href">
<xsl:value-of select="substring(./@xlink:href, 1,
string-length(./@xlink:href) - string-length(./@sv:name))" />
</xsl:attribute>
- <img
src="/ecm/skin/icons/16x16/NodeTypes/DefaultSkin/nt-folder.gif" alt=""
/>
+ <xsl:if test="$folder-icon-path!=''">
+ <img src="{$folder-icon-path}" alt="" />
+ </xsl:if>
<xsl:text> ..</xsl:text>
</a>
<br />
@@ -50,9 +53,11 @@
<xsl:template match="sv:node">
<a>
<xsl:attribute name="href">
- <xsl:value-of select="./@xlink:href" />
- </xsl:attribute>
- <img src="/ecm/skin/icons/16x16/NodeTypes/DefaultSkin/nt-folder.gif"
alt="" />
+ <xsl:value-of select="./@xlink:href" />
+ </xsl:attribute>
+ <xsl:if test="$folder-icon-path!=''">
+ <img src="{$folder-icon-path}" alt="" />
+ </xsl:if>
<xsl:text> </xsl:text>
<xsl:value-of select="./@sv:name" />
</a>
Modified:
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestGet.java
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestGet.java 2010-11-16
14:51:45 UTC (rev 3462)
+++
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestGet.java 2010-11-16
14:54:25 UTC (rev 3463)
@@ -18,7 +18,21 @@
*/
package org.exoplatform.services.jcr.webdav.command;
+import org.exoplatform.common.http.HTTPStatus;
+import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
+import org.exoplatform.services.jcr.impl.core.version.VersionImpl;
+import org.exoplatform.services.jcr.webdav.BaseStandaloneTest;
+import org.exoplatform.services.jcr.webdav.WebDavConst;
+import org.exoplatform.services.jcr.webdav.WebDavConstants.WebDAVMethods;
+import org.exoplatform.services.jcr.webdav.utils.TestUtils;
+import org.exoplatform.services.rest.ExtHttpHeaders;
+import org.exoplatform.services.rest.ext.provider.XSLTStreamingOutput;
+import org.exoplatform.services.rest.impl.ContainerResponse;
+import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
+
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
@@ -32,18 +46,6 @@
import javax.jcr.Node;
import javax.ws.rs.core.MultivaluedMap;
-import org.exoplatform.common.http.HTTPStatus;
-import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager;
-import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
-import org.exoplatform.services.jcr.impl.core.version.VersionImpl;
-import org.exoplatform.services.jcr.webdav.BaseStandaloneTest;
-import org.exoplatform.services.jcr.webdav.WebDavConst;
-import org.exoplatform.services.jcr.webdav.WebDavConstants.WebDAVMethods;
-import org.exoplatform.services.jcr.webdav.utils.TestUtils;
-import org.exoplatform.services.rest.ExtHttpHeaders;
-import org.exoplatform.services.rest.impl.ContainerResponse;
-import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
-
/**
* Created by The eXo Platform SAS Author : Dmytro Katayev
* work.visor.ck(a)gmail.com Aug 13, 2008
@@ -172,6 +174,25 @@
assertEquals(HTTPStatus.NOT_MODIFIED, response.getStatus());
}
+ public void testXSLTParamsPassing() throws Exception
+ {
+ String strToTest = "/absolute/path/to/file";
+ String folderName = TestUtils.getFolderName();
+ TestUtils.addFolder(session, folderName, defaultFolderNodeType, "");
+ ContainerResponse response = service(WebDAVMethods.GET, getPathWS() + folderName,
"", null, null);
+
+ assertEquals(HTTPStatus.OK, response.getStatus());
+
+ XSLTStreamingOutput XSLTout = (XSLTStreamingOutput)response.getEntity();
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+ XSLTout.write(byteOut);
+
+ System.out.println("\n" + byteOut.toString() + "\n");
+
+ assertTrue(byteOut.toString().contains(strToTest));
+
+ }
+
@Override
protected String getRepositoryName()
{
Modified:
jcr/trunk/exo.jcr.component.webdav/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/test/resources/conf/standalone/test-configuration.xml 2010-11-16
14:51:45 UTC (rev 3462)
+++
jcr/trunk/exo.jcr.component.webdav/src/test/resources/conf/standalone/test-configuration.xml 2010-11-16
14:54:25 UTC (rev 3463)
@@ -1,13 +1,25 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
- <!--
+<!--
- Copyright (C) 2009 eXo Platform SAS. This is free software; you can redistribute it
and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version. This software is
- distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the GNU Lesser General Public License for more details. You should
have received a copy of the GNU Lesser General Public License along with
- this software; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF site:
-
http://www.fsf.org.
- -->
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+
+-->
+
<configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd
http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
<component>
@@ -193,6 +205,11 @@
<value>text/xml,text/html:max-age=1800;text/*:max-age=777;image/png,image/jpg:max-age=3600;*/*:no-cache;image/*:max-age=555</value>
</value-param>
+ <value-param>
+ <name>folder-icon-path</name>
+ <value>/absolute/path/to/file</value>
+ </value-param>
+
</init-params>
</component>