jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r454276 - in /jackrabbit/trunk/textfilters/src: java/org/apache/jackrabbit/core/query/XMLTextFilter.java test/org/apache/jackrabbit/core/query/test/XMLTextFilterTest.java
Date Mon, 09 Oct 2006 04:13:19 GMT
Author: jukka
Date: Sun Oct  8 21:13:18 2006
New Revision: 454276

URL: http://svn.apache.org/viewvc?view=rev&rev=454276
Log:
JCR-587: Applied the XML text filtering fix and test case contributed by Magnus Grimsell.

Added:
    jackrabbit/trunk/textfilters/src/test/org/apache/jackrabbit/core/query/test/XMLTextFilterTest.java
  (with props)
Modified:
    jackrabbit/trunk/textfilters/src/java/org/apache/jackrabbit/core/query/XMLTextFilter.java

Modified: jackrabbit/trunk/textfilters/src/java/org/apache/jackrabbit/core/query/XMLTextFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/textfilters/src/java/org/apache/jackrabbit/core/query/XMLTextFilter.java?view=diff&rev=454276&r1=454275&r2=454276
==============================================================================
--- jackrabbit/trunk/textfilters/src/java/org/apache/jackrabbit/core/query/XMLTextFilter.java
(original)
+++ jackrabbit/trunk/textfilters/src/java/org/apache/jackrabbit/core/query/XMLTextFilter.java
Sun Oct  8 21:13:18 2006
@@ -133,7 +133,7 @@
 
         public void characters(char[] ch, int start, int length) {
             boolean space = false;
-            for (int i = start; i < length; i++) {
+            for (int i = start; i < start + length; i++) {
                 if (Character.isLetterOrDigit(ch[i])) {
                     if (space) {
                         buffer.append(' ');

Added: jackrabbit/trunk/textfilters/src/test/org/apache/jackrabbit/core/query/test/XMLTextFilterTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/textfilters/src/test/org/apache/jackrabbit/core/query/test/XMLTextFilterTest.java?view=auto&rev=454276
==============================================================================
--- jackrabbit/trunk/textfilters/src/test/org/apache/jackrabbit/core/query/test/XMLTextFilterTest.java
(added)
+++ jackrabbit/trunk/textfilters/src/test/org/apache/jackrabbit/core/query/test/XMLTextFilterTest.java
Sun Oct  8 21:13:18 2006
@@ -0,0 +1,79 @@
+/*
+ * 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.jackrabbit.core.query.test;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.PropertyId;
+import org.apache.jackrabbit.core.query.TextFilter;
+import org.apache.jackrabbit.core.query.XMLTextFilter;
+import org.apache.jackrabbit.core.query.lucene.FieldNames;
+import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.uuid.UUID;
+
+public class XMLTextFilterTest extends TestCase {
+
+    public void testCanExtractAttributes() throws Exception {
+        String xml = "<config><city name=\"Stockholm\"/></config>";
+        PropertyId id = new PropertyId(new NodeId(new UUID(1, 1)), new QName("", ""));
+        PropertyState state = new PropertyState(id, 1, true);
+
+        InternalValue value = InternalValue.create(xml.getBytes());
+        state.setValues(new InternalValue[]{value});
+
+        TextFilter filter = new XMLTextFilter();
+        Map fields = filter.doFilter(state, System.getProperty("encoding"));
+        Reader reader = (Reader)fields.get(FieldNames.FULLTEXT);
+        String result = getValue(reader);
+        assertEquals("Stockholm", result.trim());
+    }
+
+    public void testCanExtractCData() throws Exception {
+        String xml = "<config><city>Stockholm</city></config>";
+        PropertyId id = new PropertyId(new NodeId(new UUID(1, 1)), new QName("", ""));
+        PropertyState state = new PropertyState(id, 1, true);
+
+        InternalValue value = InternalValue.create(xml.getBytes());
+        state.setValues(new InternalValue[]{value});
+
+        TextFilter filter = new XMLTextFilter();
+        Map fields = filter.doFilter(state, System.getProperty("encoding"));
+        Reader reader = (Reader)fields.get(FieldNames.FULLTEXT);
+        String result = getValue(reader);
+        assertEquals("Stockholm", result.trim());
+    }
+
+    public String getValue(Reader r) throws IOException {
+        StringWriter w = new StringWriter();
+        char[] buf = new char[1000];
+        int length = 0;
+        while ((length = r.read(buf)) != -1) {
+            w.write(buf, 0, length);
+        }
+
+        String result = w.getBuffer().toString();
+        return result;
+    }
+}

Propchange: jackrabbit/trunk/textfilters/src/test/org/apache/jackrabbit/core/query/test/XMLTextFilterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message