Author: fmui
Date: Mon Jan 28 16:54:07 2013
New Revision: 1439493
URL: http://svn.apache.org/viewvc?rev=1439493&view=rev
Log:
Server: Simplified Browser Binding code
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserBindingUtils.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ControlParser.java
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserBindingUtils.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserBindingUtils.java?rev=1439493&r1=1439492&r2=1439493&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserBindingUtils.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserBindingUtils.java
Mon Jan 28 16:54:07 2013
@@ -208,79 +208,40 @@ public final class BrowserBindingUtils {
}
public static Properties createNewProperties(ControlParser controlParser,
TypeCache typeCache) {
- List<String> propertyIds =
controlParser.getValues(Constants.CONTROL_PROP_ID);
- if (propertyIds == null) {
+ Map<String, List<String>> properties = controlParser.getProperties();
+ if (properties == null) {
return null;
}
- Map<Integer, String> singleValuePropertyMap =
controlParser.getOneDimMap(Constants.CONTROL_PROP_VALUE);
- Map<Integer, Map<Integer, String>> multiValuePropertyMap =
controlParser
- .getTwoDimMap(Constants.CONTROL_PROP_VALUE);
-
- // load types
- int i = 0;
- for (String propertId : propertyIds) {
- if (PropertyIds.OBJECT_TYPE_ID.equals(propertId) &&
singleValuePropertyMap != null) {
- String typeId = singleValuePropertyMap.get(i);
- if (typeId != null) {
- TypeDefinition typeDef =
typeCache.getTypeDefinition(typeId);
- if (typeDef == null) {
- throw new CmisInvalidArgumentException("Invalid type:
" + typeId);
- }
- }
+ // load primary type
+ List<String> objectTypeIdsValues =
properties.get(PropertyIds.OBJECT_TYPE_ID);
+ if (objectTypeIdsValues != null && !objectTypeIdsValues.isEmpty()) {
+ TypeDefinition typeDef =
typeCache.getTypeDefinition(objectTypeIdsValues.get(0));
+ if (typeDef == null) {
+ throw new CmisInvalidArgumentException("Invalid type: " +
objectTypeIdsValues.get(0));
}
+ }
- if (PropertyIds.SECONDARY_OBJECT_TYPE_IDS.equals(propertId)) {
- Map<Integer, String> values = null;
-
- if (multiValuePropertyMap != null) {
- values = multiValuePropertyMap.get(i);
- }
-
- if (values != null) {
- for (String secTypeId : values.values()) {
- TypeDefinition typeDef =
typeCache.getTypeDefinition(secTypeId);
- if (typeDef == null) {
- throw new CmisInvalidArgumentException("Invalid
secondary type: " + secTypeId);
- }
- }
- } else if (singleValuePropertyMap != null) {
- String value = singleValuePropertyMap.get(i);
- if (value != null) {
- TypeDefinition typeDef =
typeCache.getTypeDefinition(value);
- if (typeDef == null) {
- throw new CmisInvalidArgumentException("Invalid
secondary type: " + value);
- }
- }
+ // load secondary types
+ List<String> secondaryObjectTypeIdsValues =
properties.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
+ if (secondaryObjectTypeIdsValues != null &&
!secondaryObjectTypeIdsValues.isEmpty()) {
+ for (String secTypeId : secondaryObjectTypeIdsValues) {
+ TypeDefinition typeDef =
typeCache.getTypeDefinition(secTypeId);
+ if (typeDef == null) {
+ throw new CmisInvalidArgumentException("Invalid type: " +
secTypeId);
}
}
-
- i++;
}
// create properties
PropertiesImpl result = new PropertiesImpl();
-
- i = 0;
- for (String propertyId : propertyIds) {
- PropertyDefinition<?> propDef =
typeCache.getPropertyDefinition(propertyId);
+ for (Map.Entry<String, List<String>> property : properties.entrySet())
{
+ PropertyDefinition<?> propDef =
typeCache.getPropertyDefinition(property.getKey());
if (propDef == null) {
- throw new CmisInvalidArgumentException(propertyId + " is
unknown!");
- }
-
- PropertyData<?> propertyData = null;
-
- if (singleValuePropertyMap != null &&
singleValuePropertyMap.containsKey(i)) {
- propertyData = createPropertyData(propDef,
singleValuePropertyMap.get(i));
- } else if (multiValuePropertyMap != null &&
multiValuePropertyMap.containsKey(i)) {
- propertyData = createPropertyData(propDef,
controlParser.getValues(Constants.CONTROL_PROP_VALUE, i));
- } else {
- propertyData = createPropertyData(propDef, null);
+ throw new CmisInvalidArgumentException(property.getKey() + "
is unknown!");
}
- result.addProperty(propertyData);
-
- i++;
+ result.addProperty(createPropertyData(propDef,
property.getValue()));
}
return result;
@@ -288,16 +249,12 @@ public final class BrowserBindingUtils {
public static Properties createUpdateProperties(ControlParser
controlParser, String typeId,
List<String> secondaryTypeIds, List<String> objectIds, TypeCache
typeCache) {
- List<String> propertyIds =
controlParser.getValues(Constants.CONTROL_PROP_ID);
- if (propertyIds == null) {
+ Map<String, List<String>> properties = controlParser.getProperties();
+ if (properties == null) {
return null;
}
- Map<Integer, String> singleValuePropertyMap =
controlParser.getOneDimMap(Constants.CONTROL_PROP_VALUE);
- Map<Integer, Map<Integer, String>> multiValuePropertyMap =
controlParser
- .getTwoDimMap(Constants.CONTROL_PROP_VALUE);
-
- // get type definition
+ // load primary type
if (typeId != null) {
TypeDefinition typeDef = typeCache.getTypeDefinition(typeId);
if (typeDef == null) {
@@ -305,36 +262,15 @@ public final class BrowserBindingUtils {
}
}
- // get secondary type definition
- int i = 0;
- for (String propertId : propertyIds) {
- if (PropertyIds.SECONDARY_OBJECT_TYPE_IDS.equals(propertId)) {
- Map<Integer, String> values = null;
-
- if (multiValuePropertyMap != null) {
- values = multiValuePropertyMap.get(i);
- }
-
- if (values != null) {
- for (String secTypeId : values.values()) {
- TypeDefinition typeDef =
typeCache.getTypeDefinition(secTypeId);
- if (typeDef == null) {
- throw new CmisInvalidArgumentException("Invalid
secondary type: " + secTypeId);
- }
- }
- } else if (singleValuePropertyMap != null) {
- String value = singleValuePropertyMap.get(i);
- if (value != null) {
- TypeDefinition typeDef =
typeCache.getTypeDefinition(value);
- if (typeDef == null) {
- throw new CmisInvalidArgumentException("Invalid
secondary type: " + value);
- }
- }
+ // load secondary types
+ List<String> secondaryObjectTypeIdsValues =
properties.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
+ if (secondaryObjectTypeIdsValues != null &&
!secondaryObjectTypeIdsValues.isEmpty()) {
+ for (String secTypeId : secondaryObjectTypeIdsValues) {
+ TypeDefinition typeDef =
typeCache.getTypeDefinition(secTypeId);
+ if (typeDef == null) {
+ throw new CmisInvalidArgumentException("Invalid type: " +
secTypeId);
}
- break;
}
-
- i++;
}
if (secondaryTypeIds != null) {
@@ -348,36 +284,22 @@ public final class BrowserBindingUtils {
// create properties
PropertiesImpl result = new PropertiesImpl();
-
- i = 0;
- for (String propertyId : propertyIds) {
- PropertyDefinition<?> propDef =
typeCache.getPropertyDefinition(propertyId);
+ for (Map.Entry<String, List<String>> property : properties.entrySet())
{
+ PropertyDefinition<?> propDef =
typeCache.getPropertyDefinition(property.getKey());
if (propDef == null && objectIds != null) {
for (String objectId : objectIds) {
typeCache.getTypeDefinitionForObject(objectId);
- propDef = typeCache.getPropertyDefinition(propertyId);
+ propDef =
typeCache.getPropertyDefinition(property.getKey());
if (propDef != null) {
break;
}
}
}
if (propDef == null) {
- throw new CmisInvalidArgumentException(propertyId + " is
unknown!");
+ throw new CmisInvalidArgumentException(property.getKey() + "
is unknown!");
}
- PropertyData<?> propertyData = null;
-
- if (singleValuePropertyMap != null &&
singleValuePropertyMap.containsKey(i)) {
- propertyData = createPropertyData(propDef,
singleValuePropertyMap.get(i));
- } else if (multiValuePropertyMap != null &&
multiValuePropertyMap.containsKey(i)) {
- propertyData = createPropertyData(propDef,
controlParser.getValues(Constants.CONTROL_PROP_VALUE, i));
- } else {
- propertyData = createPropertyData(propDef, null);
- }
-
- result.addProperty(propertyData);
-
- i++;
+ result.addProperty(createPropertyData(propDef,
property.getValue()));
}
return result;
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ControlParser.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ControlParser.java?rev=1439493&r1=1439492&r2=1439493&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ControlParser.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ControlParser.java
Mon Jan 28 16:54:07 2013
@@ -19,7 +19,9 @@
package org.apache.chemistry.opencmis.server.impl.browser;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -27,12 +29,16 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import
org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+import org.apache.chemistry.opencmis.commons.impl.Constants;
/**
* Parses HTML form controls.
*/
public class ControlParser {
+ public static final String CONTROL_PROP_ID_LOWER = "propertyid";
+ private static final String CONTROL_PROP_VALUE_LOWER = "propertyvalue";
+
private final HttpServletRequest request;
private final Map<String, String> zeroDim = new HashMap<String, String>();
@@ -193,4 +199,50 @@ public class ControlParser {
return twoDim.get(controlName.toLowerCase(Locale.ENGLISH));
}
+
+ public Map<String, List<String>> getProperties() {
+ Map<Integer, String> propertyIds = oneDim.get(CONTROL_PROP_ID_LOWER);
+ if (propertyIds == null) {
+ return null;
+ }
+
+ Map<Integer, String> oneDimPropValues =
oneDim.get(CONTROL_PROP_VALUE_LOWER);
+ Map<Integer, Map<Integer, String>> twoDimPropValues =
twoDim.get(CONTROL_PROP_VALUE_LOWER);
+
+ int count = propertyIds.size();
+ Map<String, List<String>> result = new LinkedHashMap<String,
List<String>>();
+
+ for (int i = 0; i < count; i++) {
+ String propertyId = propertyIds.get(i);
+ if (propertyId == null) {
+ throw new
CmisInvalidArgumentException(Constants.CONTROL_PROP_ID + " has gaps!");
+ }
+
+ List<String> values = null;
+ if (oneDimPropValues != null && oneDimPropValues.containsKey(i)) {
+ values = Collections.singletonList(oneDimPropValues.get(i));
+ } else if (twoDimPropValues != null &&
twoDimPropValues.containsKey(i)) {
+ values = new ArrayList<String>();
+
+ Map<Integer, String> valuesMap = twoDimPropValues.get(i);
+ if (valuesMap != null) {
+ int valueCount = valuesMap.size();
+
+ for (int j = 0; j < valueCount; j++) {
+ String value = valuesMap.get(j);
+ if (value == null) {
+ throw new
CmisInvalidArgumentException(Constants.CONTROL_PROP_VALUE + "[" + i
+ + "] has gaps!");
+ }
+
+ values.add(value);
+ }
+ }
+ }
+
+ result.put(propertyId, values);
+ }
+
+ return result;
+ }
}