Author: rombert
Date: Tue Sep 29 13:02:33 2015
New Revision: 1705853
URL: http://svn.apache.org/viewvc?rev=1705853&view=rev
Log:
SLING-4577 - Content sync does not support escaping comma values in
multi-valued properties
Fix and unit tests
Added:
sling/trunk/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/escaped-comma-in-multi-valued-property.xml
Modified:
sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java
sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java
Modified: sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java?rev=1705853&r1=1705852&r2=1705853&view=diff
==============================================================================
--- sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java
(original)
+++ sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java
Tue Sep 29 13:02:33 2015
@@ -188,6 +188,14 @@ public class ContentXmlHandlerTest {
(Object) "{0,date,dd.MM.yyyy HH:mm:ss.SSS} *{4}* [{2}] {3} {5}"));
}
+ @Test
+ public void escapedCommaInMultiValuedProperty() throws Exception {
+
+ ResourceProxy root = parseContentXmlFile("escaped-comma-in-multi-valued-property.xml",
"/");
+ assertThat("properties[someProp]", (String[]) root.getProperties().get("someProp"),
+ Matchers.is(new String[] { "first,first", "second" }));
+ }
+
private static Matcher<Calendar> millis(long millis) {
return new CalendarTimeInMillisMatcher(millis);
Added: sling/trunk/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/escaped-comma-in-multi-valued-property.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/escaped-comma-in-multi-valued-property.xml?rev=1705853&view=auto
==============================================================================
--- sling/trunk/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/escaped-comma-in-multi-valued-property.xml
(added)
+++ sling/trunk/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/escaped-comma-in-multi-valued-property.xml
Tue Sep 29 13:02:33 2015
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
+ someProp="[first\,first,second]"/>
Modified: sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java?rev=1705853&r1=1705852&r2=1705853&view=diff
==============================================================================
--- sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java
(original)
+++ sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java
Tue Sep 29 13:02:33 2015
@@ -17,10 +17,12 @@
package org.apache.sling.ide.impl.vlt.serialization;
import java.math.BigDecimal;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Deque;
import java.util.EnumSet;
import java.util.LinkedList;
+import java.util.List;
import java.util.UUID;
import org.apache.jackrabbit.util.ISO8601;
@@ -233,7 +235,7 @@ public class ContentXmlHandler extends D
}
String rawValues = rawValue.substring(1, rawValue.length() - 1);
- values = rawValues.split(",");
+ values = splitValues(rawValues);
explicitMultiValue = true;
} else {
values = new String[] { rawValue };
@@ -259,6 +261,34 @@ public class ContentXmlHandler extends D
throw new IllegalArgumentException("Unknown typeHint value '" + rawHint + "'");
}
+ private static String[] splitValues(String rawValues) {
+
+ List<String> values = new ArrayList<String>();
+ String[] firstPass = rawValues.split(",");
+ for ( int i = 0 ; i < firstPass.length; i++) {
+
+ String val = firstPass[i];
+
+ boolean trailingSlash = val.endsWith("\\");
+ boolean moreEntries = i < firstPass.length;
+
+ // special case where the comma is escaped, so this means that
+ // two values should be joined
+ if ( trailingSlash && moreEntries ) {
+ // re-establish the value, e.g. first\,second becomes a single first,second
entry
+ values.add(val.substring(0, val.length() - 1) + "," + firstPass[i+1]);
+ // manually advance the iteration couter since we consumed the next entry
+ i++;
+ continue;
+ }
+
+ values.add(val);
+ }
+
+ return values.toArray(new String[values.size()]);
+
+ }
+
private static void unescape(String[] values) {
for (int i = 0; i < values.length; i++) {
|