Author: fmui
Date: Tue Feb 1 16:33:39 2011
New Revision: 1066085
URL: http://svn.apache.org/viewvc?rev=1066085&view=rev
Log:
- browser binding update ... following the spec draft
Added:
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ControlParser.java
(with props)
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/createdocument.html
(with props)
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/createfolder.html
(with props)
Removed:
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/create.html
Modified:
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserBindingUtils.java
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.java
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/POSTHttpServletRequestWrapper.java
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/TypeCache.java
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.html
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/index.html
Modified:
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserBindingUtils.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserBindingUtils.java?rev=1066085&r1=1066084&r2=1066085&view=diff
==============================================================================
---
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserBindingUtils.java
(original)
+++
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserBindingUtils.java
Tue Feb 1 16:33:39 2011
@@ -23,12 +23,10 @@ import static org.apache.chemistry.openc
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.GregorianCalendar;
-import java.util.HashMap;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
import javax.servlet.http.Cookie;
@@ -36,6 +34,7 @@ import javax.servlet.http.HttpServletReq
import javax.servlet.http.HttpServletResponse;
import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.data.Ace;
import org.apache.chemistry.opencmis.commons.data.Acl;
import org.apache.chemistry.opencmis.commons.data.ContentStream;
import org.apache.chemistry.opencmis.commons.data.ObjectData;
@@ -47,6 +46,9 @@ import org.apache.chemistry.opencmis.com
import
org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.apache.chemistry.opencmis.commons.impl.Base64;
import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlEntryImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlListImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlPrincipalDataImpl;
import
org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl;
import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanImpl;
@@ -85,18 +87,26 @@ public class BrowserBindingUtils {
public static final String SELECTOR_QUERY = "query";
public static final String SELECTOR_VERSIONS = "versions";
- public static final String ACTION_CREATEDOCUMENT = "createDocument";
- public static final String ACTION_QUERY = "query";
+ public static final String CMISACTION_CREATEDOCUMENT = "createDocument";
+ public static final String CMISACTION_CREATEFOLDER = "createFolder";
+ public static final String CMISACTION_QUERY = "query";
public static final String PARAM_SELECTOR = "selector";
public static final String PARAM_TRANSACTION = "transaction";
public static final String PARAM_CLIENTTOKEN = "clientToken";
- public static final String FIELD_ACTION = "cmisaction";
- public static final String FIELD_TRANSACTION = "transaction";
- public static final String FIELD_OBJECT_ID = "objectId";
- public static final String FIELD_PROP_NAME = "property_name_";
- public static final String FIELD_PROP_VALUE = "property_value_";
+ public static final String CONTROL_CMISACTION = "cmisaction";
+ public static final String CONTROL_TRANSACTION = "transaction";
+ public static final String CONTROL_OBJECT_ID = "objectid";
+ public static final String CONTROL_PROP_ID = "propertyid";
+ public static final String CONTROL_PROP_VALUE = "propertyvalue";
+ public static final String CONTROL_POLICY = "policy";
+ public static final String CONTROL_ADD_ACE_PRINCIPAL = "addACEPrincipal";
+ public static final String CONTROL_ADD_ACE_PERMISSION = "addACEPermission";
+ public static final String CONTROL_REMOVE_ACE_PRINCIPAL =
"removeACEPrincipal";
+ public static final String CONTROL_REMOVE_ACE_PERMISSION =
"removeACEPermission";
+ public static final String CONTROL_CONTENT_TYPE = "contenttype";
+ public static final String CONTROL_FILENAME = "filename";
public static final String CONTEXT_OBJECT_ID =
"org.apache.chemistry.openmis.browserbinding.objectId";
public static final String CONTEXT_OBJECT_TYPE_ID =
"org.apache.chemistry.openmis.browserbinding.objectTypeId";
@@ -160,7 +170,7 @@ public class BrowserBindingUtils {
if (context instanceof CallContextImpl) {
((CallContextImpl) context).put(CONTEXT_TRANSACTION, transaction);
}
-
+
if (callUrl != CallUrl.ROOT) {
return;
}
@@ -216,119 +226,180 @@ public class BrowserBindingUtils {
return (T) value;
}
- @SuppressWarnings("unchecked")
- public static Properties createProperties(HttpServletRequest request,
String typeId, TypeCache typeCache) {
- Map<Integer, String> names = new HashMap<Integer, String>();
- Map<Integer, String> values = new HashMap<Integer, String>();
- int typeIdIndex = -1;
-
- Map<String, String[]> fields = request.getParameterMap();
- for (Map.Entry<String, String[]> field : fields.entrySet()) {
- String fieldName = field.getKey().toLowerCase();
+ public static Properties createProperties(ControlParser controlParser,
String typeId, TypeCache typeCache) {
+ List<String> propertyIds = controlParser.getValues(CONTROL_PROP_ID);
+ if (propertyIds == null) {
+ return null;
+ }
- try {
- if (fieldName.startsWith(FIELD_PROP_NAME)) {
- int index =
Integer.parseInt(fieldName.substring(FIELD_PROP_NAME.length()));
- names.put(index, field.getValue()[0]);
-
- if
(PropertyIds.OBJECT_TYPE_ID.equals(field.getValue()[0])) {
- typeIdIndex = index;
- }
- } else if (fieldName.startsWith(FIELD_PROP_VALUE)) {
- int index =
Integer.parseInt(fieldName.substring(FIELD_PROP_VALUE.length()));
- values.put(index, field.getValue()[0]);
+ Map<Integer, String> singleValuePropertyMap =
controlParser.getOneDimMap(CONTROL_PROP_VALUE);
+ Map<Integer, Map<Integer, String>> multiValuePropertyMap =
controlParser.getTwoDimMap(CONTROL_PROP_VALUE);
+
+ if (typeId == null) {
+ // it's a create call -> find type id in properties
+ int i = 0;
+ for (String propertId : propertyIds) {
+ if (PropertyIds.OBJECT_TYPE_ID.equals(propertId)) {
+ typeId = singleValuePropertyMap.get(i);
+ break;
}
- } catch (NumberFormatException e) {
+
+ i++;
}
- }
- if ((typeId == null) && (typeIdIndex > -1)) {
- // it's a create call -> find type id in properties
- typeId = values.get(typeIdIndex);
+ if (typeId == null) {
+ throw new
CmisInvalidArgumentException(PropertyIds.OBJECT_TYPE_ID + " not set!");
+ }
}
TypeDefinition typeDef = typeCache.getTypeDefinition(typeId);
if (typeDef == null) {
- throw new CmisInvalidArgumentException(PropertyIds.OBJECT_TYPE_ID
+ " not set!");
+ throw new CmisInvalidArgumentException("Invalid type: " + typeId);
}
PropertiesImpl result = new PropertiesImpl();
- for (Map.Entry<Integer, String> property : names.entrySet()) {
- PropertyDefinition<?> propDef =
typeDef.getPropertyDefinitions().get(property.getValue());
+ int i = 0;
+ for (String propertyId : propertyIds) {
+ PropertyDefinition<?> propDef =
typeDef.getPropertyDefinitions().get(propertyId);
if (propDef == null) {
- throw new CmisInvalidArgumentException(property.getValue() + "
is unknown!");
+ throw new CmisInvalidArgumentException(propertyId + " is
unknown!");
}
- String value = values.get(property.getKey());
-
PropertyData<?> propertyData = null;
- switch (propDef.getPropertyType()) {
- case STRING:
- propertyData = new PropertyStringImpl(property.getValue(),
value);
- break;
- case ID:
- propertyData = new PropertyIdImpl(property.getValue(), value);
- break;
- case BOOLEAN:
- propertyData = new PropertyBooleanImpl(property.getValue(),
Boolean.valueOf(value));
- break;
- case INTEGER:
- BigInteger valueInt = null;
- try {
- valueInt = new BigInteger(value);
- } catch (NumberFormatException e) {
- throw new CmisInvalidArgumentException(property.getValue()
+ " is not an integer value!");
- }
- propertyData = new PropertyIntegerImpl(property.getValue(),
valueInt);
- break;
- case DECIMAL:
- BigDecimal valueDec = null;
- try {
- valueDec = new BigDecimal(value);
- } catch (NumberFormatException e) {
- throw new CmisInvalidArgumentException(property.getValue()
+ " is not a decimal value!");
- }
- propertyData = new PropertyDecimalImpl(property.getValue(),
valueDec);
- break;
- case DATETIME:
- GregorianCalendar valueDate = new GregorianCalendar();
- SimpleDateFormat sdf = new
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
- try {
- valueDate.setTime(sdf.parse(value));
- } catch (ParseException e) {
- throw new CmisInvalidArgumentException(property.getValue()
+ " is not a datetime value!");
- }
- propertyData = new PropertyDateTimeImpl(property.getValue(),
valueDate);
- break;
- case HTML:
- propertyData = new PropertyHtmlImpl(property.getValue(),
value);
- break;
- case URI:
- propertyData = new PropertyUriImpl(property.getValue(), value);
- break;
+
+ if (singleValuePropertyMap.containsKey(i)) {
+ propertyData = createPropertyData(propDef,
singleValuePropertyMap.get(i));
+ } else if (multiValuePropertyMap.containsKey(i)) {
+ propertyData = createPropertyData(propDef,
controlParser.getValues(CONTROL_PROP_VALUE, i));
+ } else {
+ propertyData = createPropertyData(propDef, null);
}
result.addProperty(propertyData);
+
+ i++;
}
return result;
}
- public static List<String> createPolcies(HttpServletRequest request) {
- return null;
+ @SuppressWarnings("unchecked")
+ private static PropertyData<?> createPropertyData(PropertyDefinition<?>
propDef, Object value) {
+
+ List<String> strValues;
+ if (value == null) {
+ strValues = Collections.emptyList();
+ } else if (value instanceof String) {
+ strValues = new ArrayList<String>();
+ strValues.add((String) value);
+ } else {
+ strValues = (List<String>) value;
+ }
+
+ PropertyData<?> propertyData = null;
+ switch (propDef.getPropertyType()) {
+ case STRING:
+ propertyData = new PropertyStringImpl(propDef.getId(), strValues);
+ break;
+ case ID:
+ propertyData = new PropertyIdImpl(propDef.getId(), strValues);
+ break;
+ case BOOLEAN:
+ List<Boolean> boolValues = new
ArrayList<Boolean>(strValues.size());
+ try {
+ for (String s : strValues) {
+ boolValues.add(Boolean.valueOf(s));
+ }
+ } catch (NumberFormatException e) {
+ throw new CmisInvalidArgumentException(propDef.getId() + "
value is not a boolean value!");
+ }
+ propertyData = new PropertyBooleanImpl(propDef.getId(),
boolValues);
+ break;
+ case INTEGER:
+ List<BigInteger> intValues = new
ArrayList<BigInteger>(strValues.size());
+ try {
+ for (String s : strValues) {
+ intValues.add(new BigInteger(s));
+ }
+ } catch (NumberFormatException e) {
+ throw new CmisInvalidArgumentException(propDef.getId() + "
value is not an integer value!");
+ }
+ propertyData = new PropertyIntegerImpl(propDef.getId(), intValues);
+ break;
+ case DECIMAL:
+ List<BigDecimal> decValues = new
ArrayList<BigDecimal>(strValues.size());
+ try {
+ for (String s : strValues) {
+ decValues.add(new BigDecimal(s));
+ }
+ } catch (NumberFormatException e) {
+ throw new CmisInvalidArgumentException(propDef.getId() + "
value is not an integer value!");
+ }
+ propertyData = new PropertyDecimalImpl(propDef.getId(), decValues);
+ break;
+ case DATETIME:
+ List<GregorianCalendar> calValues = new
ArrayList<GregorianCalendar>(strValues.size());
+ try {
+ for (String s : strValues) {
+ GregorianCalendar cal = new GregorianCalendar();
+ cal.setTimeInMillis(Long.parseLong(s));
+ calValues.add(cal);
+ }
+ } catch (NumberFormatException e) {
+ throw new CmisInvalidArgumentException(propDef.getId() + "
value is not an datetime value!");
+ }
+ propertyData = new PropertyDateTimeImpl(propDef.getId(),
calValues);
+ break;
+ case HTML:
+ propertyData = new PropertyHtmlImpl(propDef.getId(), strValues);
+ break;
+ case URI:
+ propertyData = new PropertyUriImpl(propDef.getId(), strValues);
+ break;
+ }
+
+ return propertyData;
}
- public static Acl createAcl(HttpServletRequest request) {
- return null;
+ public static List<String> createPolicies(ControlParser controlParser) {
+ return controlParser.getValues(CONTROL_POLICY);
}
- public static Acl createAddAcl(HttpServletRequest request) {
- return null;
+ public static Acl createAddAcl(ControlParser controlParser) {
+ List<String> principals =
controlParser.getValues(CONTROL_ADD_ACE_PRINCIPAL);
+ if (principals == null) {
+ return null;
+ }
+
+ List<Ace> aces = new ArrayList<Ace>();
+
+ int i = 0;
+ for (String principalId : principals) {
+ aces.add(new AccessControlEntryImpl(new
AccessControlPrincipalDataImpl(principalId), controlParser
+ .getValues(CONTROL_ADD_ACE_PERMISSION, i)));
+ i++;
+ }
+
+ return new AccessControlListImpl(aces);
}
- public static Acl createRemoveAcl(HttpServletRequest request) {
- return null;
+ public static Acl createRemoveAcl(ControlParser controlParser) {
+ List<String> principals =
controlParser.getValues(CONTROL_REMOVE_ACE_PRINCIPAL);
+ if (principals == null) {
+ return null;
+ }
+
+ List<Ace> aces = new ArrayList<Ace>();
+
+ int i = 0;
+ for (String principalId : principals) {
+ aces.add(new AccessControlEntryImpl(new
AccessControlPrincipalDataImpl(principalId), controlParser
+ .getValues(CONTROL_REMOVE_ACE_PERMISSION, i)));
+ i++;
+ }
+
+ return new AccessControlListImpl(aces);
}
public static ContentStream createContentStream(HttpServletRequest
request) {
@@ -336,7 +407,7 @@ public class BrowserBindingUtils {
if (request instanceof POSTHttpServletRequestWrapper) {
POSTHttpServletRequestWrapper post =
(POSTHttpServletRequestWrapper) request;
- result = new ContentStreamImpl(post.getFileName(),
BigInteger.valueOf(post.getSize()),
+ result = new ContentStreamImpl(post.getFilename(),
BigInteger.valueOf(post.getSize()),
post.getContentType(), post.getStream());
}
@@ -350,7 +421,7 @@ public class BrowserBindingUtils {
if ((transaction == null) || (transaction.length() == 0)) {
return "cmis%";
}
-
+
return "cmis_" +
Base64.encodeBytes(transaction.getBytes()).replace('=', '%');
}
@@ -382,15 +453,15 @@ public class BrowserBindingUtils {
response.addCookie(tansactionCookie);
}
}
-
+
@SuppressWarnings("unchecked")
public static String createCookieValue(int code, String objectId, String
error) {
JSONObject result = new JSONObject();
-
+
result.put("code", code);
result.put("objectId", objectId);
result.put("error", error);
-
+
return result.toJSONString();
}
Modified:
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.java?rev=1066085&r1=1066084&r2=1066085&view=diff
==============================================================================
---
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.java
(original)
+++
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.java
Tue Feb 1 16:33:39 2011
@@ -100,9 +100,9 @@ public class CmisBrowserBindingServlet e
RepositoryService.class, "getTypeDefintion");
repositoryDispatcher.addResource(BrowserBindingUtils.SELECTOR_QUERY,
Dispatcher.METHOD_GET,
DiscoveryService.class, "query");
- repositoryDispatcher.addResource(BrowserBindingUtils.ACTION_QUERY,
Dispatcher.METHOD_POST,
+
repositoryDispatcher.addResource(BrowserBindingUtils.CMISACTION_QUERY,
Dispatcher.METHOD_POST,
DiscoveryService.class, "query");
-
repositoryDispatcher.addResource(BrowserBindingUtils.ACTION_CREATEDOCUMENT,
Dispatcher.METHOD_POST,
+
repositoryDispatcher.addResource(BrowserBindingUtils.CMISACTION_CREATEDOCUMENT,
Dispatcher.METHOD_POST,
ObjectService.class, "createDocument");
rootDispatcher.addResource(BrowserBindingUtils.SELECTOR_OBJECT,
Dispatcher.METHOD_GET, ObjectService.class,
@@ -119,8 +119,10 @@ public class CmisBrowserBindingServlet e
NavigationService.class, "getObjectParents");
rootDispatcher.addResource(BrowserBindingUtils.SELECTOR_VERSIONS,
Dispatcher.METHOD_GET,
VersioningService.class, "getAllVersions");
-
rootDispatcher.addResource(BrowserBindingUtils.ACTION_CREATEDOCUMENT,
Dispatcher.METHOD_POST,
+
rootDispatcher.addResource(BrowserBindingUtils.CMISACTION_CREATEDOCUMENT,
Dispatcher.METHOD_POST,
ObjectService.class, "createDocument");
+
rootDispatcher.addResource(BrowserBindingUtils.CMISACTION_CREATEFOLDER,
Dispatcher.METHOD_POST,
+ ObjectService.class, "createFolder");
} catch (NoSuchMethodException e) {
LOG.error("Cannot initialize dispatcher!", e);
}
@@ -245,11 +247,11 @@ public class CmisBrowserBindingServlet e
} else if (Dispatcher.METHOD_POST.equals(method)) {
POSTHttpServletRequestWrapper postRequest = new
POSTHttpServletRequestWrapper(request);
- String action = HttpUtils.getStringParameter(postRequest,
BrowserBindingUtils.FIELD_ACTION);
- String objectId = HttpUtils.getStringParameter(postRequest,
BrowserBindingUtils.FIELD_OBJECT_ID);
- String transaction = HttpUtils.getStringParameter(postRequest,
BrowserBindingUtils.FIELD_TRANSACTION);
+ String cmisaction = HttpUtils.getStringParameter(postRequest,
BrowserBindingUtils.CONTROL_CMISACTION);
+ String objectId = HttpUtils.getStringParameter(postRequest,
BrowserBindingUtils.CONTROL_OBJECT_ID);
+ String transaction = HttpUtils.getStringParameter(postRequest,
BrowserBindingUtils.CONTROL_TRANSACTION);
- if ((action == null) || (action.length() == 0)) {
+ if ((cmisaction == null) || (cmisaction.length() == 0)) {
throw new CmisNotSupportedException("Unknown action");
}
@@ -259,11 +261,11 @@ public class CmisBrowserBindingServlet e
// dispatch
if (callUrl == CallUrl.REPOSITORY) {
- methodFound = repositoryDispatcher.dispatch(action,
method, context, service, repositoryId,
+ methodFound = repositoryDispatcher.dispatch(cmisaction,
method, context, service, repositoryId,
postRequest, response);
} else if (callUrl == CallUrl.ROOT) {
- methodFound = rootDispatcher.dispatch(action, method,
context, service, repositoryId, postRequest,
- response);
+ methodFound = rootDispatcher.dispatch(cmisaction, method,
context, service, repositoryId,
+ postRequest, response);
}
}
Added:
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ControlParser.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ControlParser.java?rev=1066085&view=auto
==============================================================================
---
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ControlParser.java
(added)
+++
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ControlParser.java
Tue Feb 1 16:33:39 2011
@@ -0,0 +1,195 @@
+/*
+ * 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.
+ */
+package org.apache.chemistry.opencmis.server.impl.browser;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import
org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+
+/**
+ * Parses form controls.
+ */
+public class ControlParser {
+
+ private HttpServletRequest request;
+
+ private Map<String, String> zeroDim = new HashMap<String, String>();
+ private Map<String, Map<Integer, String>> oneDim = new HashMap<String,
Map<Integer, String>>();
+ private Map<String, Map<Integer, Map<Integer, String>>> twoDim = new
HashMap<String, Map<Integer, Map<Integer, String>>>();
+
+ public ControlParser(HttpServletRequest request) {
+ this.request = request;
+ parse();
+ }
+
+ @SuppressWarnings("unchecked")
+ private void parse() {
+ // gather all controls
+ Map<String, String[]> controls = request.getParameterMap();
+ for (Map.Entry<String, String[]> control : controls.entrySet()) {
+ String controlName = control.getKey().trim().toLowerCase();
+
+ int firstIndex = getFirstIndex(controlName);
+
+ if (firstIndex == -1) {
+ zeroDim.put(controlName, control.getValue()[0]);
+ } else {
+ String strippedControlName = controlName.substring(0,
controlName.indexOf('['));
+ int secondIndex = getSecondIndex(controlName);
+
+ if (secondIndex == -1) {
+ Map<Integer, String> values =
oneDim.get(strippedControlName);
+ if (values == null) {
+ values = new HashMap<Integer, String>();
+ oneDim.put(strippedControlName, values);
+ }
+
+ values.put(firstIndex, control.getValue()[0]);
+ } else {
+ Map<Integer, Map<Integer, String>> values =
twoDim.get(strippedControlName);
+ if (values == null) {
+ values = new HashMap<Integer, Map<Integer, String>>();
+ twoDim.put(strippedControlName, values);
+ }
+
+ Map<Integer, String> list = values.get(firstIndex);
+ if (list == null) {
+ list = new HashMap<Integer, String>();
+ values.put(firstIndex, list);
+ }
+
+ list.put(secondIndex, control.getValue()[0]);
+ }
+ }
+ }
+ }
+
+ private int getFirstIndex(String controlName) {
+ int result = -1;
+
+ int open = controlName.indexOf('[');
+ int close = controlName.indexOf(']');
+
+ if (open == -1 || close == -1 || close < open) {
+ return result;
+ }
+
+ String indexStr = controlName.substring(open + 1, close);
+ try {
+ result = Integer.parseInt(indexStr);
+ if (result < 0) {
+ result = -1;
+ }
+ } catch (NumberFormatException e) {
+ }
+
+ return result;
+ }
+
+ private int getSecondIndex(String controlName) {
+ int result = -1;
+
+ int open = controlName.indexOf("][");
+ int close = controlName.lastIndexOf(']');
+
+ if (open == -1 || close == -1 || close < open) {
+ return result;
+ }
+
+ String indexStr = controlName.substring(open + 2, close);
+ try {
+ result = Integer.parseInt(indexStr);
+ if (result < 0) {
+ result = -1;
+ }
+ } catch (NumberFormatException e) {
+ }
+
+ return result;
+ }
+
+ private List<String> convertToList(String controlName, Map<Integer,
String> map) {
+ if (map == null) {
+ return null;
+ }
+
+ int count = map.size();
+ List<String> result = new ArrayList<String>(count);
+
+ for (int i = 0; i < count; i++) {
+ String value = map.get(i);
+ if (value == null) {
+ throw new CmisInvalidArgumentException(controlName + " has
gaps!");
+ }
+ result.add(value);
+ }
+
+ return result;
+ }
+
+ public String getValue(String controlName) {
+ if (controlName == null) {
+ throw new IllegalArgumentException("controlName must not be
null!");
+ }
+
+ return zeroDim.get(controlName.toLowerCase());
+ }
+
+ public List<String> getValues(String controlName) {
+ if (controlName == null) {
+ throw new IllegalArgumentException("controlName must not be
null!");
+ }
+
+ return convertToList(controlName,
oneDim.get(controlName.toLowerCase()));
+ }
+
+ public List<String> getValues(String controlName, int index) {
+ if (controlName == null) {
+ throw new IllegalArgumentException("controlName must not be
null!");
+ }
+
+ Map<Integer, Map<Integer, String>> map =
twoDim.get(controlName.toLowerCase());
+ if (map == null) {
+ return null;
+ }
+
+ return convertToList(controlName, map.get(index));
+ }
+
+ public Map<Integer, String> getOneDimMap(String controlName) {
+ if (controlName == null) {
+ throw new IllegalArgumentException("controlName must not be
null!");
+ }
+
+ return oneDim.get(controlName.toLowerCase());
+ }
+
+ public Map<Integer, Map<Integer, String>> getTwoDimMap(String controlName)
{
+ if (controlName == null) {
+ throw new IllegalArgumentException("controlName must not be
null!");
+ }
+
+ return twoDim.get(controlName.toLowerCase());
+ }
+}
Propchange:
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ControlParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java?rev=1066085&r1=1066084&r2=1066085&view=diff
==============================================================================
---
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java
(original)
+++
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java
Tue Feb 1 16:33:39 2011
@@ -59,13 +59,52 @@ public final class ObjectService {
VersioningState.class);
String transaction = getStringParameter(request,
BrowserBindingUtils.PARAM_TRANSACTION);
+ ControlParser cp = new ControlParser(request);
+
TypeCache typeCache = new TypeCache(repositoryId, service);
String newObjectId = service.createDocument(repositoryId,
- BrowserBindingUtils.createProperties(request, null,
typeCache), folderId,
+ BrowserBindingUtils.createProperties(cp, null, typeCache),
folderId,
BrowserBindingUtils.createContentStream(request),
versioningState,
- BrowserBindingUtils.createPolcies(request),
BrowserBindingUtils.createAddAcl(request),
- BrowserBindingUtils.createRemoveAcl(request), null);
+ BrowserBindingUtils.createPolicies(cp),
BrowserBindingUtils.createAddAcl(cp),
+ BrowserBindingUtils.createRemoveAcl(cp), null);
+
+ ObjectInfo objectInfo = service.getObjectInfo(repositoryId,
newObjectId);
+ if (objectInfo == null) {
+ throw new CmisRuntimeException("Object Info is missing!");
+ }
+
+ ObjectData object = objectInfo.getObject();
+ if (object == null) {
+ throw new CmisRuntimeException("Object is null!");
+ }
+
+ JSONObject jsonObject = JSONConverter.convert(object, typeCache);
+
+ response.setStatus(HttpServletResponse.SC_OK);
+ BrowserBindingUtils.setCookie(request, response, repositoryId,
transaction,
+ BrowserBindingUtils.createCookieValue(200, object.getId(),
null));
+
+ BrowserBindingUtils.writeJSON(jsonObject, request, response);
+ }
+
+ /**
+ * createFolder.
+ */
+ public static void createFolder(CallContext context, CmisService service,
String repositoryId,
+ HttpServletRequest request, HttpServletResponse response) throws
Exception {
+ // get parameters
+ String folderId = (String)
context.get(BrowserBindingUtils.CONTEXT_OBJECT_ID);
+ String transaction = getStringParameter(request,
BrowserBindingUtils.PARAM_TRANSACTION);
+
+ ControlParser cp = new ControlParser(request);
+
+ TypeCache typeCache = new TypeCache(repositoryId, service);
+
+ String newObjectId = service.createFolder(repositoryId,
+ BrowserBindingUtils.createProperties(cp, null, typeCache),
folderId,
+ BrowserBindingUtils.createPolicies(cp),
BrowserBindingUtils.createAddAcl(cp),
+ BrowserBindingUtils.createRemoveAcl(cp), null);
ObjectInfo objectInfo = service.getObjectInfo(repositoryId,
newObjectId);
if (objectInfo == null) {
Modified:
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/POSTHttpServletRequestWrapper.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/POSTHttpServletRequestWrapper.java?rev=1066085&r1=1066084&r2=1066085&view=diff
==============================================================================
---
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/POSTHttpServletRequestWrapper.java
(original)
+++
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/POSTHttpServletRequestWrapper.java
Tue Feb 1 16:33:39 2011
@@ -28,6 +28,7 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
+import org.apache.chemistry.opencmis.server.shared.HttpUtils;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
@@ -35,7 +36,7 @@ import org.apache.commons.fileupload.ser
public class POSTHttpServletRequestWrapper extends HttpServletRequestWrapper {
private boolean isMultipart;
private Map<String, String[]> parameters;
- private String fileName;
+ private String filename;
private String contentType;
private long size;
private InputStream stream;
@@ -72,12 +73,22 @@ public class POSTHttpServletRequestWrapp
parameters.put(item.getFieldName(), newValues);
}
} else {
- fileName = item.getName();
+ filename = item.getName();
contentType = (item.getContentType() == null ?
"application/octet-stream" : item.getContentType());
size = item.getSize();
stream = item.getInputStream();
}
}
+
+ String filenameControl = HttpUtils.getStringParameter(this,
BrowserBindingUtils.CONTROL_FILENAME);
+ if ((filenameControl) != null && (filenameControl.trim().length()
> 0)) {
+ filename = filenameControl;
+ }
+
+ String contentTypeControl = HttpUtils.getStringParameter(this,
BrowserBindingUtils.CONTROL_CONTENT_TYPE);
+ if ((contentTypeControl != null) &&
(contentTypeControl.trim().length() > 0)) {
+ contentType = contentTypeControl;
+ }
}
}
@@ -124,8 +135,8 @@ public class POSTHttpServletRequestWrapp
return parameters.get(name);
}
- public String getFileName() {
- return fileName;
+ public String getFilename() {
+ return filename;
}
public String getContentType() {
Modified:
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/TypeCache.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/TypeCache.java?rev=1066085&r1=1066084&r2=1066085&view=diff
==============================================================================
---
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/TypeCache.java
(original)
+++
incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/TypeCache.java
Tue Feb 1 16:33:39 2011
@@ -41,6 +41,7 @@ public class TypeCache {
TypeDefinition type = typeDefinitions.get(typeId);
if (type == null) {
type = service.getTypeDefinition(repositoryId, typeId, null);
+ typeDefinitions.put(type.getId(), type);
}
return type;
Added:
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/createdocument.html
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/createdocument.html?rev=1066085&view=auto
==============================================================================
---
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/createdocument.html
(added)
+++
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/createdocument.html
Tue Feb 1 16:33:39 2011
@@ -0,0 +1,117 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<title>OpenCMIS Browser Binding createDocument Demo</title>
+<style type="text/css">
+body {
+ font-family: Arial, sans-serif;
+ font-size: 11pt;
+}
+
+.box {
+ border-width: 1px;
+ border-style: solid;
+ width: 100%;
+ padding: 3px;
+}
+
+td {
+ padding: 5px;
+}
+</style>
+<script type="text/javascript">
+var repositoryUrl;
+var rootFolderUrl;
+var lastTransaction;
+
+function loadRepositoryInfos(infos) {
+ for(repId in infos) {
+ var ri = infos[repId];
+
+ // the InMemory repository has only one repository
+ repositoryUrl = ri.repositoryUrl;
+ rootFolderUrl = ri.rootFolderUrl;
+ }
+}
+
+function createDocument() {
+ var createForm = document.getElementById('createForm');
+ var docname = createForm["propertyValue[0]"].value;
+ document.getElementById('info').innerHTML = "Creating " + docname + " ...";
+
+ createForm.action = rootFolderUrl + createForm.folder.value;
+ lastTransaction = (new Date()).getTime() + "-" +
Math.floor(Math.random()*10000000) + "-" + docname;
+ createForm.transaction.value = lastTransaction;
+
+ return true;
+}
+
+function createDocumentCallback() {
+ if(lastTransaction) {
+ document.getElementById('info').innerHTML = 'Transaction: ' +
lastTransaction
+
+ var script1 = document.createElement("script");
+ script1.setAttribute("src", repositoryUrl +
"?selector=lastResult&clientToken=showNewDocumentId&transaction="+lastTransaction);
+ script1.setAttribute("type","text/javascript");
+ document.body.appendChild(script1);
+ }
+}
+
+function showNewDocumentId(result) {
+ if(result.objectId) {
+ alert("New document id: " + result.objectId + " (code: " + result.code
+ ")");
+ }
+ else {
+ alert("Error: " + result.error + " (code: " + result.code + ")");
+ }
+}
+</script>
+</head>
+<body>
+<h1>OpenCMIS Browser Binding - Create Demo</h1>
+
+<h2>Create Document</h2>
+
+<form id="createForm" action="" method="POST" target="result"
enctype="multipart/form-data" onsubmit="return createDocument()">
+<input name="cmisaction" type="hidden" value="createDocument" />
+<input name="transaction" type="hidden" value="" />
+<table>
+<tr>
+ <td>Folder:</td>
+ <td><input name="folder" type="text" size="100" maxlength="1000"
value="/"></td>
+</tr>
+<tr>
+ <td>Name:</td>
+ <td><input id="docname" name="propertyValue[0]" type="text" size="100"
maxlength="100" value="document"></td>
+ <input name="propertyId[0]" type="hidden" value="cmis:name" />
+</tr>
+<tr>
+ <td>Object Type:</td>
+ <td><input name="propertyValue[1]" type="text" size="100" maxlength="100"
value="cmis:document"></td>
+ <input name="propertyId[1]" type="hidden" value="cmis:objectTypeId" />
+</tr>
+<tr>
+ <td>File name:</td>
+ <td><input name="filename" type="text" size="100" maxlength="30" value="">
(if left blank the orignal file name is used)</td>
+</tr>
+<tr>
+ <td>Content type:</td>
+ <td><input name="contentType" type="text" size="100" maxlength="30"
value=""> (if left blank the content type is determined by the browser)</td>
+</tr>
+<tr>
+ <td>File:</td>
+ <td><input name="content" type="file"></td>
+</tr>
+<tr>
+ <td></td>
+ <td><input type="submit" value="Create" /></td>
+</tr>
+</table>
+</form>
+
+<div id="info"></div>
+<iframe name="result" style="border:2px;width:600px;height:400px;"
onload="createDocumentCallback()"></iframe>
+
+<script type="text/javascript"
src="browser?clientToken=loadRepositoryInfos"></script>
+</body>
+</html>
\ No newline at end of file
Propchange:
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/createdocument.html
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/createfolder.html
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/createfolder.html?rev=1066085&view=auto
==============================================================================
---
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/createfolder.html
(added)
+++
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/createfolder.html
Tue Feb 1 16:33:39 2011
@@ -0,0 +1,105 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<title>OpenCMIS Browser Binding createFolder Demo</title>
+<style type="text/css">
+body {
+ font-family: Arial, sans-serif;
+ font-size: 11pt;
+}
+
+.box {
+ border-width: 1px;
+ border-style: solid;
+ width: 100%;
+ padding: 3px;
+}
+
+td {
+ padding: 5px;
+}
+</style>
+<script type="text/javascript">
+var repositoryUrl;
+var rootFolderUrl;
+var lastTransaction;
+
+function loadRepositoryInfos(infos) {
+ for(repId in infos) {
+ var ri = infos[repId];
+
+ // the InMemory repository has only one repository
+ repositoryUrl = ri.repositoryUrl;
+ rootFolderUrl = ri.rootFolderUrl;
+ }
+}
+
+function createFolder() {
+ var createForm = document.getElementById('createForm');
+ var foldername = createForm["propertyValue[0]"].value;
+ document.getElementById('info').innerHTML = "Creating " + foldername + "
...";
+
+ createForm.action = rootFolderUrl + createForm.folder.value;
+ lastTransaction = (new Date()).getTime() + "-" +
Math.floor(Math.random()*10000000) + "-" + foldername;
+ createForm.transaction.value = lastTransaction;
+
+ return true;
+}
+
+function createFolderCallback() {
+ if(lastTransaction) {
+ document.getElementById('info').innerHTML = 'Transaction: ' +
lastTransaction
+
+ var script1 = document.createElement("script");
+ script1.setAttribute("src", repositoryUrl +
"?selector=lastResult&clientToken=showNewFolderId&transaction="+lastTransaction);
+ script1.setAttribute("type","text/javascript");
+ document.body.appendChild(script1);
+ }
+}
+
+function showNewFolderId(result) {
+ if(result.objectId) {
+ alert("New folder id: " + result.objectId + " (code: " + result.code +
")");
+ }
+ else {
+ alert("Error: " + result.error + " (code: " + result.code + ")");
+ }
+}
+</script>
+</head>
+<body>
+<h1>OpenCMIS Browser Binding - Create Demo</h1>
+
+<h2>Create Folder</h2>
+
+<form id="createForm" action="" method="POST" target="result" onsubmit="return
createFolder()">
+<input name="cmisaction" type="hidden" value="createFolder" />
+<input name="transaction" type="hidden" value="" />
+<table>
+<tr>
+ <td>Folder:</td>
+ <td><input name="folder" type="text" size="100" maxlength="1000"
value="/"></td>
+</tr>
+<tr>
+ <td>Name:</td>
+ <td><input id="docname" name="propertyValue[0]" type="text" size="100"
maxlength="100" value="folder"></td>
+ <input name="propertyId[0]" type="hidden" value="cmis:name" />
+</tr>
+<tr>
+ <td>Object Type:</td>
+ <td><input name="propertyValue[1]" type="text" size="100" maxlength="100"
value="cmis:folder"></td>
+ <input name="propertyId[1]" type="hidden" value="cmis:objectTypeId" />
+</tr>
+<tr>
+ <td></td>
+ <td><input type="submit" value="Create" /></td>
+</tr>
+</table>
+</form>
+
+<div id="info"></div>
+<iframe name="result" style="border:2px;width:600px;height:400px;"
onload="createFolderCallback()"></iframe>
+
+<script type="text/javascript"
src="browser?clientToken=loadRepositoryInfos"></script>
+</body>
+</html>
\ No newline at end of file
Propchange:
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/createfolder.html
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.html
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.html?rev=1066085&r1=1066084&r2=1066085&view=diff
==============================================================================
---
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.html
(original)
+++
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.html
Tue Feb 1 16:33:39 2011
@@ -178,7 +178,7 @@ function printTypes(types) {
<div id="query" class="box">
<h2>Query</h2>
<form id="queryForm" action="" method="POST">
-<input name="action" type="hidden" value="query" />
+<input name="cmisaction" type="hidden" value="query" />
<table>
<tr><td>Query:</td><td><input name="q" type="text" size="100" maxlength="1000"
value="SELECT * FROM cmis:document"></td></tr>
<tr><td>Max Items:</td><td><input name="maxItems" type="text" size="4"
maxlength="8" value="100"></td></tr>
Modified:
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/index.html
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/index.html?rev=1066085&r1=1066084&r2=1066085&view=diff
==============================================================================
---
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/index.html
(original)
+++
incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/index.html
Tue Feb 1 16:33:39 2011
@@ -17,7 +17,8 @@
<ul>
<li><a href="demo.html">Demo Page</a></li>
-<li><a href="create.html">Create Document Demo Page</a></li>
+<li><a href="createdocument.html">Create Document Demo Page</a></li>
+<li><a href="createfolder.html">Create Folder Demo Page</a></li>
<li><a href="browser">Repository Infos</a></li>
</ul>