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 re...@apache.org on 2001/01/08 18:08:44 UTC
cvs commit: jakarta-slide/src/stores/slidestore/file FileDescriptorsStoreNoVersioning.java
remm 01/01/08 09:08:43
Modified: src/stores/slidestore/file
FileDescriptorsStoreNoVersioning.java
Log:
- Commit a new revision of the filesystem descriptors store. It's about 15%
done, but it could be a starting point for anyone interested in working on
that part.
Revision Changes Path
1.2 +414 -126 jakarta-slide/src/stores/slidestore/file/FileDescriptorsStoreNoVersioning.java
Index: FileDescriptorsStoreNoVersioning.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/stores/slidestore/file/FileDescriptorsStoreNoVersioning.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FileDescriptorsStoreNoVersioning.java 2000/10/09 04:58:31 1.1
+++ FileDescriptorsStoreNoVersioning.java 2001/01/08 17:08:38 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/stores/slidestore/file/FileDescriptorsStoreNoVersioning.java,v 1.1 2000/10/09 04:58:31 remm Exp $
- * $Revision: 1.1 $
- * $Date: 2000/10/09 04:58:31 $
+ * $Header: /home/cvs/jakarta-slide/src/stores/slidestore/file/FileDescriptorsStoreNoVersioning.java,v 1.2 2001/01/08 17:08:38 remm Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/01/08 17:08:38 $
*
* ====================================================================
*
@@ -64,11 +64,13 @@
package slidestore.file;
import java.util.Hashtable;
+import java.util.Vector;
import java.util.Enumeration;
import java.util.Date;
import java.io.*;
import org.apache.slide.common.*;
import org.apache.slide.store.*;
+import org.apache.slide.security.*;
import org.apache.slide.structure.*;
import org.apache.slide.content.*;
@@ -76,19 +78,23 @@
* Filesystem implementation of Store.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class FileDescriptorsStoreNoVersioning extends ServiceImpl
- implements ContentStore {
+ implements RevisionDescriptorsStore, RevisionDescriptorStore,
+ SecurityStore, NodeStore {
// -------------------------------------------------------------- Constants
- public static final int BUFFER_SIZE = 2048;
- public static final String CHARACTER_ENCODING = "8859_1";
+ // Object types
+ protected static final int SUBJECT = 0;
+ protected static final int ACTION = 1;
+ protected static final int LINK = 2;
+
// ----------------------------------------------------- Instance Variables
@@ -190,95 +196,312 @@
}
- // --------------------------------------------------- ContentStore Methods
+ // ------------------------------------------------------ NodeStore Methods
/**
- * Retrive revision content.
+ * Retrive an object.
*
- * @param uri Uri
- * @param revisionNumber Node revision number
+ * @param uri Uri of the object we want to retrieve
+ * @exception ServiceAccessException Error accessing the Data Source
+ * @exception ObjectNotFoundException The object to retrieve was not found
*/
- public NodeRevisionContent retrieveRevisionContent
- (Uri uri, NodeRevisionNumber revisionNumber)
- throws ServiceAccessException, RevisionNotFoundException {
- NodeRevisionContent result = null;
- String revisionUri = uri.toString();
+ public ObjectNode retrieveObject(Uri uri)
+ throws ServiceAccessException, ObjectNotFoundException {
+
+ int objectType = SUBJECT;
+ String linkTo = null;
+ ObjectNode result = null;
+ Vector childrenVector = new Vector();
+ Vector linksVector = new Vector();
+ String relative = uri.getRelative();
+ if (relative.equals(""))
+ relative = "/";
+
try {
- File file = new File(rootpath + revisionUri);
- FileInputStream is = new FileInputStream(file);
- InputStreamReader reader = new InputStreamReader
- (is, CHARACTER_ENCODING);
- result = new NodeRevisionContent();
- result.setContent(reader);
- result.setContent(is);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- throw new RevisionNotFoundException(uri.toString(),
- revisionNumber);
+
+
+ File file = new File(rootpath + relative + ".structure");
+ File parentFile = new File(file.getParent());
+ if ((parentFile != null) && (!parentFile.exists())) {
+ parentFile.mkdirs();
+ }
+
+ FileReader reader = new FileReader(file);
+ BufferedReader bfReader = new BufferedReader(reader);
+
+ String type = bfReader.readLine();
+ if (type != null) {
+ objectType = Integer.parseInt(type);
+ }
+ if (objectType == LINK) {
+ linkTo = bfReader.readLine();
+ }
+
+ bfReader.close();
+
+ } catch (FileNotFoundException e) {
+ //e.printStackTrace();
+ // Silent exception, except if we're on the root path
+ if (relative.equals("/"))
+ throw new ObjectNotFoundException(uri);
} catch (IOException e) {
e.printStackTrace();
throw new ServiceAccessException(this, e.getMessage());
- }
- return result;
-
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new ServiceAccessException(this, e.getMessage());
+ }
+
+ // Retrieving the children list
+
+ try {
+
+ File file = new File(rootpath + uri.getRelative());
+ if (file.isDirectory()) {
+
+ String[] children = file.list();
+
+ // Now each of these path need to be converted
+ for (int i=0; i < children.length; i++) {
+ String current = children[i].replace('\\','/');
+ int pos = current.indexOf(uri.toString());
+
+ // DEBUG
+ System.out.println("Adding child :"
+ + current.substring(pos + uri.toString().length()));
+ // END DEBUG
+ childrenVector.addElement
+ (current.substring(pos + uri.toString().length()));
+ }
+
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new ServiceAccessException(this, e.getMessage());
+ }
+
+ switch (objectType) {
+ case SUBJECT :
+ result = new SubjectNode(uri.toString(), childrenVector,
+ linksVector);
+ break;
+ case ACTION :
+ result = new ActionNode(uri.toString(), childrenVector,
+ linksVector);
+ break;
+ case LINK :
+ result = new LinkNode(uri.toString(), childrenVector,
+ linksVector, linkTo);
+ break;
+ }
+
+ return result;
+ }
+
+
+ /**
+ * Update an object.
+ *
+ * @param object Object to update
+ * @exception ServiceAccessException Error accessing the Data Source
+ * @exception ObjectNotFoundException The object to update was not found
+ */
+ public void storeObject(Uri uri, ObjectNode object)
+ throws ServiceAccessException, ObjectNotFoundException {
+ }
+
+
+ /**
+ * Create a new object.
+ *
+ * @param object ObjectNode
+ * @param uri Uri of the object we want to create
+ * @exception ServiceAccessException Error accessing the Data Source
+ * @exception ObjectAlreadyExistsException An object already exists
+ * at this Uri
+ */
+ public void createObject(Uri uri, ObjectNode object)
+ throws ServiceAccessException, ObjectAlreadyExistsException {
+ }
+
+
+ /**
+ * Remove an object.
+ *
+ * @param object Object to remove
+ * @exception ServiceAccessException Error accessing the Data Source
+ * @exception ObjectNotFoundException The object to remove was not found
+ */
+ public void removeObject(Uri uri, ObjectNode object)
+ throws ServiceAccessException, ObjectNotFoundException {
+ }
+
+
+ // --------------------------------------- RevisionDescriptorsStore Methods
+
+
+ /**
+ * Retrieve the revisions informations of an object.
+ *
+ * @param uri Uri
+ * @exception ServiceAccessException Service access error
+ * @exception RevisionDescriptorNotFoundException Revision descriptor
+ * was not found
+ */
+ public NodeRevisionDescriptors retrieveRevisionDescriptors(Uri uri)
+ throws ServiceAccessException, RevisionDescriptorNotFoundException {
+
+ NodeRevisionNumber initialRevision = new NodeRevisionNumber();
+ Hashtable workingRevisions = new Hashtable();
+ Hashtable latestRevisionNumbers = new Hashtable();
+ Hashtable branches = new Hashtable();
+ boolean isVersioned = false;
+
+ return new NodeRevisionDescriptors(uri.toString(), initialRevision,
+ workingRevisions,
+ latestRevisionNumbers,
+ branches, isVersioned);
+ }
+
+
+ /**
+ * Create a new revision information object.
+ *
+ * @param uri Uri
+ * @param revisionDescriptors Node revision descriptors
+ * @exception ServiceAccessException Service access error
+ */
+ public void createRevisionDescriptors
+ (Uri uri, NodeRevisionDescriptors revisionDescriptors)
+ throws ServiceAccessException {
+ }
+
+
+ /**
+ * Update revision information.
+ *
+ * @param uri Uri
+ * @param revisionDescriptors Node revision descriptors
+ * @exception ServiceAccessException Service access error
+ * @exception RevisionDescriptorNotFoundException Revision descriptor
+ * was not found
+ */
+ public void storeRevisionDescriptors
+ (Uri uri, NodeRevisionDescriptors revisionDescriptors)
+ throws ServiceAccessException, RevisionDescriptorNotFoundException {
+ }
+
+
+ /**
+ * Remove revision information.
+ *
+ * @param uri Uri
+ * @exception ServiceAccessException Service access error
+ */
+ public void removeRevisionDescriptors(Uri uri)
+ throws ServiceAccessException {
+ }
+
+
+ // ---------------------------------------- RevisionDescriptorStore Methods
+
+
+ /**
+ * Retrieve an individual object's revision descriptor.
+ *
+ * @param Uri uri
+ * @param revisionNumber Node revision number
+ */
+ public NodeRevisionDescriptor retrieveRevisionDescriptor
+ (Uri uri, NodeRevisionNumber revisionNumber)
+ throws ServiceAccessException, RevisionDescriptorNotFoundException {
+ return null;
}
/**
- * Create a new revision
+ * Create a new revision descriptor.
*
* @param uri Uri
* @param revisionDescriptor Node revision descriptor
- * @param revisionContent Node revision content
+ * @exception ServiceAccessException Service access error
+ */
+ public void createRevisionDescriptor
+ (Uri uri, NodeRevisionDescriptor revisionDescriptor)
+ throws ServiceAccessException {
+ }
+
+
+ /**
+ * Update a revision descriptor.
+ *
+ * @param uri Uri
+ * @param revisionDescriptors Node revision descriptor
+ * @exception ServiceAccessException Service access error
+ * @exception RevisionDescriptorNotFoundException Revision descriptor
+ * was not found
+ */
+ public void storeRevisionDescriptor
+ (Uri uri, NodeRevisionDescriptor revisionDescriptor)
+ throws ServiceAccessException, RevisionDescriptorNotFoundException {
+ }
+
+
+ /**
+ * Remove a revision descriptor.
+ *
+ * @param uri Uri
+ * @param revisionNumber Revision number
+ * @exception ServiceAccessException Service access error
+ */
+ public void removeRevisionDescriptor(Uri uri, NodeRevisionNumber number)
+ throws ServiceAccessException {
+ }
+
+
+ // -------------------------------------------------- SecurityStore Methods
+
+
+ /**
+ * Grant a new permission.
+ *
+ * @param permission Permission we want to create
+ * @exception ServiceAccessException Error accessing the Data Source
*/
- public void createRevisionContent
- (Uri uri, NodeRevisionDescriptor revisionDescriptor,
- NodeRevisionContent revisionContent)
- throws ServiceAccessException, RevisionAlreadyExistException {
- String revisionUri = uri.toString();
+ public void grantPermission(Uri uri, NodePermission permission)
+ throws ServiceAccessException {
try {
- File file = new File(rootpath + revisionUri);
+
+ File file = new File(rootpath + uri + ".acl");
File parentFile = new File(file.getParent());
if ((parentFile != null) && (!parentFile.exists())) {
parentFile.mkdirs();
}
- boolean created = !file.exists();
- if (!created) {
- throw new RevisionAlreadyExistException
- (uri.toString(), revisionDescriptor.getRevisionNumber());
- }
+ FileWriter writer = new FileWriter(file);
+ PrintWriter printer = new PrintWriter(writer);
- InputStream is = revisionContent.streamContent();
-
- if (is != null) {
- OutputStream os = new FileOutputStream(file);
- // We copy 8 ko with each read
- byte[] buffer = new byte[BUFFER_SIZE];
- long position = 0;
- long contentLength = revisionDescriptor.getContentLength();
-
- int nChar = 0;
- while (position < contentLength) {
- nChar = is.read(buffer, 0, BUFFER_SIZE);
- if (nChar == -1) {
- break;
- }
- os.write(buffer, 0, nChar);
- position = position + nChar;
- }
- is.close();
- os.close();
-
- if (position < contentLength) {
- // Not enough bytes read !!!
- throw new IOException("Not enough bytes read");
- }
- } else {
+ Enumeration oldPermissions = enumeratePermissions(uri);
+
+ while (oldPermissions.hasMoreElements()) {
+ NodePermission currentPermission =
+ (NodePermission) oldPermissions.nextElement();
+ printer.println(currentPermission.getSubjectUri());
+ printer.println(currentPermission.getActionUri());
+ printer.println(currentPermission.isInheritable());
+ printer.println(currentPermission.isNegative());
}
+ printer.println(permission.getSubjectUri());
+ printer.println(permission.getActionUri());
+ printer.println(permission.isInheritable());
+ printer.println(permission.isNegative());
+
+ printer.close();
+
} catch (IOException e) {
e.printStackTrace();
throw new ServiceAccessException(this, e.getMessage());
@@ -286,95 +509,160 @@
e.printStackTrace();
throw new ServiceAccessException(this, e.getMessage());
}
+
}
/**
- * Modify the latest revision of an object.
+ * Revoke a permission.
*
- * @param uri Uri
- * @param revisionDescriptor Node revision descriptor
- * @param revisionContent Node revision content
+ * @param permission Permission we want to create
+ * @exception ServiceAccessException Error accessing the Data Source
*/
- public void storeRevisionContent
- (Uri uri, NodeRevisionDescriptor revisionDescriptor,
- NodeRevisionContent revisionContent)
- throws ServiceAccessException, RevisionNotFoundException {
- String revisionUri = uri.toString();
+ public void revokePermission(Uri uri, NodePermission permission)
+ throws ServiceAccessException {
+
try {
- File file = new File(rootpath + revisionUri);
- InputStream is = revisionContent.streamContent();
+ File file = new File(rootpath + uri + ".acl");
+ File parentFile = new File(file.getParent());
+ if ((parentFile != null) && (!parentFile.exists())) {
+ parentFile.mkdirs();
+ }
- if (is != null) {
- OutputStream os = null;
- try {
- os = new FileOutputStream(file);
- } catch (FileNotFoundException ex) {
- // Try to create the parent directory and try again
- File parentFile = new File(file.getParent());
- if ((parentFile != null) && (!parentFile.exists())) {
- parentFile.mkdirs();
- }
- os = new FileOutputStream(file);
- }
- // We copy 8 ko with each read
- byte[] buffer = new byte[BUFFER_SIZE];
- long position = 0;
- long contentLength = revisionDescriptor.getContentLength();
-
- int nChar = 0;
- while (position < contentLength) {
- nChar = is.read(buffer, 0, BUFFER_SIZE);
- if (nChar == -1) {
- break;
- }
- os.write(buffer, 0, nChar);
- position = position + nChar;
- }
- is.close();
- os.close();
-
- if (position < contentLength) {
- // Not enough bytes read !!!
- throw new IOException("Not enough bytes read");
+ FileWriter writer = new FileWriter(file);
+ PrintWriter printer = new PrintWriter(writer);
+
+ Enumeration oldPermissions = enumeratePermissions(uri);
+
+ while (oldPermissions.hasMoreElements()) {
+ NodePermission currentPermission =
+ (NodePermission) oldPermissions.nextElement();
+ if (currentPermission != permission) {
+ printer.println(currentPermission.getSubjectUri());
+ printer.println(currentPermission.getActionUri());
+ printer.println(currentPermission.isInheritable());
+ printer.println(currentPermission.isNegative());
}
- } else {
}
- } catch (FileNotFoundException e) {
+ printer.close();
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new ServiceAccessException(this, e.getMessage());
+ } catch (Exception e) {
e.printStackTrace();
- throw new RevisionNotFoundException
- (uri.toString(), revisionDescriptor.getRevisionNumber());
+ throw new ServiceAccessException(this, e.getMessage());
+ }
+
+ }
+
+
+ /**
+ * Revoke all the permissions on an object.
+ *
+ * @param permission Permission we want to create
+ * @exception ServiceAccessException Error accessing the Data Source
+ */
+ public void revokePermissions(Uri uri)
+ throws ServiceAccessException {
+
+ try {
+
+ File file = new File(rootpath + uri + ".acl");
+ File parentFile = new File(file.getParent());
+ if ((parentFile != null) && (!parentFile.exists())) {
+ parentFile.mkdirs();
+ }
+
+ FileWriter writer = new FileWriter(file);
+ PrintWriter printer = new PrintWriter(writer);
+
+ printer.println();
+
+ printer.close();
+
} catch (IOException e) {
e.printStackTrace();
throw new ServiceAccessException(this, e.getMessage());
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new ServiceAccessException(this, e.getMessage());
}
+
}
/**
- * Remove revision.
+ * Enumerate permissions on an object.
*
- * @param uri Uri
- * @param revisionNumber Node revision number
+ * @param permission Permission we want to create
+ * @exception ServiceAccessException Error accessing the Data Source
*/
- public void removeRevisionContent(Uri uri,
- NodeRevisionNumber revisionNumber)
+ public Enumeration enumeratePermissions(Uri uri)
throws ServiceAccessException {
- String revisionUri = uri.toString();
+ Vector result = new Vector();
+
try {
- File file = new File(rootpath + revisionUri);
- boolean deleted = file.delete();
+
+ File file = new File(rootpath + uri + ".acl");
File parentFile = new File(file.getParent());
- if (parentFile != null) {
- parentFile.delete();
+ if ((parentFile != null) && (!parentFile.exists())) {
+ parentFile.mkdirs();
}
+
+ FileReader reader = new FileReader(file);
+ BufferedReader bfReader = new BufferedReader(reader);
+
+ NodePermission permission = null;
+
+ String subject = null;
+ String action = null;
+ String inheritable = null;
+ String negative = null;
+
+ while (true) {
+
+ subject = bfReader.readLine();
+ if ((subject == null) || (subject.equals("")))
+ break;
+ action = bfReader.readLine();
+ if ((action == null) || (action.equals("")))
+ break;
+ inheritable = bfReader.readLine();
+ if ((inheritable == null) || (inheritable.equals("")))
+ break;
+ negative = bfReader.readLine();
+ if ((negative == null) || (negative.equals("")))
+ break;
+
+ permission =
+ new NodePermission(uri.toString(), subject, action,
+ Boolean.getBoolean(inheritable),
+ Boolean.getBoolean(negative));
+
+ result.addElement(permission);
+
+ }
+
+ bfReader.close();
+
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ // Silent exception
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new ServiceAccessException(this, e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceAccessException(this, e.getMessage());
}
+
+ return result.elements();
+
}
+
}