You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by na...@apache.org on 2007/07/25 04:14:15 UTC
svn commit: r559282 -
/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java
Author: natalia
Date: Tue Jul 24 19:14:15 2007
New Revision: 559282
URL: http://svn.apache.org/viewvc?view=rev&rev=559282
Log:
Fixes for nested content and empty elements
Modified:
xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java?view=diff&rev=559282&r1=559281&r2=559282
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java Tue Jul 24 19:14:15 2007
@@ -588,19 +588,17 @@
}
public void endElement(String namespaceURI, String localName, String qName) {
- if (info.sb != null) {
- processEntry(new IndexPattern(symbols, info.symbolID), info.sb.toString(), info.pos, info.len);
- }
+ StringBuffer sb = info.sb;
+ processEntry(new IndexPattern(symbols, info.symbolID), sb.toString(), info.pos, info.len);
+
info = (StackInfo) stack.pop();
+ if (info != null) {
+ info.sb.append(sb);
+ }
}
public void characters(char ch[], int start, int length) {
- String val = new String(ch).trim();
- if (info.sb == null) {
- info.sb = new StringBuffer(ch.length);
- } else if (info.sb.length() > 0) {
- info.sb.append(' ');
- }
+ String val = new String(ch);
info.sb.append(val);
}
@@ -622,7 +620,7 @@
*/
private class StackInfo {
public short symbolID;
- public StringBuffer sb = null;
+ public StringBuffer sb = new StringBuffer();
public int pos = -1;
public int len = -1;
Re: svn commit: r559282 - /xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java
Posted by Natalia Shilenkova <ns...@gmail.com>.
On 7/26/07, Vadim Gritsenko <va...@reverycodes.com> wrote:
> natalia@apache.org wrote:
> > public void characters(char ch[], int start, int length) {
> > - String val = new String(ch).trim();
> ...
> > + String val = new String(ch);
> > info.sb.append(val);
>
> Now, after I had a look at this piece, I realized that it was wrong then and it
> is still wrong now :)
Damn :)
> String must be constructed only from the relevant part of the character buffer:
>
> String val = new String(ch, start, length);
>
> Otherwise it can contain junk / extra data. It is a pure coincidence that it
> worked at all. :)
>
> Even better would be to forgo string construction completely and use append method:
>
> info.sb.append(ch, start, length);
>
> This would save one extra characters copying.
Thanks for spotting the problem.
Natalia
Re: svn commit: r559282 - /xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java
Posted by Vadim Gritsenko <va...@reverycodes.com>.
natalia@apache.org wrote:
> public void characters(char ch[], int start, int length) {
> - String val = new String(ch).trim();
...
> + String val = new String(ch);
> info.sb.append(val);
Now, after I had a look at this piece, I realized that it was wrong then and it
is still wrong now :)
String must be constructed only from the relevant part of the character buffer:
String val = new String(ch, start, length);
Otherwise it can contain junk / extra data. It is a pure coincidence that it
worked at all. :)
Even better would be to forgo string construction completely and use append method:
info.sb.append(ch, start, length);
This would save one extra characters copying.
Vadim