r563 - in webdavservertest/trunk: . src src/main src/main/java src/main/java/org src/main/java/org/codelutin src/main/java/org/codelutin/webdav src/main/resources src/main/webapp src/main/webapp/WEB-INF src/test
Author: echatellier Date: 2012-11-09 17:00:03 +0100 (Fri, 09 Nov 2012) New Revision: 563 Url: http://nuiton.org/repositories/revision/sandbox/563 Log: Initial import. Added: webdavservertest/trunk/pom.xml webdavservertest/trunk/src/ webdavservertest/trunk/src/main/ webdavservertest/trunk/src/main/java/ webdavservertest/trunk/src/main/java/org/ webdavservertest/trunk/src/main/java/org/codelutin/ webdavservertest/trunk/src/main/java/org/codelutin/webdav/ webdavservertest/trunk/src/main/java/org/codelutin/webdav/WebdavServlet.java webdavservertest/trunk/src/main/java/org/codelutin/webdav/WebdavStore.java webdavservertest/trunk/src/main/resources/ webdavservertest/trunk/src/main/resources/log4j.xml webdavservertest/trunk/src/main/resources/test.odt webdavservertest/trunk/src/main/resources/test.txt webdavservertest/trunk/src/main/webapp/ webdavservertest/trunk/src/main/webapp/WEB-INF/ webdavservertest/trunk/src/main/webapp/WEB-INF/web.xml webdavservertest/trunk/src/test/ webdavservertest/trunk/src/test/java/ Added: webdavservertest/trunk/pom.xml =================================================================== --- webdavservertest/trunk/pom.xml (rev 0) +++ webdavservertest/trunk/pom.xml 2012-11-09 16:00:03 UTC (rev 563) @@ -0,0 +1,52 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.codelutin</groupId> + <artifactId>webdavservertest</artifactId> + <version>0.0.1-SNAPSHOT</version> + <packaging>war</packaging> + + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.7.2</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.7.2</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.5</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>net.sf.webdav-servlet</groupId> + <artifactId>webdav-servlet</artifactId> + <version>2.0.1</version> + </dependency> + </dependencies> + + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-maven-plugin</artifactId> + <version>8.1.7.v20120910</version> + </plugin> + </plugins> + </pluginManagement> + </build> + + <repositories> + <repository> + <id>aa</id> + <url>https://repository.jboss.org/nexus/content/repositories/thirdparty-uploads</url> + </repository> + </repositories> +</project> Added: webdavservertest/trunk/src/main/java/org/codelutin/webdav/WebdavServlet.java =================================================================== --- webdavservertest/trunk/src/main/java/org/codelutin/webdav/WebdavServlet.java (rev 0) +++ webdavservertest/trunk/src/main/java/org/codelutin/webdav/WebdavServlet.java 2012-11-09 16:00:03 UTC (rev 563) @@ -0,0 +1,56 @@ +/* + * #%L + * + * %% + * Copyright (C) 2012 Code Lutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.codelutin.webdav; + +import java.io.File; + +import javax.servlet.ServletException; + +import net.sf.webdav.IWebdavStore; +import net.sf.webdav.LocalFileSystemStore; +import net.sf.webdav.WebDavServletBean; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class WebdavServlet extends WebDavServletBean { + + /** serialVersionUID. */ + private static final long serialVersionUID = -1392228290035641456L; + + private static final Logger logger = LoggerFactory.getLogger(WebdavServlet.class); + + protected File testFile; + + @Override + public void init() throws ServletException { + logger.debug("init"); + + IWebdavStore webdavStore = new WebdavStore(); + + //File root = new File("src/main/resources"); + //IWebdavStore webdavStore = new LocalFileSystemStore(root); + + super.init(webdavStore, null, null, 0, true); + } +} Property changes on: webdavservertest/trunk/src/main/java/org/codelutin/webdav/WebdavServlet.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: webdavservertest/trunk/src/main/java/org/codelutin/webdav/WebdavStore.java =================================================================== --- webdavservertest/trunk/src/main/java/org/codelutin/webdav/WebdavStore.java (rev 0) +++ webdavservertest/trunk/src/main/java/org/codelutin/webdav/WebdavStore.java 2012-11-09 16:00:03 UTC (rev 563) @@ -0,0 +1,163 @@ +/* + * #%L + * + * %% + * Copyright (C) 2012 Code Lutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.codelutin.webdav; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; +import java.security.Principal; +import java.util.Date; + +import net.sf.webdav.ITransaction; +import net.sf.webdav.IWebdavStore; +import net.sf.webdav.StoredObject; +import net.sf.webdav.exceptions.WebdavException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class WebdavStore implements IWebdavStore { + + private static final Logger logger = LoggerFactory.getLogger(WebdavStore.class); + + protected File testFile; + + public WebdavStore() { + URL url = WebdavServlet.class.getResource("/test.odt"); + testFile = new File(url.getFile()); + } + + public ITransaction begin(Principal principal) { + logger.debug("begin"); + return null; + } + + public void checkAuthentication(ITransaction transaction) { + logger.debug("checkAuthentication"); + + } + + public void commit(ITransaction transaction) { + logger.debug("commit"); + + } + + public void rollback(ITransaction transaction) { + logger.debug("rollback"); + + } + + public void createFolder(ITransaction transaction, String folderUri) { + logger.debug("createFolder"); + + } + + public void createResource(ITransaction transaction, String resourceUri) { + logger.debug("createResource"); + + } + + public InputStream getResourceContent(ITransaction transaction, + String resourceUri) { + logger.debug("getResourceContent"); + InputStream is; + try { + is = new BufferedInputStream(new FileInputStream(testFile)); + } catch (FileNotFoundException ex) { + throw new RuntimeException("Can't access to file", ex); + } + return is; + } + + public long setResourceContent(ITransaction transaction, + String resourceUri, InputStream content, String contentType, + String characterEncoding) { + logger.debug("setResourceContent to " + testFile); + + try { + OutputStream os = new BufferedOutputStream(new FileOutputStream(testFile), 65536); + try { + int read; + byte[] copyBuffer = new byte[65536]; + + while ((read = content.read(copyBuffer, 0, copyBuffer.length)) != -1) { + os.write(copyBuffer, 0, read); + } + } finally { + try { + content.close(); + } finally { + os.close(); + } + } + } catch (IOException ex) { + logger.error("LocalFileSystemStore.setResourceContent(" + resourceUri + ") failed", ex); + throw new WebdavException(ex); + } + + return testFile.length(); + } + + public String[] getChildrenNames(ITransaction transaction, String folderUri) { + logger.debug("getChildrenNames"); + return null; + } + + public long getResourceLength(ITransaction transaction, String path) { + logger.debug("getResourceLength"); + return testFile.length(); + } + + public void removeObject(ITransaction transaction, String uri) { + logger.debug("removeObject"); + + } + + public StoredObject getStoredObject(ITransaction transaction, String uri) { + logger.debug("getStoredObject"); + StoredObject so = null; + + if (uri.endsWith("/")) { + so = new StoredObject(); + so.setFolder(true); + so.setLastModified(new Date()); + so.setCreationDate(new Date()); + so.setResourceLength(4); + } + else if (testFile.exists()) { + so = new StoredObject(); + so.setFolder(testFile.isDirectory()); + so.setLastModified(new Date(testFile.lastModified())); + so.setCreationDate(new Date(testFile.lastModified())); + so.setResourceLength(getResourceLength(transaction, uri)); + } + return so; + } +} Property changes on: webdavservertest/trunk/src/main/java/org/codelutin/webdav/WebdavStore.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: webdavservertest/trunk/src/main/resources/log4j.xml =================================================================== (Binary files differ) Property changes on: webdavservertest/trunk/src/main/resources/log4j.xml ___________________________________________________________________ Added: svn:mime-type + application/xml Added: webdavservertest/trunk/src/main/resources/test.odt =================================================================== (Binary files differ) Property changes on: webdavservertest/trunk/src/main/resources/test.odt ___________________________________________________________________ Added: svn:mime-type + application/vnd.oasis.opendocument.text Added: webdavservertest/trunk/src/main/resources/test.txt =================================================================== --- webdavservertest/trunk/src/main/resources/test.txt (rev 0) +++ webdavservertest/trunk/src/main/resources/test.txt 2012-11-09 16:00:03 UTC (rev 563) @@ -0,0 +1 @@ +teste !!! Added: webdavservertest/trunk/src/main/webapp/WEB-INF/web.xml =================================================================== (Binary files differ) Property changes on: webdavservertest/trunk/src/main/webapp/WEB-INF/web.xml ___________________________________________________________________ Added: svn:mime-type + application/xml
participants (1)
-
echatellier@users.nuiton.org