From commits-return-2987-apmail-jackrabbit-commits-archive=jackrabbit.apache.org@jackrabbit.apache.org Thu Oct 26 11:28:36 2006 Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 17652 invoked from network); 26 Oct 2006 09:12:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 26 Oct 2006 09:12:10 -0000 Received: (qmail 9074 invoked by uid 500); 26 Oct 2006 09:12:21 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 9055 invoked by uid 500); 26 Oct 2006 09:12:21 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 9046 invoked by uid 99); 26 Oct 2006 09:12:21 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Oct 2006 02:12:21 -0700 X-ASF-Spam-Status: No, hits=0.6 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Oct 2006 02:12:08 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id DC1201A985C; Thu, 26 Oct 2006 02:11:22 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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... Date: Thu, 26 Oct 2006 09:11:20 -0000 To: commits@jackrabbit.apache.org From: tripod@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061026091122.DC1201A985C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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; - /** - * XMLPersistenceManager is a FileSystem-based - * PersistenceManager that persists ItemState - * and NodeReferences 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 XMLPersistenceManager 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("\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\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\n"); - } - writer.write("\t\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\n"); - } - writer.write("\t\n"); - - writer.write("\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("\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("\n"); - } - } - writer.write("\t\n"); - writer.write("\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("\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("\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 --> - + @@ -98,7 +98,7 @@ a 'normal' persistence manager, but this could change in future implementations. --> - + 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 @@ - + @@ -200,7 +200,7 @@ - + @@ -249,7 +249,7 @@ The class attribute of the PersistenceManager element contains the fully qualified class name of the persistence manager implementation class. The class must implement the - org.apache.jackrabbit.core.state.PersistenceManager + org.apache.jackrabbit.core.persistence.PersistenceManager interface and have an empty default constructor. String properties can be assigned using the param elements according to the JavaBean conventions. @@ -260,7 +260,9 @@

- The org.apache.jackrabbit.core.state.mem.InMemPersistenceManager + The + org.apache.jackrabbit.core.persistence.mem.InMemPersistenceManager + 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 @@

- The org.apache.jackrabbit.core.state.obj.ObjectPersistenceManager + The + org.apache.jackrabbit.core.persistence.obj.ObjectPersistenceManager + 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 @@

- The org.apache.jackrabbit.core.state.xml.XMLPersistenceManager + The + org.apache.jackrabbit.core.persistence.xml.XMLPersistenceManager + 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 @@

- The org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager + The + org.apache.jackrabbit.core.persistence.db.SimpleDbPersistenceManager + 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 @@

- The org.apache.jackrabbit.core.state.db.DerbyPersistenceManager + The + org.apache.jackrabbit.core.persistence.db.DerbyPersistenceManager + is a subclass of the SimpleDbPersistenceManager. It implements a persistence manager that uses an embedded Apache Derby 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 --> - + @@ -247,7 +247,7 @@ a 'normal' persistence manager, but this could change in future implementations. --> - + 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 --> - +