You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ju...@apache.org on 2001/02/26 14:46:16 UTC
cvs commit: jakarta-slide/src/stores/slidestore/reference FileContentStore.java MemoryDescriptorsStore.java
juergen 01/02/26 05:46:16
Modified: src/stores/slidestore/reference FileContentStore.java
MemoryDescriptorsStore.java
Added: src/stores/slidestore/reference/fileDeleter
DeleterWalker.java DirectoryFilter.java
Log:
if resetBeforeStarting is set to true in the domain.xml file all file content file are removed before server start. Please see seperate e-mail for details.
Revision Changes Path
1.1 jakarta-slide/src/stores/slidestore/reference/fileDeleter/DeleterWalker.java
Index: DeleterWalker.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/src/stores/slidestore/reference/fileDeleter/DeleterWalker.java,v 1.1 2001/02/26 13:46:14 juergen Exp $
* $Revision: 1.1 $
* $Date: 2001/02/26 13:46:14 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package slidestore.reference.fileDeleter;
//Java import
import java.io.*;
public class DeleterWalker {
private DirectoryFilter filter;
/**
* Constructor. The starting path (eg C:\, D:\TEMP\) is passed to start the Walker
* @param String
* @param String[]
*/
public DeleterWalker(String path, String[] filterValues) {
filter = new DirectoryFilter();
for (int i = 0; i < filterValues.length; i++) {
filter.addFileName(filterValues[i]);
}
walkDirectory(path);
}
/**
* This allows Walker to walk through the directories looking for files of the given filter
* @param String
* @param int
* @param String
*/
public void walkDirectory(String path) {
try {
File rootFile = new File(path);
String[] fileList = rootFile.list();
for (int i = 0; i < fileList.length; i++) {
File currentFile = new File(path+"\\"+fileList[i]);
if (currentFile.isDirectory()) {
walkDirectory(path+"\\"+currentFile.getName());
}
if (filter.accept(currentFile,path) ) {
currentFile.delete();
File newFile = new File(path);
String[] check = newFile.list();
if (check.length == 0) {
if (!(newFile.delete() ))
System.out.println("UNABLE TO DELETE DIRECTORY "+newFile.getPath());
}
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
1.1 jakarta-slide/src/stores/slidestore/reference/fileDeleter/DirectoryFilter.java
Index: DirectoryFilter.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/src/stores/slidestore/reference/fileDeleter/DirectoryFilter.java,v 1.1 2001/02/26 13:46:14 juergen Exp $
* $Revision: 1.1 $
* $Date: 2001/02/26 13:46:14 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package slidestore.reference.fileDeleter;
//Java imports
import java.util.Hashtable;
import java.io.*;
public class DirectoryFilter {
private Hashtable filter;
public DirectoryFilter() {
filter = new Hashtable();
}
/**
* Add a fileName to the filter. Eg. *.*, *.xml, WalkerFilter.java etc
* @param String
*/
public void addFileName(String fileName) {
if (!(fileName == null))
filter.put(fileName,"");
}
/**
* Is the given file acceptable part of the filter.
* @param java.io.File
* @param String
* @return boolean
*/
public boolean accept(java.io.File file, String path) {
//If the file is hidden then don't return false
if (file.isHidden()) {
return false;
}
//Take into account *.* will override any filter
if ((!((filter.get("*.*")) == null))) {
return true;
}
String fileName = file.getName();
//Check to see if the file name is part of the filter
if ((filter.get(fileName)) == null) {
//The file name is not part of the filter, check to see if the extension
//is part of the filter
String fileExtension = fileName.substring((fileName.lastIndexOf(".")+1),fileName.length());
if ((filter.get("*."+fileExtension)) == null) {
//The file is not part of the filter, return false
return false;
}
}
return true;
}
}
1.5 +29 -8 jakarta-slide/src/stores/slidestore/reference/FileContentStore.java
Index: FileContentStore.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/stores/slidestore/reference/FileContentStore.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FileContentStore.java 2001/02/02 06:28:05 1.4
+++ FileContentStore.java 2001/02/26 13:46:15 1.5
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/stores/slidestore/reference/FileContentStore.java,v 1.4 2001/02/02 06:28:05 remm Exp $
- * $Revision: 1.4 $
- * $Date: 2001/02/02 06:28:05 $
+ * $Header: /home/cvs/jakarta-slide/src/stores/slidestore/reference/FileContentStore.java,v 1.5 2001/02/26 13:46:15 juergen Exp $
+ * $Revision: 1.5 $
+ * $Date: 2001/02/26 13:46:15 $
*
* ====================================================================
*
@@ -76,7 +76,7 @@
* Filesystem implementation of ContentStore.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public class FileContentStore extends AbstractSimpleService
implements ContentStore {
@@ -104,6 +104,16 @@
private boolean version = true;
+
+
+ /**
+ * True if content written from a prior server run should be removed.
+ * WARNING: setting this option to true will remove all files, located
+ * under the RootPath location!
+ */
+ private boolean removePriorContent = false;
+
+
// ---------------------------------------------------- ServiceImpl Methods
@@ -127,6 +137,11 @@
if (versionValue != null) {
version = Boolean.getBoolean(versionValue);
}
+ String removePriorContentValue = (String) parameters.get("resetBeforeStarting");
+ if (removePriorContentValue != null) {
+ removePriorContent = removePriorContentValue.equalsIgnoreCase("true");
+ }
+
}
@@ -159,6 +174,8 @@
public synchronized void initialize(NamespaceAccessToken token)
throws ServiceInitializationFailedException {
try {
+ // remove prior content specified at rootPath
+ if (removePriorContent) reset();
File baseDir = new File(rootpath);
baseDir.mkdirs();
} catch (Exception e) {
@@ -175,6 +192,10 @@
*/
public void reset()
throws ServiceResetFailedException {
+
+ String[] filter = new String[1];
+ filter[0] = "*.*";
+ new slidestore.reference.fileDeleter.DeleterWalker(rootpath, filter );
}
@@ -215,7 +236,7 @@
NodeRevisionContent result = null;
String revisionUri = null;
if (version)
- revisionUri = uri.toString() + "_"
+ revisionUri = uri.toString() + "_"
+ revisionDescriptor.getRevisionNumber();
else
revisionUri = uri.toString();
@@ -227,15 +248,15 @@
result = new NodeRevisionContent();
result.setContent(reader);
result.setContent(is);
- } catch (FileNotFoundException e) {
+ } catch (FileNotFoundException e) {
throw new RevisionNotFoundException
(uri.toString(),
revisionDescriptor.getRevisionNumber());
} catch (IOException e) {
e.printStackTrace();
throw new ServiceAccessException(this, e.getMessage());
- }
- return result;
+ }
+ return result;
}
1.4 +6 -4 jakarta-slide/src/stores/slidestore/reference/MemoryDescriptorsStore.java
Index: MemoryDescriptorsStore.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/stores/slidestore/reference/MemoryDescriptorsStore.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MemoryDescriptorsStore.java 2001/02/21 16:37:04 1.3
+++ MemoryDescriptorsStore.java 2001/02/26 13:46:15 1.4
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/stores/slidestore/reference/MemoryDescriptorsStore.java,v 1.3 2001/02/21 16:37:04 juergen Exp $
- * $Revision: 1.3 $
- * $Date: 2001/02/21 16:37:04 $
+ * $Header: /home/cvs/jakarta-slide/src/stores/slidestore/reference/MemoryDescriptorsStore.java,v 1.4 2001/02/26 13:46:15 juergen Exp $
+ * $Revision: 1.4 $
+ * $Date: 2001/02/26 13:46:15 $
*
* ====================================================================
*
@@ -80,7 +80,7 @@
* Reference implementation.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
public class MemoryDescriptorsStore extends FileContentStore
implements LockStore, NodeStore, RevisionDescriptorsStore,
@@ -194,6 +194,8 @@
*/
public synchronized void reset()
throws ServiceResetFailedException {
+
+ super.reset();
objects = new Hashtable();
permissions = new Hashtable();
locks = new Hashtable();