You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by dp...@apache.org on 2010/03/19 11:09:27 UTC
svn commit: r925158 [2/2] - in /incubator/chemistry/trunk/chemistry:
chemistry-jcr/ chemistry-jcr/src/main/java/org/apache/chemistry/jcr/
chemistry-parent/ chemistry-tests/
chemistry-tests/src/test/java/org/apache/chemistry/test/
chemistry-tests/src/te...
Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrObjectEntry.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrObjectEntry.java?rev=925158&r1=925157&r2=925158&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrObjectEntry.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrObjectEntry.java Fri Mar 19 10:09:26 2010
@@ -1,12 +1,9 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,554 +12,489 @@
* limitations under the License.
*
* Authors:
- * Dominique Pfister, Day
- * Michael Mertins, Saperion
+ * Florent Guillaume, Nuxeo
*/
package org.apache.chemistry.jcr;
import java.io.Serializable;
-import java.math.BigDecimal;
-import java.net.URI;
-import java.util.Calendar;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import javax.jcr.Item;
import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
-import javax.jcr.Value;
import javax.xml.namespace.QName;
-import org.apache.chemistry.Connection;
-import org.apache.chemistry.Document;
-import org.apache.chemistry.Folder;
+import org.apache.chemistry.AllowableAction;
+import org.apache.chemistry.BaseType;
+import org.apache.chemistry.ChangeInfo;
+import org.apache.chemistry.ContentStream;
import org.apache.chemistry.ObjectEntry;
-import org.apache.chemistry.Policy;
import org.apache.chemistry.Property;
import org.apache.chemistry.PropertyDefinition;
-import org.apache.chemistry.PropertyType;
-import org.apache.chemistry.Relationship;
-import org.apache.chemistry.RelationshipDirection;
import org.apache.chemistry.Type;
-import org.apache.chemistry.Updatability;
-import org.apache.chemistry.impl.simple.SimplePropertyDefinition;
+import org.apache.chemistry.impl.base.BaseRepository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.JcrConstants;
-public abstract class JcrObjectEntry implements ObjectEntry {
-
- public static final String MIX_UNSTRUCTURED = "mix:unstructured";
+/**
+ * JCR implementation of an {@link ObjectEntry}.
+ * <p>
+ * This implementation doesn't do type validation when values are set.
+ */
+class JcrObjectEntry implements ObjectEntry {
+ /**
+ * Logger.
+ */
private static final Log log = LogFactory.getLog(JcrObjectEntry.class);
- protected Node node;
-
- protected final JcrConnection connection;
-
+ /**
+ * Values.
+ */
+ private Map<String, Serializable> values;
+
+ /**
+ * Associated JCR node, <code>null</code> if this is a new node.
+ */
+ private Node node;
+
+ /**
+ * Type, <code>null</code> if this hasn't been computed yet.
+ */
+ private Type type;
+
+ /**
+ * JCR connection.
+ */
+ private final JcrConnection connection;
+
+ /**
+ * Create a new instance of this class. Used for existing objects.
+ *
+ * @param node JCR node
+ * @param connection JCR connection
+ */
public JcrObjectEntry(Node node, JcrConnection connection) {
- this.node = node;
- this.connection = connection;
- }
-
- public Connection getConnection() {
- return connection;
+ this(node, null, connection);
}
- public Set<QName> getAllowableActions() {
- throw null;
+ /**
+ * Create a new instance of this class. Used for existing objects.
+ *
+ * @param node JCR node
+ * @param type type that should override type saved in JCR properties
+ * @param connection JCR connection
+ */
+ public JcrObjectEntry(Node node, Type type, JcrConnection connection) {
+ this.node = node;
+ this.type = type;
+ this.connection = connection;
}
- public String getPathSegment() {
- return null;
+ /**
+ * Constructor used for new object entries.
+ *
+ * @param type type
+ * @param connection connection
+ */
+ public JcrObjectEntry(Type type, JcrConnection connection) {
+ this.type = type;
+ this.connection = connection;
}
- public Boolean getBoolean(String id) {
- try {
- return Boolean.valueOf(node.getProperty(JcrCmisMap.cmisToJcr(id)).getBoolean());
- } catch (PathNotFoundException e) {
- /* property does not exist */
- } catch (RepositoryException e) {
- String msg = "Unable to get boolean value: " + id;
- log.error(msg, e);
+ /**
+ * {@inheritDoc}
+ */
+ public String getId() {
+ if (isNew()) {
+ return null;
}
- return null;
- }
-
- public Boolean[] getBooleans(String id) {
try {
- Value[] values = node.getProperty(JcrCmisMap.cmisToJcr(id)).getValues();
- Boolean[] result = new Boolean[values.length];
- for (int i = 0; i < values.length; i++) {
- result[i] = Boolean.valueOf(values[i].getBoolean());
- }
- return result;
- } catch (PathNotFoundException e) {
- /* property does not exist */
+ return node.getIdentifier();
} catch (RepositoryException e) {
- String msg = "Unable to get boolean values: " + id;
- log.error(msg, e);
+ log.error("Unable to retrieve identifier", e);
+ return null;
}
- return null;
- }
-
- public String getChangeToken() {
- return getString(Property.CHANGE_TOKEN);
- }
-
- public String getCheckInComment() {
- return getString(Property.CHECK_IN_COMMENT);
}
- public String getCreatedBy() {
- return getString(Property.CREATED_BY);
- }
-
- public Calendar getCreationDate() {
- return getDateTime(Property.CREATION_DATE);
- }
-
- public Calendar getDateTime(String id) {
+ /**
+ * {@inheritDoc}
+ */
+ public String getTypeId() {
+ if (type != null) {
+ return type.getId();
+ }
try {
- return node.getProperty(JcrCmisMap.cmisToJcr(id)).getDate();
- } catch (PathNotFoundException e) {
- /* property does not exist */
+ if (hasCmisPrefix() && node.hasProperty(Property.TYPE_ID)) {
+ return node.getProperty(Property.TYPE_ID).getString();
+ }
+ String nt = node.getPrimaryNodeType().getName();
+ if (JcrCmisMap.isBaseTypeFolder(nt)) {
+ return BaseType.FOLDER.getId();
+ } else {
+ return BaseType.DOCUMENT.getId();
+ }
} catch (RepositoryException e) {
- String msg = "Unable to get date time value: " + id;
- log.error(msg, e);
+ log.error("Unable to get type id", e);
+ return BaseType.DOCUMENT.getId();
}
- return null;
}
- public Calendar[] getDateTimes(String id) {
- try {
- Value[] values = node.getProperty(JcrCmisMap.cmisToJcr(id)).getValues();
- Calendar[] result = new Calendar[values.length];
- for (int i = 0; i < values.length; i++) {
- result[i] = values[i].getDate();
- }
- return result;
- } catch (PathNotFoundException e) {
- /* property does not exist */
- } catch (RepositoryException e) {
- String msg = "Unable to get date time values: " + id;
- log.error(msg, e);
+ /**
+ * Load the type unless done.
+ */
+ private synchronized Type getType() {
+ if (type == null) {
+ String typeId = getTypeId();
+ type = connection.getRepository().getType(typeId);
+ if (type == null) {
+ log.warn("Actual object type not registered: " + typeId);
+ type = BaseRepository.DOCUMENT_TYPE;
+ }
}
- return null;
+ return type;
}
- public BigDecimal getDecimal(String id) {
- try {
- return new BigDecimal(node.getProperty(JcrCmisMap.cmisToJcr(id)).getDouble());
- } catch (PathNotFoundException e) {
- /* property does not exist */
- } catch (RepositoryException e) {
- String msg = "Unable to get decimal value: " + id;
- log.error(msg, e);
- }
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public BaseType getBaseType() {
+ return getType().getBaseType();
}
- public BigDecimal[] getDecimals(String id) {
- try {
- Value[] values = node.getProperty(JcrCmisMap.cmisToJcr(id)).getValues();
- BigDecimal[] result = new BigDecimal[values.length];
- for (int i = 0; i < values.length; i++) {
- result[i] = new BigDecimal(values[i].getDouble());
- }
- return result;
- } catch (PathNotFoundException e) {
- /* property does not exist */
- } catch (RepositoryException e) {
- String msg = "Unable to get decimal values: " + id;
- log.error(msg, e);
+ /**
+ * Return this object's name.
+ *
+ * @return name or <code>null</code> if this object is new
+ */
+ private String getName() {
+ if (!isNew()) {
+ try {
+ return node.getName();
+ } catch (RepositoryException e) {
+ log.error("Unable to get node name", e);
+ }
}
return null;
}
- public Document getDocument() {
- throw new UnsupportedOperationException();
- }
-
- public Folder getFolder() {
- throw new UnsupportedOperationException();
- }
-
- public String getHTML(String id) {
- return (String) getValue(id);
- }
-
- public String[] getHTMLs(String id) {
- return (String[]) getValue(id);
- }
-
- public String getId(String id) {
- try {
- javax.jcr.Property prop = node.getProperty(JcrCmisMap.cmisToJcr(id));
- return getItemId(prop);
- } catch (PathNotFoundException e) {
- /* property does not exist */
- } catch (RepositoryException e) {
- String msg = "Unable to get item path: " + id;
- log.error(msg, e);
+ /**
+ * Return this object's path.
+ *
+ * @return path or <code>null</code> if this object is new
+ */
+ private String getPath() {
+ if (!isNew()) {
+ try {
+ return node.getPath();
+ } catch (RepositoryException e) {
+ log.error("Unable to get node name", e);
+ }
}
return null;
}
- public String getId() {
- try {
- return getItemId(node);
- } catch (RepositoryException e) {
- String msg = "Unable to get item path.";
- log.error(msg, e);
+ /**
+ * Return this object's path.
+ *
+ * @return path or <code>null</code> if this object is new
+ */
+ private String getParentId() {
+ if (!isNew() && !connection.getRootFolderId().getId().equals(getId())) {
+ try {
+ return node.getParent().getIdentifier();
+ } catch (RepositoryException e) {
+ log.error("Unable to get node name", e);
+ }
}
return null;
}
- public String[] getIds(String id) {
- return (String[]) getValue(id);
- }
-
- public Integer getInteger(String id) {
- try {
- return Integer.valueOf((int) node.getProperty(JcrCmisMap.cmisToJcr(id)).getLong());
- } catch (PathNotFoundException e) {
- /* property does not exist */
- } catch (RepositoryException e) {
- String msg = "Unable to get integer value: " + id;
- log.error(msg, e);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public ChangeInfo getChangeInfo() {
return null;
}
- public Integer[] getIntegers(String id) {
- try {
- Value[] values = node.getProperty(JcrCmisMap.cmisToJcr(id)).getValues();
- Integer[] result = new Integer[values.length];
- for (int i = 0; i < values.length; i++) {
- result[i] = Integer.valueOf((int) values[i].getLong());
- }
- return result;
- } catch (PathNotFoundException e) {
- /* property does not exist */
- } catch (RepositoryException e) {
- String msg = "Unable to get integer values: " + id;
- log.error(msg, e);
+ /**
+ * {@inheritDoc}
+ */
+ public String getPathSegment() {
+ if (isNew()) {
+ return null;
}
- return null;
+ return (String) getValue(Property.NAME);
}
- public Calendar getLastModificationDate() {
- return getDateTime(Property.LAST_MODIFICATION_DATE);
+ /**
+ * {@inheritDoc}
+ */
+ public Map<String, Serializable> getValues() {
+ loadValues();
+ return values;
}
- public String getLastModifiedBy() {
- return getString(Property.LAST_MODIFIED_BY);
+ /**
+ * {@inheritDoc}
+ */
+ public Serializable getValue(String id) {
+ loadValues();
+ return values.get(id);
}
- public String getName() {
- try {
- return node.getName();
- } catch (RepositoryException e) {
- String msg = "Unable to get node name.";
- log.error(msg, e);
+ /**
+ * {@inheritDoc}
+ */
+ public void setValue(String id, Serializable value) {
+ loadValues();
+ if (value == null) {
+ values.remove(id);
+ } else {
+ values.put(id, value);
}
- return null;
- }
-
- public Policy getPolicy() {
- throw new UnsupportedOperationException();
}
- // TODO use the definition inside SimpleType
- private static final SimplePropertyDefinition PROP_TYPE_ID = new SimplePropertyDefinition(
- Property.TYPE_ID, "def:typeid", null, Property.TYPE_ID, "Type ID",
- "", false, PropertyType.ID, false, null, false, true, null,
- Updatability.READ_ONLY, true, true, 0, null, null, -1, null);
-
- public Map<String, Property> getProperties() {
- Map<String, Property> properties = new HashMap<String, Property>();
- for (PropertyDefinition pd : getType().getPropertyDefinitions()) {
- String id = pd.getId();
- if ("*".equals(id)) {
- // residual property
- continue;
- }
- properties.put(id, getProperty(id));
+ /**
+ * {@inheritDoc}
+ */
+ public void setValues(Map<String, Serializable> values) {
+ loadValues();
+ // don't use putAll as we want to check for nulls
+ for (String id : values.keySet()) {
+ setValue(id, values.get(id));
}
- // TODO return other virtual properties and provide helper class
- properties.put(Property.TYPE_ID, new Property() {
-
- public PropertyDefinition getDefinition() {
- return PROP_TYPE_ID;
- }
-
- public Serializable getValue() {
- return getTypeId();
- }
-
- public void setValue(Serializable value) {
- }
- });
- return properties;
}
- public Property getProperty(String id) {
- try {
- return new JcrProperty(node.getProperty(JcrCmisMap.cmisToJcr(id)));
- } catch (PathNotFoundException e) {
- /* property does not exist */
- } catch (RepositoryException e) {
- String msg = "Unable to get property: " + id;
- log.error(msg, e);
- }
- return null;
- }
+ /**
+ * Load values unless already done.
+ */
+ synchronized void loadValues() {
+ if (values == null) {
+ values = new HashMap<String, Serializable>();
- public Relationship getRelationship() {
- throw new UnsupportedOperationException();
- }
+ loadPropertyValues(values);
- public Collection<ObjectEntry> getRelationships() {
- return Collections.emptyList();
- }
+ values.put(Property.TYPE_ID, getTypeId());
+ values.put(Property.BASE_TYPE_ID, getBaseType().getId());
- public String getString(String id) {
- try {
- return node.getProperty(JcrCmisMap.cmisToJcr(id)).getString();
- } catch (PathNotFoundException e) {
- /* property does not exist */
- } catch (RepositoryException e) {
- String msg = "Unable to get string value: " + id;
- log.error(msg, e);
- }
- return null;
- }
+ if (!isNew()) {
+ values.put(Property.ID, getId());
+ values.put(Property.NAME, getName());
+ values.put(Property.PATH, getPath());
- public String[] getStrings(String id) {
- try {
- Value[] values = node.getProperty(JcrCmisMap.cmisToJcr(id)).getValues();
- String[] result = new String[values.length];
- for (int i = 0; i < values.length; i++) {
- result[i] = values[i].getString();
- }
- return result;
- } catch (PathNotFoundException e) {
- /* property does not exist */
- } catch (RepositoryException e) {
- String msg = "Unable to get string values: " + id;
- log.error(msg, e);
+ String parentId = getParentId();
+ if (parentId != null) {
+ values.put(Property.PARENT_ID, parentId);
+ }
+ loadContentStreamValues(values);
+ }
}
- return null;
}
- public Type getType() {
- try {
- return new JcrType(node.getPrimaryNodeType(), getBaseType());
- } catch (RepositoryException e) {
- String msg = "Unable to get primary node type.";
- log.error(msg, e);
+ /**
+ * Load values from the underlying JCR node.
+ *
+ * @param values map to populate with entries
+ */
+ private void loadPropertyValues(Map<String, Serializable> values) {
+ if (isNew()) {
+ return;
}
- return null;
- }
-
- public String getTypeId() {
- return getType().getId();
- }
-
- public URI getURI(String id) {
- return (URI) getValue(id);
- }
-
- public URI[] getURIs(String id) {
- return (URI[]) getValue(id);
- }
-
- public Serializable getValue(String id) {
- String name = JcrCmisMap.cmisToJcr(id);
- try {
- if (node.hasProperty(name)) {
- if (JcrCmisMap.isArray(name)) {
- // TODO: Array handling doesn't work yet
- // i.e. for (Value v : node.getProperty(name).getValues();
- } else {
- Value value = node.getProperty(name).getValue();
- if (JcrCmisMap.isDate(name)) {
- return value.getDate();
- } else if (JcrCmisMap.isBool(name)) {
- return value.getBoolean();
- } else if (JcrCmisMap.isInt(name)) {
- return value.getLong();
- } else {
- return value.getString();
- }
+ /* Load JCR property values that are included in this
+ * type's property definitions
+ */
+ Type type = connection.getRepository().getType(getTypeId());
+ for (PropertyDefinition pd : type.getPropertyDefinitions()) {
+ String id = pd.getId();
+ try {
+ if (id.startsWith(JcrRepository.CMIS_PREFIX) && !hasCmisPrefix()) {
+ continue;
}
+ if (node.hasProperty(id)) {
+ values.put(id, JcrCmisMap.valueToSerializable(
+ pd.getType(),
+ node.getProperty(id).getValue()));
+ }
+ } catch (RepositoryException e) {
+ log.error("Unable to load property: " + id, e);
}
- } catch (PathNotFoundException e) {
- /* property does not exist */
- } catch (RepositoryException e) {
- String msg = "Unable to get value: " + id;
- log.error(msg, e);
}
- return null;
}
- public Map<String, Serializable> getValues() {
- Map<String, Serializable> values = new HashMap<String, Serializable>();
- for (PropertyDefinition def : getType().getPropertyDefinitions()) {
- String id = def.getId();
- values.put(JcrCmisMap.cmisToJcr(id), getValue(id));
+ /**
+ * Load content stream values from the underlying JCR node.
+ *
+ * @param values map to populate with entries
+ */
+ private void loadContentStreamValues(Map<String, Serializable> values) {
+ if (isNew() || getBaseType() != BaseType.DOCUMENT) {
+ return;
}
- return values;
- }
-
- public String getVersionLabel() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public String getVersionSeriesCheckedOutBy() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public String getVersionSeriesCheckedOutId() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public String getVersionSeriesId() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public String getXML(String id) {
- return (String) getValue(id);
- }
-
- public String[] getXMLs(String id) {
- return (String[]) getValue(id);
- }
-
- public boolean hasContentStream() {
- return false;
- }
-
- public boolean isImmutable() {
- return false;
- }
-
- public boolean isLatestMajorVersion() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean isLatestVersion() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean isMajorVersion() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean isVersionSeriesCheckedOut() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public void applyPolicy(Policy policy) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
- }
-
- public void delete() {
try {
- Node parent = node.getParent();
- node.remove();
- parent.save();
+ Node content = node.getNode(JcrConstants.JCR_CONTENT);
+ String filename = getName();
+ if (hasCmisPrefix() && node.hasProperty(Property.CONTENT_STREAM_FILE_NAME)) {
+ filename = node.getProperty(Property.CONTENT_STREAM_FILE_NAME).getString();
+ }
+ JcrContentStream cs = new JcrContentStream(content, filename);
+ if (cs.getLength() != 0) {
+ values.put(Property.CONTENT_STREAM_FILE_NAME, cs.getFileName());
+ values.put(Property.CONTENT_STREAM_MIME_TYPE, cs.getMimeType());
+ values.put(Property.CONTENT_STREAM_LENGTH, Integer.valueOf((int) cs.getLength()));
+ }
} catch (RepositoryException e) {
- String msg = "Unable to delete object.";
+ String msg = "Unable to inspect jcr:content sub node.";
log.error(msg, e);
}
}
- public Collection<Folder> getParents() {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
- }
-
- public Collection<Policy> getPolicies() {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
- }
-
- public List<Relationship> getRelationships(RelationshipDirection direction,
- String typeId, boolean includeSubRelationshipTypes) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
- }
-
- public void move(Folder targetFolder, Folder sourceFolder) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
- }
-
- public void removePolicy(Policy policy) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+ /**
+ * {@inheritDoc}
+ */
+ public Set<QName> getAllowableActions() {
+ boolean canWrite = true;
+ boolean isFolder = getBaseType() == BaseType.FOLDER;
+ Set<QName> set = new HashSet<QName>();
+ set.add(AllowableAction.CAN_GET_OBJECT_PARENTS);
+ set.add(AllowableAction.CAN_GET_PROPERTIES);
+ if (isFolder) {
+ set.add(AllowableAction.CAN_GET_DESCENDANTS);
+ set.add(AllowableAction.CAN_GET_FOLDER_PARENT);
+ set.add(AllowableAction.CAN_GET_FOLDER_TREE);
+ set.add(AllowableAction.CAN_GET_CHILDREN);
+ } else {
+ set.add(AllowableAction.CAN_GET_CONTENT_STREAM);
+ }
+ if (canWrite) {
+ if (isFolder) {
+ set.add(AllowableAction.CAN_CREATE_DOCUMENT);
+ set.add(AllowableAction.CAN_CREATE_FOLDER);
+ set.add(AllowableAction.CAN_CREATE_RELATIONSHIP);
+ set.add(AllowableAction.CAN_DELETE_TREE);
+ set.add(AllowableAction.CAN_ADD_OBJECT_TO_FOLDER);
+ set.add(AllowableAction.CAN_REMOVE_OBJECT_FROM_FOLDER);
+ } else {
+ set.add(AllowableAction.CAN_SET_CONTENT_STREAM);
+ set.add(AllowableAction.CAN_DELETE_CONTENT_STREAM);
+ }
+ set.add(AllowableAction.CAN_UPDATE_PROPERTIES);
+ set.add(AllowableAction.CAN_MOVE_OBJECT);
+ set.add(AllowableAction.CAN_DELETE_OBJECT);
+ }
+ if (Boolean.FALSE.booleanValue()) {
+ // TODO
+ set.add(AllowableAction.CAN_GET_RENDITIONS);
+ set.add(AllowableAction.CAN_CHECK_OUT);
+ set.add(AllowableAction.CAN_CANCEL_CHECK_OUT);
+ set.add(AllowableAction.CAN_CHECK_IN);
+ set.add(AllowableAction.CAN_GET_ALL_VERSIONS);
+ set.add(AllowableAction.CAN_GET_OBJECT_RELATIONSHIPS);
+ set.add(AllowableAction.CAN_APPLY_POLICY);
+ set.add(AllowableAction.CAN_REMOVE_POLICY);
+ set.add(AllowableAction.CAN_GET_APPLIED_POLICIES);
+ set.add(AllowableAction.CAN_GET_ACL);
+ set.add(AllowableAction.CAN_APPLY_ACL);
+ }
+ return set;
}
- public void unfile() {
+ public Collection<ObjectEntry> getRelationships() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
}
- public static String getItemId(Item item) throws RepositoryException {
- return escape(item.getPath());
- }
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + '(' + getTypeId() + ',' + getId()
+ + ')';
+ }
+
+ /**
+ * Return the node representing this entry.
+ *
+ * @return node or <code>null</code> if this entry is new
+ */
+ Node getNode() {
+ return node;
+ }
+
+ /**
+ * Set the node representing this entry. Done after saving a node
+ * for the first time. Populate the missing values in our values
+ * array.
+ *
+ * @param node node
+ */
+ synchronized void setNode(Node node) {
+ this.node = node;
- public static String getPath(String id) {
- return unescape(id);
+ if (values != null) {
+ values.put(Property.ID, getId());
+ values.put(Property.NAME, getName());
+ values.put(Property.PATH, getPath());
+
+ String parentId = getParentId();
+ if (parentId != null) {
+ values.put(Property.PARENT_ID, parentId);
+ }
+ }
}
- public static String escape(String s) {
- StringBuffer result = new StringBuffer();
-
- char[] ach = s.toCharArray();
- for (char c : ach) {
- String esc = Integer.toHexString(c);
- int len = esc.length();
- if (len > 2) {
- esc = esc.substring(len - 2);
- } else if (len < 2) {
- result.append('0');
+ /**
+ * Update the internal content stream properties after a content stream
+ * has been written.
+ *
+ * @param cs content stream or <code>null</code>
+ */
+ synchronized void setContentStream(ContentStream cs) {
+ if (values != null) {
+ if (cs == null) {
+ values.remove(Property.CONTENT_STREAM_FILE_NAME);
+ values.remove(Property.CONTENT_STREAM_MIME_TYPE);
+ values.remove(Property.CONTENT_STREAM_LENGTH);
+ } else {
+ String filename = cs.getFileName();
+ if (filename == null) {
+ filename = (String) getValue(Property.NAME);
+ }
+ values.put(Property.CONTENT_STREAM_FILE_NAME, filename);
+ values.put(Property.CONTENT_STREAM_MIME_TYPE, cs.getMimeType());
+ values.put(Property.CONTENT_STREAM_LENGTH, Integer.valueOf((int) cs.getLength()));
}
- result.append(esc);
}
- return result.toString();
}
- public static String unescape(String s) {
- StringBuffer result = new StringBuffer();
-
- char[] ach = s.toCharArray();
- int i = 0;
+ /**
+ * Return a flag indicating whether this entry is new.
+ *
+ * @return <code>true</code> if this entry is new;
+ * <code>false</code> otherwise
+ */
+ public boolean isNew() {
+ return node == null;
+ }
- while (i < ach.length) {
- char c = (char) Integer.parseInt(s.substring(i, i + 2), 16);
- result.append(c);
- i += 2;
- }
- return result.toString();
+ /**
+ * Return the JCR connection.
+ *
+ * @return connection
+ */
+ JcrConnection getConnection() {
+ return connection;
}
- protected void setNode(Node node) {
- this.node = node;
+ /**
+ * Return a flag indicating whether the namespace prefix <b>cmis</b> is known to
+ * the repository.
+ *
+ * @return namespace URI
+ */
+ boolean hasCmisPrefix() {
+ return connection.getRepository().hasCmisPrefix();
}
}
Added: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrPolicy.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrPolicy.java?rev=925158&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrPolicy.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrPolicy.java Fri Mar 19 10:09:26 2010
@@ -0,0 +1,30 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Authors:
+ * Florent Guillaume, Nuxeo
+ */
+package org.apache.chemistry.jcr;
+
+import org.apache.chemistry.Policy;
+
+/**
+ * Policy implementation.
+ */
+class JcrPolicy extends JcrObject implements Policy {
+
+ public JcrPolicy(JcrObjectEntry entry) {
+ super(entry);
+ }
+
+}
Propchange: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrPolicy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrPolicy.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url
Added: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRelationship.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRelationship.java?rev=925158&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRelationship.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRelationship.java Fri Mar 19 10:09:26 2010
@@ -0,0 +1,30 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Authors:
+ * Florent Guillaume, Nuxeo
+ */
+package org.apache.chemistry.jcr;
+
+import org.apache.chemistry.Relationship;
+
+/**
+ * Relationship implementation.
+ */
+public class JcrRelationship extends JcrObject implements Relationship {
+
+ public JcrRelationship(JcrObjectEntry entry) {
+ super(entry);
+ }
+
+}
Propchange: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRelationship.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRelationship.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url
Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java?rev=925158&r1=925157&r2=925158&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java Fri Mar 19 10:09:26 2010
@@ -23,20 +23,14 @@ package org.apache.chemistry.jcr;
import java.io.Serializable;
import java.net.URI;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.jcr.NamespaceException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
-import javax.jcr.nodetype.NoSuchNodeTypeException;
-import javax.jcr.nodetype.NodeType;
-import javax.jcr.nodetype.NodeTypeIterator;
-import javax.jcr.nodetype.NodeTypeManager;
import org.apache.chemistry.ACLCapabilityType;
import org.apache.chemistry.BaseType;
@@ -45,182 +39,163 @@ import org.apache.chemistry.CapabilityCh
import org.apache.chemistry.CapabilityJoin;
import org.apache.chemistry.CapabilityQuery;
import org.apache.chemistry.CapabilityRendition;
-import org.apache.chemistry.ListPage;
import org.apache.chemistry.ObjectId;
-import org.apache.chemistry.Paging;
-import org.apache.chemistry.PropertyDefinition;
import org.apache.chemistry.Repository;
import org.apache.chemistry.RepositoryCapabilities;
-import org.apache.chemistry.RepositoryEntry;
import org.apache.chemistry.RepositoryInfo;
import org.apache.chemistry.SPI;
-import org.apache.chemistry.Type;
-import org.apache.chemistry.impl.simple.SimpleListPage;
+import org.apache.chemistry.impl.base.BaseRepository;
import org.apache.chemistry.impl.simple.SimpleObjectId;
+import org.apache.chemistry.impl.simple.SimpleType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.w3c.dom.Document;
-public class JcrRepository implements Repository, RepositoryInfo,
+/**
+ * Repository implementation that exposes a JCR repository.
+ */
+public class JcrRepository extends BaseRepository implements Repository, RepositoryInfo,
RepositoryCapabilities {
+ /**
+ * CMIS property prefix ("cmis:").
+ */
+ public static final String CMIS_PREFIX = "cmis:";
+
+ /**
+ * Mixin to add in order to add custom properties ("mix:unstructured").
+ */
+ public static final String MIX_UNSTRUCTURED = "mix:unstructured";
+
+ /**
+ * Logger.
+ */
private static final Log log = LogFactory.getLog(JcrRepository.class);
+ /**
+ * JCR repository.
+ */
private final javax.jcr.Repository repository;
- private final String workspace;
+ /**
+ * Workspace to login to.
+ */
+ private String workspace;
+
+ /**
+ * Credentials to use when connecting.
+ */
+ private SimpleCredentials creds;
+
+ /**
+ * Root folder id.
+ */
+ private ObjectId rootFolderId;
+
+ /**
+ * Flag indicating whether the repository has registered <b>cmis</b> prefix.
+ */
+ private Boolean hasCmisPrefix;
+
+ /**
+ * Create a new instance of this class.
+ *
+ * @param repository JCR repository
+ * @param types types to add (in testing)
+ */
+ public JcrRepository(javax.jcr.Repository repository, Collection<SimpleType> types) {
+ super("chemistry-jcr");
- private final SimpleCredentials creds;
-
- public JcrRepository(javax.jcr.Repository repository, String workspace,
- SimpleCredentials creds) {
this.repository = repository;
- this.workspace = workspace;
- this.creds = creds;
- }
- public JcrRepository(javax.jcr.Repository repository, String workspace) {
- this.repository = repository;
- this.workspace = workspace;
- this.creds = new SimpleCredentials("admin", "admin".toCharArray());
+ addTypes(getDefaultTypes());
+ if (types != null) {
+ addTypes(types);
+ }
}
+ /**
+ * Create a new instance of this class.
+ *
+ * @param repository JCR repository
+ */
public JcrRepository(javax.jcr.Repository repository) {
this(repository, null);
}
- public SPI getSPI(Map<String, Serializable> params) {
- return getConnection(params);
- }
-
- public JcrConnection getConnection(Map<String, Serializable> params) {
- try {
- return new JcrConnection(repository.login(creds, workspace), this);
- } catch (RepositoryException e) {
- String msg = "Unable to open connection.";
- throw new RuntimeException(msg, e);
- }
+ /**
+ * Set workspace to use when connecting.
+ *
+ * @param workspace workspace
+ */
+ public void setWorkspace(String workspace) {
+ this.workspace = workspace;
}
- public <T> T getExtension(Class<T> klass) {
- return null;
+ /**
+ * Set credentials to use when connecting.
+ *
+ * @param creds credentials
+ */
+ public void setCredentials(SimpleCredentials creds) {
+ this.creds = creds;
}
- public RepositoryInfo getInfo() {
- return this;
+ /**
+ * Set root folder id.
+ *
+ * @param rootFolderId root folder id
+ */
+ public void setRootNodeId(String id) {
+ this.rootFolderId = new SimpleObjectId(id);
}
- public void addType(Type type) {
- throw new UnsupportedOperationException("Cannot add types");
+ /**
+ * {@inheritDoc}
+ */
+ public SPI getSPI(Map<String, Serializable> params) {
+ return getConnection(params);
}
- public Type getType(String typeId) {
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized JcrConnection getConnection(Map<String, Serializable> params) {
try {
Session session = repository.login(creds, workspace);
-
- // TODO fetch the types only once, include other types
- NodeTypeManager ntmgr = session.getWorkspace().getNodeTypeManager();
- NodeType nt = ntmgr.getNodeType(typeId);
-
- BaseType baseType = BaseType.FOLDER;
- if (JcrCmisMap.isBaseTypeDocument(nt.getName())) {
- baseType = BaseType.DOCUMENT;
+ if (rootFolderId == null) {
+ rootFolderId = new SimpleObjectId(session.getRootNode().getIdentifier());
}
- return new JcrType(nt, baseType);
- } catch (NoSuchNodeTypeException e) {
- return null;
+ return new JcrConnection(session, this);
} catch (RepositoryException e) {
- String msg = "Unable get type: " + typeId;
- log.error(msg, e);
- }
- return null;
- }
-
- public PropertyDefinition getPropertyDefinition(String id) {
- // TODO improve by caching
- for (Type type : getTypes()) {
- PropertyDefinition pdef = type.getPropertyDefinition(id);
- if (pdef != null) {
- return pdef;
- }
- }
- return null;
- }
-
- public Collection<Type> getTypes() {
- return getTypeDescendants(null, -1, true);
- }
-
- public Collection<Type> getTypeDescendants(String typeId) {
- Collection<Type> list = getTypeDescendants(typeId, -1, true);
- if (typeId != null) {
- // add the type itself as first element
- Type type = getType(typeId);
- ((LinkedList<Type>) list).addFirst(type);
+ String msg = "Unable to open connection.";
+ throw new RuntimeException(msg, e);
}
- return list;
- }
-
- public ListPage<Type> getTypeChildren(String typeId,
- boolean includePropertyDefinitions, Paging paging) {
- // TODO proper children
- List<Type> list = getTypeDescendants(typeId, -1, true);
- return new SimpleListPage<Type>(list);
}
- public List<Type> getTypeDescendants(String typeId, int depth,
- boolean includePropertyDefinitions) {
-
- // TODO depth, includePropertyDefinitions
-
- try {
- List<Type> result = new LinkedList<Type>();
-
- Session session = repository.login(creds, workspace);
-
- NodeTypeManager ntmgr = session.getWorkspace().getNodeTypeManager();
- if (typeId != null) {
- // check existence
- ntmgr.getNodeType(typeId);
- }
-
- NodeTypeIterator nodeTypes = ntmgr.getAllNodeTypes();
- while (nodeTypes.hasNext()) {
- NodeType nodeType = nodeTypes.nextNodeType();
- if (nodeType.isMixin()) {
- // Mixing Types will be ignored
- continue;
- }
- BaseType baseType = BaseType.FOLDER;
- if (JcrCmisMap.isBaseTypeDocument(nodeType.getName())) {
- baseType = BaseType.DOCUMENT;
- }
- // If typeId is provided, only the descendants are returned,
- // otherwise all types are returned.
- // TODO proper hierarchy of types
- if (typeId == null) {
- result.add(new JcrType(nodeType, baseType));
- }
- }
-
- return result;
- } catch (NoSuchNodeTypeException e) {
- throw new IllegalArgumentException("No such type: " + typeId);
- } catch (RepositoryException e) {
- String msg = "Unable to retrieve node types.";
- log.error(msg, e);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public <T> T getExtension(Class<T> klass) {
return null;
}
+ /**
+ * {@inheritDoc}
+ */
public String getId() {
return getName();
}
+ /**
+ * {@inheritDoc}
+ */
public String getName() {
return repository.getDescriptor(javax.jcr.Repository.REP_NAME_DESC);
}
+ /**
+ * {@inheritDoc}
+ */
public URI getThinClientURI() {
URI uri = null;
try {
@@ -235,10 +210,9 @@ public class JcrRepository implements Re
// ---------------------------------------------------------- RepositoryInfo
- public RepositoryCapabilities getCapabilities() {
- return this;
- }
-
+ /**
+ * {@inheritDoc}
+ */
public Set<BaseType> getChangeLogBaseTypes() {
// TODO-0.63 TCK checks 0.62 schema which has minOccurs=1
Set<BaseType> changeLogBaseTypes = new HashSet<BaseType>();
@@ -249,107 +223,201 @@ public class JcrRepository implements Re
return changeLogBaseTypes;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isChangeLogIncomplete() {
return false;
}
+ /**
+ * {@inheritDoc}
+ */
public String getLatestChangeLogToken() {
return "";
}
+ /**
+ * {@inheritDoc}
+ */
public ACLCapabilityType getACLCapabilityType() {
// TODO Auto-generated method stub
return null;
}
+ /**
+ * {@inheritDoc}
+ */
public String getDescription() {
return getName();
}
+ /**
+ * {@inheritDoc}
+ */
public String getProductName() {
return repository.getDescriptor(javax.jcr.Repository.REP_NAME_DESC);
}
+ /**
+ * {@inheritDoc}
+ */
public String getProductVersion() {
return repository.getDescriptor(javax.jcr.Repository.REP_VERSION_DESC);
}
- public Collection<RepositoryEntry> getRelatedRepositories() {
- return Collections.emptySet();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public ObjectId getRootFolderId() {
+ if (rootFolderId == null) {
+ Session session = null;
- public Document getRepositorySpecificInformation() {
- return null;
+ try {
+ session = repository.login(creds, workspace);
+ rootFolderId = new SimpleObjectId(session.getRootNode().getIdentifier());
+ } catch (RepositoryException e) {
+ log.error("Unable to determine root folder id.", e);
+ } finally {
+ if (session != null) {
+ session.logout();
+ }
+ }
+ }
+ return rootFolderId;
}
- public ObjectId getRootFolderId() {
- return new SimpleObjectId(JcrObjectEntry.escape("/"));
+ /**
+ * Return a flag indicating whether the <b>cmis</b> prefix is registered.
+ *
+ * @return <code>true</code> if <b>cmis</b> is registered;
+ * <code>false</code> otherwise
+ */
+ public synchronized boolean hasCmisPrefix() {
+ if (hasCmisPrefix == null) {
+ Session session = null;
+
+ try {
+ session = repository.login(creds, workspace);
+ String uri = session.getWorkspace().getNamespaceRegistry().getURI("cmis");
+ hasCmisPrefix = uri != null;
+ } catch (NamespaceException e) {
+ hasCmisPrefix = Boolean.FALSE;
+ } catch (RepositoryException e) {
+ log.error("Unable to determine check namespace prefix: cmis.", e);
+ } finally {
+ if (session != null) {
+ session.logout();
+ }
+ }
+ }
+ return hasCmisPrefix.booleanValue();
}
+ /**
+ * {@inheritDoc}
+ */
public String getVendorName() {
return repository.getDescriptor(javax.jcr.Repository.REP_VENDOR_DESC);
}
- public String getVersionSupported() {
- return "1.0";
- }
-
// -------------------------------------------------- RepositoryCapabilities
+ /**
+ * {@inheritDoc}
+ */
public CapabilityJoin getJoinCapability() {
return CapabilityJoin.NONE;
}
+ /**
+ * {@inheritDoc}
+ */
public CapabilityQuery getQueryCapability() {
return CapabilityQuery.BOTH_SEPARATE;
}
+ /**
+ * {@inheritDoc}
+ */
public CapabilityRendition getRenditionCapability() {
return CapabilityRendition.NONE;
}
+ /**
+ * {@inheritDoc}
+ */
public CapabilityChange getChangeCapability() {
return CapabilityChange.NONE;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean hasMultifiling() {
return true;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean hasUnfiling() {
return true;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean hasVersionSpecificFiling() {
return false;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isAllVersionsSearchable() {
return false;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean hasGetDescendants() {
return false;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean hasGetFolderTree() {
return false;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isContentStreamUpdatableAnytime() {
return true;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isPWCSearchable() {
return false;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isPWCUpdatable() {
return false;
}
+ /**
+ * {@inheritDoc}
+ */
public CapabilityACL getACLCapability() {
- // TODO Auto-generated method stub
return CapabilityACL.NONE;
}
}
Modified: incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml?rev=925158&r1=925157&r2=925158&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml Fri Mar 19 10:09:26 2010
@@ -148,7 +148,7 @@
<dependency>
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
- <version>1.0</version>
+ <version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.abdera</groupId>
Modified: incubator/chemistry/trunk/chemistry/chemistry-tests/pom.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/pom.xml?rev=925158&r1=925157&r2=925158&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tests/pom.xml (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tests/pom.xml Fri Mar 19 10:09:26 2010
@@ -28,7 +28,7 @@
<name>Chemistry Tests</name>
<properties>
- <jackrabbit.version>1.6.0</jackrabbit.version>
+ <jackrabbit.version>2.0.0</jackrabbit.version>
</properties>
<dependencies>
@@ -99,6 +99,24 @@
<artifactId>jackrabbit-core</artifactId>
<version>${jackrabbit.version}</version>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.tika</groupId>
+ <artifactId>tika-parsers</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
</dependencies>
Modified: incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestJcrRepository.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestJcrRepository.java?rev=925158&r1=925157&r2=925158&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestJcrRepository.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestJcrRepository.java Fri Mar 19 10:09:26 2010
@@ -20,19 +20,32 @@ package org.apache.chemistry.test;
import java.io.File;
import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Arrays;
+import javax.jcr.Node;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.Workspace;
+import javax.jcr.nodetype.NodeTypeManager;
+import org.apache.chemistry.BaseType;
import org.apache.chemistry.CapabilityQuery;
+import org.apache.chemistry.ContentStreamPresence;
+import org.apache.chemistry.Property;
+import org.apache.chemistry.PropertyDefinition;
+import org.apache.chemistry.PropertyType;
import org.apache.chemistry.Repository;
-import org.apache.chemistry.jcr.JcrObjectEntry;
+import org.apache.chemistry.Updatability;
+import org.apache.chemistry.impl.simple.SimplePropertyDefinition;
+import org.apache.chemistry.impl.simple.SimpleType;
import org.apache.chemistry.jcr.JcrRepository;
import org.apache.commons.io.FileUtils;
-import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
+import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.api.JackrabbitRepository;
+import org.apache.jackrabbit.commons.cnd.CndImporter;
import org.apache.jackrabbit.core.TransientRepository;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
/**
* Test on a Jackrabbit repository.
@@ -43,41 +56,87 @@ public class TestJcrRepository extends B
private static final String NODETYPES_CND = "/nodetypes.cnd";
+ private static final String REPOSITORY_XML = "/repository.xml";
+
protected JackrabbitRepository jackrabbitRepo;
+ protected Session session;
+
@Override
public Repository makeRepository() throws Exception {
File dir = new File(DIRECTORY);
FileUtils.deleteDirectory(dir);
dir.mkdirs();
- String config = new File(dir, "repository.xml").toString();
+
+ InputStream xml = getClass().getResourceAsStream(REPOSITORY_XML);
String home = new File(dir, "repository").toString();
- jackrabbitRepo = new TransientRepository(config, home);
- Session session = jackrabbitRepo.login(new SimpleCredentials("userid",
- "".toCharArray()));
+ RepositoryConfig config = RepositoryConfig.create(xml, home);
+ jackrabbitRepo = new TransientRepository(config);
+
+ session = jackrabbitRepo.login(new SimpleCredentials("userid", "".toCharArray()));
Workspace workspace = session.getWorkspace();
String workspaceName = workspace.getName();
+
// add mix:unstructured if needed
- JackrabbitNodeTypeManager ntm = (JackrabbitNodeTypeManager) workspace.getNodeTypeManager();
- if (!ntm.hasNodeType(JcrObjectEntry.MIX_UNSTRUCTURED)) {
+ NodeTypeManager ntm = workspace.getNodeTypeManager();
+ if (!ntm.hasNodeType(JcrRepository.MIX_UNSTRUCTURED)) {
InputStream is = getClass().getResourceAsStream(NODETYPES_CND);
- ntm.registerNodeTypes(is, JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
+ try {
+ CndImporter.registerNodeTypes(new InputStreamReader(is), session);
+ } finally {
+ is.close();
+ }
}
- session.logout();
+
+ // create root folder for tests
+ Node testRoot = session.getRootNode().addNode("testroot", JcrConstants.NT_FOLDER);
+ testRoot.addMixin(JcrRepository.MIX_UNSTRUCTURED);
+ testRoot.setProperty(Property.TYPE_ID, JcrRepository.ROOT_TYPE_ID);
+ testRoot.setProperty(Property.BASE_TYPE_ID, BaseType.FOLDER.getId());
+ session.save();
+ String rootNodeId = testRoot.getIdentifier();
expectedRepositoryId = "Jackrabbit";
expectedRepositoryName = "Jackrabbit";
expectedRepositoryDescription = "Jackrabbit";
expectedRepositoryVendor = "Apache Software Foundation";
expectedRepositoryProductName = "Jackrabbit";
- expectedRepositoryProductVersion = "1.6.0";
+ expectedRepositoryProductVersion = "2.0.0";
expectedCapabilityHasGetDescendants = false;
+ expectedCapabilityHasGetFolderTree = false;
expectedCapabilityHasMultifiling = true;
expectedCapabilityQuery = CapabilityQuery.BOTH_SEPARATE;
expectedCapabilityHasUnfiling = true;
- expectedRootTypeId = "rep:root";
- Repository repo = new JcrRepository(jackrabbitRepo, workspaceName);
+ rootFolderName = "testroot";
+
+ PropertyDefinition p1 = new SimplePropertyDefinition("title",
+ "def:title", null, "title", "Title", "", false,
+ PropertyType.STRING, false, null, false, false, "(no title)",
+ Updatability.READ_WRITE, true, true, 0, null, null, -1, null);
+ PropertyDefinition p2 = new SimplePropertyDefinition("description",
+ "def:description", null, "description", "Description", "",
+ false, PropertyType.STRING, false, null, false, false, "",
+ Updatability.READ_WRITE, true, true, 0, null, null, -1, null);
+ PropertyDefinition p3 = new SimplePropertyDefinition("date",
+ "def:date", null, "date", "Date", "", false,
+ PropertyType.DATETIME, false, null, false, false, null,
+ Updatability.READ_WRITE, true, true, 0, null, null, -1, null);
+ SimpleType dt = new SimpleType("doc", BaseType.DOCUMENT.getId(), "doc",
+ null, "Doc", "My Doc Type", BaseType.DOCUMENT, "", true, true,
+ true, true, true, true, true, true,
+ ContentStreamPresence.ALLOWED, null, null, Arrays.asList(p1,
+ p2, p3));
+ SimpleType ft = new SimpleType("fold", BaseType.FOLDER.getId(), "fold",
+ null, "Fold", "My Folder Type", BaseType.FOLDER, "", true,
+ true, true, true, true, true, false, false,
+ ContentStreamPresence.NOT_ALLOWED, null, null, Arrays.asList(
+ p1, p2));
+
+ JcrRepository repo = new JcrRepository(jackrabbitRepo, Arrays.asList(dt, ft));
+ repo.setRootNodeId(rootNodeId);
+ repo.setWorkspace(workspaceName);
+ repo.setCredentials(new SimpleCredentials("admin", "admin".toCharArray()));
BasicHelper.populateRepository(repo);
return repo;
}
@@ -85,6 +144,7 @@ public class TestJcrRepository extends B
@Override
public void tearDown() throws Exception {
super.tearDown();
+ session.logout();
jackrabbitRepo.shutdown();
}
Modified: incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/resources/nodetypes.cnd
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/resources/nodetypes.cnd?rev=925158&r1=925157&r2=925158&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/resources/nodetypes.cnd (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/resources/nodetypes.cnd Fri Mar 19 10:09:26 2010
@@ -14,6 +14,7 @@
<nt='http://www.jcp.org/jcr/nt/1.0'>
<mix='http://www.jcp.org/jcr/mix/1.0'>
+<cmis='cmis'>
/**
* This mixin is used to store unstructured content. It allows any number of
Added: incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/resources/repository.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/resources/repository.xml?rev=925158&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/resources/repository.xml (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/resources/repository.xml Fri Mar 19 10:09:26 2010
@@ -0,0 +1,132 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!DOCTYPE Repository
+ PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 2.0//EN"
+ "http://jackrabbit.apache.org/dtd/repository-2.0.dtd">
+
+<Repository>
+ <!--
+ virtual file system where the repository stores global state
+ (e.g. registered namespaces, custom node types, etc.)
+ -->
+ <FileSystem class="org.apache.jackrabbit.core.fs.mem.MemoryFileSystem" />
+
+ <!--
+ data store configuration
+ -->
+ <DataStore class="org.apache.jackrabbit.core.data.FileDataStore"/>
+
+ <!--
+ security configuration
+ -->
+ <Security appName="Jackrabbit">
+ <!--
+ security manager:
+ class: FQN of class implementing the JackrabbitSecurityManager interface
+ -->
+ <SecurityManager class="org.apache.jackrabbit.core.security.simple.SimpleSecurityManager" workspaceName="security">
+ <!--
+ workspace access:
+ class: FQN of class implementing the WorkspaceAccessManager interface
+ -->
+ <!-- <WorkspaceAccessManager class="..."/> -->
+ <!-- <param name="config" value="${rep.home}/security.xml"/> -->
+ </SecurityManager>
+
+ <!--
+ access manager:
+ class: FQN of class implementing the AccessManager interface
+ -->
+ <AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager">
+ <!-- <param name="config" value="${rep.home}/access.xml"/> -->
+ </AccessManager>
+
+ <LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
+ <!--
+ anonymous user name ('anonymous' is the default value)
+ -->
+ <param name="anonymousId" value="anonymous"/>
+ <!--
+ administrator user id (default value if param is missing is 'admin')
+ -->
+ <param name="adminId" value="admin"/>
+ </LoginModule>
+ </Security>
+
+ <!--
+ location of workspaces root directory and name of default workspace
+ -->
+ <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/>
+ <!--
+ workspace configuration template:
+ used to create the initial workspace if there's no workspace yet
+ -->
+ <Workspace name="${wsp.name}">
+ <!--
+ virtual file system of the workspace:
+ class: FQN of class implementing the FileSystem interface
+ -->
+ <FileSystem class="org.apache.jackrabbit.core.fs.mem.MemoryFileSystem" />
+ <!--
+ persistence manager of the workspace:
+ class: FQN of class implementing the PersistenceManager interface
+ -->
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.mem.InMemPersistenceManager" />
+ <!--
+ Search index and the file system it uses.
+ class: FQN of class implementing the QueryHandler interface
+ -->
+ <!--
+ <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+ <param name="path" value="${wsp.home}/index"/>
+ <param name="supportHighlighting" value="true"/>
+ </SearchIndex>
+ -->
+ </Workspace>
+
+ <!--
+ Configures the versioning
+ -->
+ <Versioning rootPath="${rep.home}/version">
+ <!--
+ Configures the filesystem to use for versioning for the respective
+ persistence manager
+ -->
+ <FileSystem class="org.apache.jackrabbit.core.fs.mem.MemoryFileSystem" />
+
+ <!--
+ Configures the persistence manager to be used for persisting version state.
+ Please note that the current versioning implementation is based on
+ a 'normal' persistence manager, but this could change in future
+ implementations.
+ -->
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.mem.InMemPersistenceManager" />
+ </Versioning>
+
+ <!--
+ Search index for content that is shared repository wide
+ (/jcr:system tree, contains mainly versions)
+ -->
+ <!--
+ <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+ <param name="path" value="${rep.home}/repository/index"/>
+ <param name="supportHighlighting" value="true"/>
+ </SearchIndex>
+ -->
+</Repository>
Propchange: incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/resources/repository.xml
------------------------------------------------------------------------------
svn:eol-style = native