You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by tr...@apache.org on 2006/10/26 11:11:20 UTC
svn commit: r467925 [6/6] - in /jackrabbit/trunk/jackrabbit:
applications/test/ applications/test/workspaces/default/
applications/test/workspaces/test/ src/main/config/
src/main/java/org/apache/jackrabbit/core/
src/main/java/org/apache/jackrabbit/core...
Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java?view=diff&rev=467925&r1=467924&r2=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java Thu Oct 26 02:11:18 2006
@@ -16,904 +16,12 @@
*/
package org.apache.jackrabbit.core.state.xml;
-import org.apache.jackrabbit.core.NodeId;
-import org.apache.jackrabbit.core.PropertyId;
-import org.apache.jackrabbit.core.fs.BasedFileSystem;
-import org.apache.jackrabbit.core.fs.FileSystem;
-import org.apache.jackrabbit.core.fs.FileSystemException;
-import org.apache.jackrabbit.core.fs.FileSystemResource;
-import org.apache.jackrabbit.core.fs.local.LocalFileSystem;
-import org.apache.jackrabbit.core.nodetype.NodeDefId;
-import org.apache.jackrabbit.core.nodetype.PropDefId;
-import org.apache.jackrabbit.core.state.AbstractPersistenceManager;
-import org.apache.jackrabbit.core.state.ItemStateException;
-import org.apache.jackrabbit.core.state.NoSuchItemStateException;
-import org.apache.jackrabbit.core.state.NodeReferences;
-import org.apache.jackrabbit.core.state.NodeReferencesId;
-import org.apache.jackrabbit.core.state.NodeState;
-import org.apache.jackrabbit.core.state.PMContext;
-import org.apache.jackrabbit.core.state.PropertyState;
-import org.apache.jackrabbit.core.state.util.BLOBStore;
-import org.apache.jackrabbit.core.state.util.FileSystemBLOBStore;
-import org.apache.jackrabbit.core.state.util.ResourceBasedBLOBStore;
-import org.apache.jackrabbit.core.util.DOMWalker;
-import org.apache.jackrabbit.core.value.BLOBFileValue;
-import org.apache.jackrabbit.core.value.InternalValue;
-import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.util.Text;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.jcr.PropertyType;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
/**
- * <code>XMLPersistenceManager</code> is a <code>FileSystem</code>-based
- * <code>PersistenceManager</code> that persists <code>ItemState</code>
- * and <code>NodeReferences</code> objects in XML format.
+ * Legacy class kept for backward compatibility reasons.
+ * @deprecated use {@link org.apache.jackrabbit.core.persistence.xml.XMLPersistenceManager}
+ * instead.
*/
-public class XMLPersistenceManager extends AbstractPersistenceManager {
-
- private static Logger log = LoggerFactory.getLogger(XMLPersistenceManager.class);
-
- /**
- * hexdigits for toString
- */
- private static final char[] HEXDIGITS = "0123456789abcdef".toCharArray();
-
- /**
- * The default encoding used in serialization
- */
- public static final String DEFAULT_ENCODING = "UTF-8";
-
- /**
- * The XML elements and attributes used in serialization
- */
- private static final String NODE_ELEMENT = "node";
- private static final String UUID_ATTRIBUTE = "uuid";
- private static final String NODETYPE_ATTRIBUTE = "nodeType";
- private static final String PARENTUUID_ATTRIBUTE = "parentUUID";
- private static final String DEFINITIONID_ATTRIBUTE = "definitionId";
- private static final String MODCOUNT_ATTRIBUTE = "modCount";
-
- private static final String MIXINTYPES_ELEMENT = "mixinTypes";
- private static final String MIXINTYPE_ELEMENT = "mixinType";
-
- private static final String PROPERTIES_ELEMENT = "properties";
- private static final String PROPERTY_ELEMENT = "property";
- private static final String NAME_ATTRIBUTE = "name";
- private static final String TYPE_ATTRIBUTE = "type";
- private static final String MULTIVALUED_ATTRIBUTE = "multiValued";
-
- private static final String VALUES_ELEMENT = "values";
- private static final String VALUE_ELEMENT = "value";
-
- private static final String NODES_ELEMENT = "nodes";
-
- private static final String NODEREFERENCES_ELEMENT = "references";
- private static final String TARGETID_ATTRIBUTE = "targetId";
- private static final String NODEREFERENCE_ELEMENT = "reference";
- private static final String PROPERTYID_ATTRIBUTE = "propertyId";
-
- private static final String NODEFILENAME = ".node.xml";
-
- private static final String NODEREFSFILENAME = ".references.xml";
-
- private boolean initialized;
-
- // file system where the item state is stored
- private FileSystem itemStateFS;
- // file system where BLOB data is stored
- private FileSystem blobFS;
- // BLOBStore that manages BLOB data in the file system
- private BLOBStore blobStore;
-
- /**
- * Creates a new <code>XMLPersistenceManager</code> instance.
- */
- public XMLPersistenceManager() {
- initialized = false;
- }
-
- private String buildNodeFolderPath(NodeId id) {
- StringBuffer sb = new StringBuffer();
- char[] chars = id.getUUID().toString().toCharArray();
- int cnt = 0;
- for (int i = 0; i < chars.length; i++) {
- if (chars[i] == '-') {
- continue;
- }
- //if (cnt > 0 && cnt % 4 == 0) {
- if (cnt == 4 || cnt == 8) {
- sb.append('/');
- }
- sb.append(chars[i]);
- cnt++;
- }
- return sb.toString();
- }
-
- private String buildPropFilePath(PropertyId id) {
- String fileName;
- try {
- MessageDigest md5 = MessageDigest.getInstance("MD5");
- md5.update(id.getName().getNamespaceURI().getBytes());
- md5.update(id.getName().getLocalName().getBytes());
- byte[] bytes = md5.digest();
- char[] chars = new char[32];
- for (int i = 0, j = 0; i < 16; i++) {
- chars[j++] = HEXDIGITS[(bytes[i] >> 4) & 0x0f];
- chars[j++] = HEXDIGITS[bytes[i] & 0x0f];
- }
- fileName = new String(chars) + ".xml";
- } catch (NoSuchAlgorithmException nsae) {
- // should never get here as MD5 should always be available in the JRE
- String msg = "MD5 not available";
- log.error(msg, nsae);
- throw new InternalError(msg + nsae);
- }
- return buildNodeFolderPath(id.getParentId()) + "/" + fileName;
- }
-
- private String buildNodeFilePath(NodeId id) {
- return buildNodeFolderPath(id) + "/" + NODEFILENAME;
- }
-
- private String buildNodeReferencesFilePath(NodeReferencesId id) {
- return buildNodeFolderPath(id.getTargetId()) + "/" + NODEREFSFILENAME;
- }
-
- private void readState(DOMWalker walker, NodeState state)
- throws ItemStateException {
- // first do some paranoid sanity checks
- if (!walker.getName().equals(NODE_ELEMENT)) {
- String msg = "invalid serialization format (unexpected element: "
- + walker.getName() + ")";
- log.debug(msg);
- throw new ItemStateException(msg);
- }
- // check uuid
- if (!state.getNodeId().getUUID().toString().equals(walker.getAttribute(UUID_ATTRIBUTE))) {
- String msg = "invalid serialized state: uuid mismatch";
- log.debug(msg);
- throw new ItemStateException(msg);
- }
- // check nodetype
- String ntName = walker.getAttribute(NODETYPE_ATTRIBUTE);
- if (!QName.valueOf(ntName).equals(state.getNodeTypeName())) {
- String msg = "invalid serialized state: nodetype mismatch";
- log.debug(msg);
- throw new ItemStateException(msg);
- }
-
- // now we're ready to read state
-
- // primary parent
- String parentUUID = walker.getAttribute(PARENTUUID_ATTRIBUTE);
- if (parentUUID.length() > 0) {
- state.setParentId(NodeId.valueOf(parentUUID));
- }
-
- // definition id
- String definitionId = walker.getAttribute(DEFINITIONID_ATTRIBUTE);
- state.setDefinitionId(NodeDefId.valueOf(definitionId));
-
- // modification count
- String modCount = walker.getAttribute(MODCOUNT_ATTRIBUTE);
- state.setModCount(Short.parseShort(modCount));
-
- // mixin types
- if (walker.enterElement(MIXINTYPES_ELEMENT)) {
- Set mixins = new HashSet();
- while (walker.iterateElements(MIXINTYPE_ELEMENT)) {
- mixins.add(QName.valueOf(walker.getAttribute(NAME_ATTRIBUTE)));
- }
- if (mixins.size() > 0) {
- state.setMixinTypeNames(mixins);
- }
- walker.leaveElement();
- }
-
- // property entries
- if (walker.enterElement(PROPERTIES_ELEMENT)) {
- while (walker.iterateElements(PROPERTY_ELEMENT)) {
- String propName = walker.getAttribute(NAME_ATTRIBUTE);
- // @todo deserialize type and values
- state.addPropertyName(QName.valueOf(propName));
- }
- walker.leaveElement();
- }
-
- // child node entries
- if (walker.enterElement(NODES_ELEMENT)) {
- while (walker.iterateElements(NODE_ELEMENT)) {
- String childName = walker.getAttribute(NAME_ATTRIBUTE);
- String childUUID = walker.getAttribute(UUID_ATTRIBUTE);
- state.addChildNodeEntry(QName.valueOf(childName), NodeId.valueOf(childUUID));
- }
- walker.leaveElement();
- }
- }
-
- private void readState(DOMWalker walker, PropertyState state)
- throws ItemStateException {
- // first do some paranoid sanity checks
- if (!walker.getName().equals(PROPERTY_ELEMENT)) {
- String msg = "invalid serialization format (unexpected element: "
- + walker.getName() + ")";
- log.debug(msg);
- throw new ItemStateException(msg);
- }
- // check name
- if (!state.getName().equals(QName.valueOf(walker.getAttribute(NAME_ATTRIBUTE)))) {
- String msg = "invalid serialized state: name mismatch";
- log.debug(msg);
- throw new ItemStateException(msg);
- }
- // check parentUUID
- NodeId parentId = NodeId.valueOf(walker.getAttribute(PARENTUUID_ATTRIBUTE));
- if (!parentId.equals(state.getParentId())) {
- String msg = "invalid serialized state: parentUUID mismatch";
- log.debug(msg);
- throw new ItemStateException(msg);
- }
-
- // now we're ready to read state
-
- // type
- String typeName = walker.getAttribute(TYPE_ATTRIBUTE);
- int type;
- try {
- type = PropertyType.valueFromName(typeName);
- } catch (IllegalArgumentException iae) {
- // should never be getting here
- throw new ItemStateException("unexpected property-type: " + typeName, iae);
- }
- state.setType(type);
-
- // multiValued
- String multiValued = walker.getAttribute(MULTIVALUED_ATTRIBUTE);
- state.setMultiValued(Boolean.getBoolean(multiValued));
-
- // definition id
- String definitionId = walker.getAttribute(DEFINITIONID_ATTRIBUTE);
- state.setDefinitionId(PropDefId.valueOf(definitionId));
-
- // modification count
- String modCount = walker.getAttribute(MODCOUNT_ATTRIBUTE);
- state.setModCount(Short.parseShort(modCount));
-
- // values
- ArrayList values = new ArrayList();
- if (walker.enterElement(VALUES_ELEMENT)) {
- while (walker.iterateElements(VALUE_ELEMENT)) {
- // read serialized value
- String content = walker.getContent();
- if (PropertyType.STRING == type) {
- // STRING value can be empty; ignore length
- values.add(InternalValue.valueOf(content, type));
- } else if (content.length() > 0) {
- // non-empty non-STRING value
- if (type == PropertyType.BINARY) {
- try {
- // special handling required for binary value:
- // the value stores the id of the BLOB data
- // in the BLOB store
- if (blobStore instanceof ResourceBasedBLOBStore) {
- // optimization: if the BLOB store is resource-based
- // retrieve the resource directly rather than having
- // to read the BLOB from an input stream
- FileSystemResource fsRes =
- ((ResourceBasedBLOBStore) blobStore).getResource(content);
- values.add(InternalValue.create(fsRes));
- } else {
- InputStream in = blobStore.get(content);
- try {
- values.add(InternalValue.create(in, false));
- } finally {
- try {
- in.close();
- } catch (IOException e) {
- // ignore
- }
- }
- }
- } catch (Exception e) {
- String msg = "error while reading serialized binary value";
- log.debug(msg);
- throw new ItemStateException(msg, e);
- }
- } else {
- // non-empty non-STRING non-BINARY value
- values.add(InternalValue.valueOf(content, type));
- }
- } else {
- // empty non-STRING value
- log.warn(state.getPropertyId() + ": ignoring empty value of type "
- + PropertyType.nameFromValue(type));
- }
- }
- walker.leaveElement();
- }
- state.setValues((InternalValue[])
- values.toArray(new InternalValue[values.size()]));
- }
-
- private void readState(DOMWalker walker, NodeReferences refs)
- throws ItemStateException {
- // first do some paranoid sanity checks
- if (!walker.getName().equals(NODEREFERENCES_ELEMENT)) {
- String msg = "invalid serialization format (unexpected element: " + walker.getName() + ")";
- log.debug(msg);
- throw new ItemStateException(msg);
- }
- // check targetId
- if (!refs.getId().equals(NodeReferencesId.valueOf(walker.getAttribute(TARGETID_ATTRIBUTE)))) {
- String msg = "invalid serialized state: targetId mismatch";
- log.debug(msg);
- throw new ItemStateException(msg);
- }
-
- // now we're ready to read the references data
-
- // property id's
- refs.clearAllReferences();
- while (walker.iterateElements(NODEREFERENCE_ELEMENT)) {
- refs.addReference(PropertyId.valueOf(walker.getAttribute(PROPERTYID_ATTRIBUTE)));
- }
- }
-
- //---------------------------------------------------< PersistenceManager >
- /**
- * {@inheritDoc}
- */
- public void init(PMContext context) throws Exception {
- if (initialized) {
- throw new IllegalStateException("already initialized");
- }
-
- itemStateFS = new BasedFileSystem(context.getFileSystem(), "/data");
-
- /**
- * store BLOB data in local file system in a sub directory
- * of the workspace home directory
- */
- LocalFileSystem blobFS = new LocalFileSystem();
- blobFS.setRoot(new File(context.getHomeDir(), "blobs"));
- blobFS.init();
- this.blobFS = blobFS;
- blobStore = new FileSystemBLOBStore(blobFS);
-
- initialized = true;
- }
-
- /**
- * {@inheritDoc}
- */
- public synchronized void close() throws Exception {
- if (!initialized) {
- throw new IllegalStateException("not initialized");
- }
-
- try {
- // close BLOB file system
- blobFS.close();
- blobFS = null;
- blobStore = null;
- /**
- * there's no need close the item state store because it
- * is based in the workspace's file system which is
- * closed by the repository
- */
- } finally {
- initialized = false;
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public synchronized NodeState load(NodeId id)
- throws NoSuchItemStateException, ItemStateException {
-
- if (!initialized) {
- throw new IllegalStateException("not initialized");
- }
-
- Exception e = null;
- String nodeFilePath = buildNodeFilePath(id);
-
- try {
- if (!itemStateFS.isFile(nodeFilePath)) {
- throw new NoSuchItemStateException(id.toString());
- }
- InputStream in = itemStateFS.getInputStream(nodeFilePath);
-
- try {
- DOMWalker walker = new DOMWalker(in);
- String ntName = walker.getAttribute(NODETYPE_ATTRIBUTE);
-
- NodeState state = createNew(id);
- state.setNodeTypeName(QName.valueOf(ntName));
- readState(walker, state);
- return state;
- } finally {
- in.close();
- }
- } catch (IOException ioe) {
- e = ioe;
- // fall through
- } catch (FileSystemException fse) {
- e = fse;
- // fall through
- }
- String msg = "failed to read node state: " + id;
- log.debug(msg);
- throw new ItemStateException(msg, e);
- }
-
- /**
- * {@inheritDoc}
- */
- public synchronized PropertyState load(PropertyId id)
- throws NoSuchItemStateException, ItemStateException {
-
- if (!initialized) {
- throw new IllegalStateException("not initialized");
- }
-
- Exception e = null;
- String propFilePath = buildPropFilePath(id);
-
- try {
- if (!itemStateFS.isFile(propFilePath)) {
- throw new NoSuchItemStateException(id.toString());
- }
- InputStream in = itemStateFS.getInputStream(propFilePath);
- try {
- DOMWalker walker = new DOMWalker(in);
- PropertyState state = createNew(id);
- readState(walker, state);
- return state;
- } finally {
- in.close();
- }
- } catch (IOException ioe) {
- e = ioe;
- // fall through
- } catch (FileSystemException fse) {
- e = fse;
- // fall through
- }
- String msg = "failed to read property state: " + id.toString();
- log.debug(msg);
- throw new ItemStateException(msg, e);
- }
-
- /**
- * {@inheritDoc}
- */
- protected void store(NodeState state) throws ItemStateException {
- if (!initialized) {
- throw new IllegalStateException("not initialized");
- }
-
- NodeId id = state.getNodeId();
- String nodeFilePath = buildNodeFilePath(id);
- FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath);
- try {
- nodeFile.makeParentDirs();
- OutputStream os = nodeFile.getOutputStream();
- Writer writer = null;
- try {
- String encoding = DEFAULT_ENCODING;
- try {
- writer = new BufferedWriter(new OutputStreamWriter(os, encoding));
- } catch (UnsupportedEncodingException e) {
- // should never get here!
- OutputStreamWriter osw = new OutputStreamWriter(os);
- encoding = osw.getEncoding();
- writer = new BufferedWriter(osw);
- }
-
- writer.write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n");
- writer.write("<" + NODE_ELEMENT + " "
- + UUID_ATTRIBUTE + "=\"" + id.getUUID() + "\" "
- + PARENTUUID_ATTRIBUTE + "=\"" + (state.getParentId() == null ? "" : state.getParentId().getUUID().toString()) + "\" "
- + DEFINITIONID_ATTRIBUTE + "=\"" + state.getDefinitionId().toString() + "\" "
- + MODCOUNT_ATTRIBUTE + "=\"" + state.getModCount() + "\" "
- + NODETYPE_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(state.getNodeTypeName().toString()) + "\">\n");
-
- // mixin types
- writer.write("\t<" + MIXINTYPES_ELEMENT + ">\n");
- Iterator iter = state.getMixinTypeNames().iterator();
- while (iter.hasNext()) {
- writer.write("\t\t<" + MIXINTYPE_ELEMENT + " "
- + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(iter.next().toString()) + "\"/>\n");
- }
- writer.write("\t</" + MIXINTYPES_ELEMENT + ">\n");
-
- // properties
- writer.write("\t<" + PROPERTIES_ELEMENT + ">\n");
- iter = state.getPropertyNames().iterator();
- while (iter.hasNext()) {
- QName propName = (QName) iter.next();
- writer.write("\t\t<" + PROPERTY_ELEMENT + " "
- + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(propName.toString()) + "\">\n");
- // @todo serialize type, definition id and values
- writer.write("\t\t</" + PROPERTY_ELEMENT + ">\n");
- }
- writer.write("\t</" + PROPERTIES_ELEMENT + ">\n");
-
- // child nodes
- writer.write("\t<" + NODES_ELEMENT + ">\n");
- iter = state.getChildNodeEntries().iterator();
- while (iter.hasNext()) {
- NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) iter.next();
- writer.write("\t\t<" + NODE_ELEMENT + " "
- + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(entry.getName().toString()) + "\" "
- + UUID_ATTRIBUTE + "=\"" + entry.getId().getUUID().toString() + "\">\n");
- writer.write("\t\t</" + NODE_ELEMENT + ">\n");
- }
- writer.write("\t</" + NODES_ELEMENT + ">\n");
-
- writer.write("</" + NODE_ELEMENT + ">\n");
- } finally {
- writer.close();
- }
- } catch (Exception e) {
- String msg = "failed to write node state: " + id;
- log.debug(msg);
- throw new ItemStateException(msg, e);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- protected void store(PropertyState state) throws ItemStateException {
- if (!initialized) {
- throw new IllegalStateException("not initialized");
- }
-
- String propFilePath = buildPropFilePath(state.getPropertyId());
- FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath);
- try {
- propFile.makeParentDirs();
- OutputStream os = propFile.getOutputStream();
- // write property state to xml file
- Writer writer = null;
- try {
- String encoding = DEFAULT_ENCODING;
- try {
- writer = new BufferedWriter(new OutputStreamWriter(os, encoding));
- } catch (UnsupportedEncodingException e) {
- // should never get here!
- OutputStreamWriter osw = new OutputStreamWriter(os);
- encoding = osw.getEncoding();
- writer = new BufferedWriter(osw);
- }
-
- String typeName;
- int type = state.getType();
- try {
- typeName = PropertyType.nameFromValue(type);
- } catch (IllegalArgumentException iae) {
- // should never be getting here
- throw new ItemStateException("unexpected property-type ordinal: " + type, iae);
- }
-
- writer.write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n");
- writer.write("<" + PROPERTY_ELEMENT + " "
- + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(state.getName().toString()) + "\" "
- + PARENTUUID_ATTRIBUTE + "=\"" + state.getParentId().getUUID() + "\" "
- + MULTIVALUED_ATTRIBUTE + "=\"" + Boolean.toString(state.isMultiValued()) + "\" "
- + DEFINITIONID_ATTRIBUTE + "=\"" + state.getDefinitionId().toString() + "\" "
- + MODCOUNT_ATTRIBUTE + "=\"" + state.getModCount() + "\" "
- + TYPE_ATTRIBUTE + "=\"" + typeName + "\">\n");
- // values
- writer.write("\t<" + VALUES_ELEMENT + ">\n");
- InternalValue[] values = state.getValues();
- if (values != null) {
- for (int i = 0; i < values.length; i++) {
- writer.write("\t\t<" + VALUE_ELEMENT + ">");
- InternalValue val = values[i];
- if (val != null) {
- if (type == PropertyType.BINARY) {
- // special handling required for binary value:
- // put binary value in BLOB store
- BLOBFileValue blobVal = (BLOBFileValue) val.internalValue();
- InputStream in = blobVal.getStream();
- String blobId = blobStore.createId(state.getPropertyId(), i);
- try {
- blobStore.put(blobId, in, blobVal.getLength());
- } finally {
- try {
- in.close();
- } catch (IOException e) {
- // ignore
- }
- }
- // store id of BLOB as property value
- writer.write(blobId);
- // replace value instance with value backed by resource
- // in BLOB store and discard old value instance (e.g. temp file)
- if (blobStore instanceof ResourceBasedBLOBStore) {
- // optimization: if the BLOB store is resource-based
- // retrieve the resource directly rather than having
- // to read the BLOB from an input stream
- FileSystemResource fsRes =
- ((ResourceBasedBLOBStore) blobStore).getResource(blobId);
- values[i] = InternalValue.create(fsRes);
- } else {
- in = blobStore.get(blobId);
- try {
- values[i] = InternalValue.create(in, false);
- } finally {
- try {
- in.close();
- } catch (IOException e) {
- // ignore
- }
- }
- }
- blobVal.discard();
- } else {
- writer.write(Text.encodeIllegalXMLCharacters(val.toString()));
- }
- }
- writer.write("</" + VALUE_ELEMENT + ">\n");
- }
- }
- writer.write("\t</" + VALUES_ELEMENT + ">\n");
- writer.write("</" + PROPERTY_ELEMENT + ">\n");
- } finally {
- writer.close();
- }
- } catch (Exception e) {
- String msg = "failed to store property state: " + state.getParentId() + "/" + state.getName();
- log.debug(msg);
- throw new ItemStateException(msg, e);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- protected void destroy(NodeState state) throws ItemStateException {
- if (!initialized) {
- throw new IllegalStateException("not initialized");
- }
-
- NodeId id = state.getNodeId();
- String nodeFilePath = buildNodeFilePath(id);
- FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath);
- try {
- if (nodeFile.exists()) {
- // delete resource and prune empty parent folders
- nodeFile.delete(true);
- }
- } catch (FileSystemException fse) {
- String msg = "failed to delete node state: " + id;
- log.debug(msg);
- throw new ItemStateException(msg, fse);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- protected void destroy(PropertyState state) throws ItemStateException {
- if (!initialized) {
- throw new IllegalStateException("not initialized");
- }
-
- // delete binary values (stored as files)
- InternalValue[] values = state.getValues();
- if (values != null) {
- for (int i = 0; i < values.length; i++) {
- InternalValue val = values[i];
- if (val != null) {
- if (val.getType() == PropertyType.BINARY) {
- BLOBFileValue blobVal = (BLOBFileValue) val.internalValue();
- // delete blob file and prune empty parent folders
- blobVal.delete(true);
- }
- }
- }
- }
- // delete property file
- String propFilePath = buildPropFilePath(state.getPropertyId());
- FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath);
- try {
- if (propFile.exists()) {
- // delete resource and prune empty parent folders
- propFile.delete(true);
- }
- } catch (FileSystemException fse) {
- String msg = "failed to delete property state: " + state.getParentId() + "/" + state.getName();
- log.debug(msg);
- throw new ItemStateException(msg, fse);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public synchronized NodeReferences load(NodeReferencesId id)
- throws NoSuchItemStateException, ItemStateException {
-
- if (!initialized) {
- throw new IllegalStateException("not initialized");
- }
-
- Exception e = null;
- String refsFilePath = buildNodeReferencesFilePath(id);
- try {
- if (!itemStateFS.isFile(refsFilePath)) {
- throw new NoSuchItemStateException(id.toString());
- }
-
- InputStream in = itemStateFS.getInputStream(refsFilePath);
-
- try {
- DOMWalker walker = new DOMWalker(in);
- NodeReferences refs = new NodeReferences(id);
- readState(walker, refs);
- return refs;
- } finally {
- in.close();
- }
- } catch (IOException ioe) {
- e = ioe;
- // fall through
- } catch (FileSystemException fse) {
- e = fse;
- // fall through
- }
- String msg = "failed to load references: " + id;
- log.debug(msg);
- throw new ItemStateException(msg, e);
- }
-
- /**
- * {@inheritDoc}
- */
- protected void store(NodeReferences refs) throws ItemStateException {
- if (!initialized) {
- throw new IllegalStateException("not initialized");
- }
-
- NodeReferencesId id = refs.getId();
- String refsFilePath = buildNodeReferencesFilePath(id);
- FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath);
- try {
- refsFile.makeParentDirs();
- OutputStream os = refsFile.getOutputStream();
- BufferedWriter writer = null;
- try {
- String encoding = DEFAULT_ENCODING;
- try {
- writer = new BufferedWriter(new OutputStreamWriter(os, encoding));
- } catch (UnsupportedEncodingException e) {
- // should never get here!
- OutputStreamWriter osw = new OutputStreamWriter(os);
- encoding = osw.getEncoding();
- writer = new BufferedWriter(osw);
- }
- writer.write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n");
- writer.write("<" + NODEREFERENCES_ELEMENT + " "
- + TARGETID_ATTRIBUTE + "=\"" + refs.getId() + "\">\n");
- // write references (i.e. the id's of the REFERENCE properties)
- Iterator iter = refs.getReferences().iterator();
- while (iter.hasNext()) {
- PropertyId propId = (PropertyId) iter.next();
- writer.write("\t<" + NODEREFERENCE_ELEMENT + " "
- + PROPERTYID_ATTRIBUTE + "=\"" + propId + "\"/>\n");
- }
- writer.write("</" + NODEREFERENCES_ELEMENT + ">\n");
- } finally {
- writer.close();
- }
- } catch (Exception e) {
- String msg = "failed to store references: " + id;
- log.debug(msg);
- throw new ItemStateException(msg, e);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- protected void destroy(NodeReferences refs) throws ItemStateException {
- if (!initialized) {
- throw new IllegalStateException("not initialized");
- }
-
- NodeReferencesId id = refs.getId();
- String refsFilePath = buildNodeReferencesFilePath(id);
- FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath);
- try {
- if (refsFile.exists()) {
- // delete resource and prune empty parent folders
- refsFile.delete(true);
- }
- } catch (FileSystemException fse) {
- String msg = "failed to delete references: " + id;
- log.debug(msg);
- throw new ItemStateException(msg, fse);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public synchronized boolean exists(NodeId id) throws ItemStateException {
- if (!initialized) {
- throw new IllegalStateException("not initialized");
- }
-
- try {
- String nodeFilePath = buildNodeFilePath(id);
- FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath);
- return nodeFile.exists();
- } catch (FileSystemException fse) {
- String msg = "failed to check existence of item state: " + id;
- log.debug(msg);
- throw new ItemStateException(msg, fse);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public synchronized boolean exists(PropertyId id) throws ItemStateException {
- if (!initialized) {
- throw new IllegalStateException("not initialized");
- }
-
- try {
- String propFilePath = buildPropFilePath(id);
- FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath);
- return propFile.exists();
- } catch (FileSystemException fse) {
- String msg = "failed to check existence of item state: " + id;
- log.error(msg, fse);
- throw new ItemStateException(msg, fse);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public synchronized boolean exists(NodeReferencesId id)
- throws ItemStateException {
-
- if (!initialized) {
- throw new IllegalStateException("not initialized");
- }
+public class XMLPersistenceManager
+ extends org.apache.jackrabbit.core.persistence.xml.XMLPersistenceManager {
- try {
- String refsFilePath = buildNodeReferencesFilePath(id);
- FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath);
- return refsFile.exists();
- } catch (FileSystemException fse) {
- String msg = "failed to check existence of references: " + id;
- log.debug(msg);
- throw new ItemStateException(msg, fse);
- }
- }
-}
+}
\ No newline at end of file
Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/test-repository.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/test-repository.xml?view=diff&rev=467925&r1=467924&r2=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/test-repository.xml (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/test-repository.xml Thu Oct 26 02:11:18 2006
@@ -67,7 +67,7 @@
persistence manager of the workspace:
class: FQN of class implementing the PersistenceManager interface
-->
- <PersistenceManager class="org.apache.jackrabbit.core.state.db.DerbyPersistenceManager">
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.db.DerbyPersistenceManager">
<param name="url" value="jdbc:derby:${wsp.home}/db;create=true"/>
<param name="schemaObjectPrefix" value="${wsp.name}_"/>
</PersistenceManager>
@@ -98,7 +98,7 @@
a 'normal' persistence manager, but this could change in future
implementations.
-->
- <PersistenceManager class="org.apache.jackrabbit.core.state.db.DerbyPersistenceManager">
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.db.DerbyPersistenceManager">
<param name="url" value="jdbc:derby:${rep.home}/version/db;create=true"/>
<param name="schemaObjectPrefix" value="version_"/>
</PersistenceManager>
Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java?view=diff&rev=467925&r1=467924&r2=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java Thu Oct 26 02:11:18 2006
@@ -21,6 +21,7 @@
import org.apache.jackrabbit.core.NodeImpl;
import org.apache.jackrabbit.core.PropertyId;
import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.persistence.PersistenceManager;
import org.apache.jackrabbit.core.fs.FileSystem;
import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
import org.apache.jackrabbit.core.observation.DelegatingObservationDispatcher;
@@ -32,7 +33,6 @@
import org.apache.jackrabbit.core.state.NodeReferences;
import org.apache.jackrabbit.core.state.NodeReferencesId;
import org.apache.jackrabbit.core.state.NodeState;
-import org.apache.jackrabbit.core.state.PersistenceManager;
import org.apache.jackrabbit.core.state.PropertyState;
import org.apache.jackrabbit.core.state.SharedItemStateManager;
import org.apache.jackrabbit.core.state.ItemStateListener;
Modified: jackrabbit/trunk/jackrabbit/src/site/xdoc/doc/config.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/site/xdoc/doc/config.xml?view=diff&rev=467925&r1=467924&r2=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/site/xdoc/doc/config.xml (original)
+++ jackrabbit/trunk/jackrabbit/src/site/xdoc/doc/config.xml Thu Oct 26 02:11:18 2006
@@ -160,7 +160,7 @@
<FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
<param name="path" value="${wsp.home}"/>
</FileSystem>
- <PersistenceManager class="org.apache.jackrabbit.core.state.db.DerbyPersistenceManager">
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.db.DerbyPersistenceManager">
<param name="url" value="jdbc:derby:${wsp.home}/db;create=true"/>
<param name="schemaObjectPrefix" value="${wsp.name}_"/>
</PersistenceManager>
@@ -200,7 +200,7 @@
<FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
<param name="path" value="${rep.home}/version"/>
</FileSystem>
- <PersistenceManager class="org.apache.jackrabbit.core.state.db.DerbyPersistenceManager">
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.db.DerbyPersistenceManager">
<param name="url" value="jdbc:derby:${rep.home}/version/db;create=true"/>
<param name="schemaObjectPrefix" value="version_"/>
</PersistenceManager>
@@ -249,7 +249,7 @@
The <code>class</code> attribute of the <code>PersistenceManager</code>
element contains the fully qualified class name of the persistence
manager implementation class. The class must implement the
- <code>org.apache.jackrabbit.core.state.PersistenceManager</code>
+ <code>org.apache.jackrabbit.core.persistence.PersistenceManager</code>
interface and have an empty default constructor. String properties
can be assigned using the <code>param</code> elements according to
the JavaBean conventions.
@@ -260,7 +260,9 @@
</p>
<subsection name="InMemPersistenceManager" id="InMemPersistenceManager">
<p>
- The <code>org.apache.jackrabbit.core.state.mem.InMemPersistenceManager</code>
+ The <code>
+ org.apache.jackrabbit.core.persistence.mem.InMemPersistenceManager
+ </code>
class implements a simple persistence manager that keeps all content
in memory. A custom binary serializer is optionally used to load
and store the persistent state during initialization and shutdown
@@ -298,7 +300,9 @@
</subsection>
<subsection name="ObjectPersistenceManager" id="ObjectPersistenceManager">
<p>
- The <code>org.apache.jackrabbit.core.state.obj.ObjectPersistenceManager</code>
+ The <code>
+ org.apache.jackrabbit.core.persistence.obj.ObjectPersistenceManager
+ </code>
class implements a persistence manager that uses a custom binary
serialization format to store the managed content directly in
the underlying virtual file system. The virtual file system is
@@ -315,7 +319,9 @@
</subsection>
<subsection name="XMLPersistenceManager" id="XMLPersistenceManager">
<p>
- The <code>org.apache.jackrabbit.core.state.xml.XMLPersistenceManager</code>
+ The <code>
+ org.apache.jackrabbit.core.persistence.xml.XMLPersistenceManager
+ </code>
class implements a persistence manager that uses XML files stored
in the underlying virtual file system. The difference between this
persistence manager and the ObjectPersistenceManager is the storage
@@ -334,7 +340,9 @@
</subsection>
<subsection name="SimpleDbPersistenceManager" id="SimpleDbPersistenceManager">
<p>
- The <code>org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager</code>
+ The <code>
+ org.apache.jackrabbit.core.persistence.db.SimpleDbPersistenceManager
+ </code>
class implements a generic Java Database Connectivity (JDBC) -based
persistence manager. Content is stored in a set of simple
non-normalized tables that are created automatically unless they
@@ -383,7 +391,9 @@
</subsection>
<subsection name="DerbyPersistenceManager" id="DerbyPersistenceManager">
<p>
- The <code>org.apache.jackrabbit.core.state.db.DerbyPersistenceManager</code>
+ The <code>
+ org.apache.jackrabbit.core.persistence.db.DerbyPersistenceManager
+ </code>
is a subclass of the <code>SimpleDbPersistenceManager</code>. It
implements a persistence manager that uses an embedded
<a href="http://db.apache.org/derby/">Apache Derby</a> database
Modified: jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/config/RepositoryConfigTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/config/RepositoryConfigTest.java?view=diff&rev=467925&r1=467924&r2=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/config/RepositoryConfigTest.java (original)
+++ jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/config/RepositoryConfigTest.java Thu Oct 26 02:11:18 2006
@@ -16,9 +16,11 @@
*/
package org.apache.jackrabbit.core.config;
+import junit.framework.TestCase;
+import org.xml.sax.InputSource;
+
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -26,10 +28,6 @@
import java.net.URI;
import java.net.URISyntaxException;
-import junit.framework.TestCase;
-
-import org.xml.sax.InputSource;
-
/**
* Test cases for repository configuration handling.
*/
@@ -191,7 +189,7 @@
VersioningConfig vc = config.getVersioningConfig();
assertEquals(new File(REPOSITORY_HOME, "version"), vc.getHomeDir());
assertEquals(
- "org.apache.jackrabbit.core.state.obj.ObjectPersistenceManager",
+ "org.apache.jackrabbit.core.persistence.obj.ObjectPersistenceManager",
vc.getPersistenceManagerConfig().getClassName());
assertTrue(vc.getPersistenceManagerConfig().getParameters().isEmpty());
}
Modified: jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java?view=diff&rev=467925&r1=467924&r2=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java (original)
+++ jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java Thu Oct 26 02:11:18 2006
@@ -53,7 +53,7 @@
PersistenceManagerConfig pmc = config.getPersistenceManagerConfig();
assertEquals(
- "org.apache.jackrabbit.core.state.obj.ObjectPersistenceManager",
+ "org.apache.jackrabbit.core.persistence.obj.ObjectPersistenceManager",
pmc.getClassName());
assertTrue(pmc.getParameters().isEmpty());
Modified: jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/config/repository.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/config/repository.xml?view=diff&rev=467925&r1=467924&r2=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/config/repository.xml (original)
+++ jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/config/repository.xml Thu Oct 26 02:11:18 2006
@@ -32,11 +32,11 @@
a Security element that specifies the name of the app-entry
in the JAAS config and the access manager
- a Workspaces element that specifies the location of the
- workspaces root directory, the name of the default workspace,
- the maximum idle time before a workspace is automatically
- shutdown (optional) and the workspace configuration root directory
- within the virtual repository file system (optional)
+ a Workspaces element that specifies the location of the
+ workspaces root directory, the name of the default workspace,
+ the maximum idle time before a workspace is automatically
+ shutdown (optional) and the workspace configuration root directory
+ within the virtual repository file system (optional)
a Workspace element that is used as a workspace configuration
template; it is used to create the initial workspace if there's
@@ -204,16 +204,16 @@
class: FQN of class implementing the PersistenceManager interface
-->
<!--
- <PersistenceManager class="org.apache.jackrabbit.core.state.xml.XMLPersistenceManager"/>
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.xml.XMLPersistenceManager"/>
-->
<!--
- <PersistenceManager class="org.apache.jackrabbit.core.state.mem.InMemPersistenceManager">
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.mem.InMemPersistenceManager">
<param name="initialCapacity" value="100000"/>
<param name="loadFactor" value="0.3"/>
<param name="persistent" value="true"/>
</PersistenceManager>
-->
- <PersistenceManager class="org.apache.jackrabbit.core.state.obj.ObjectPersistenceManager"/>
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.obj.ObjectPersistenceManager"/>
<!--
Search index and the file system it uses.
-->
@@ -247,7 +247,7 @@
a 'normal' persistence manager, but this could change in future
implementations.
-->
- <PersistenceManager class="org.apache.jackrabbit.core.state.obj.ObjectPersistenceManager"/>
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.obj.ObjectPersistenceManager"/>
</Versioning>
</Repository>
Propchange: jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/config/repository.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/config/workspace.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/config/workspace.xml?view=diff&rev=467925&r1=467924&r2=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/config/workspace.xml (original)
+++ jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/config/workspace.xml Thu Oct 26 02:11:18 2006
@@ -27,7 +27,7 @@
persistence of the workspace:
class: FQN of class implementing PersistenceManager interface
-->
- <PersistenceManager class="org.apache.jackrabbit.core.state.obj.ObjectPersistenceManager"/>
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.obj.ObjectPersistenceManager"/>
<!--
Search index and the file system it uses.
-->