Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be able to point to the exact loctions of attributes #149

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main/java/com/ctc/wstx/sr/AttributeCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.codehaus.stax2.typed.TypedValueDecoder;
import org.codehaus.stax2.typed.TypedXMLStreamException;
import org.codehaus.stax2.validation.XMLValidator;
import org.codehaus.stax2.XMLStreamLocation2;

import com.ctc.wstx.api.ReaderConfig;
import com.ctc.wstx.cfg.ErrorConsts;
Expand Down Expand Up @@ -523,6 +524,14 @@ public final int getXmlIdAttrIndex() {
return mXmlIdAttrIndex;
}

public final XMLStreamLocation2 getValueLocationStart(int index) {
return mNamespaceBuilder.getLocation(index * 2);
}

public final XMLStreamLocation2 getValueLocationEnd(int index) {
return mNamespaceBuilder.getLocation(index * 2 + 1);
}

/*
//////////////////////////////////////////////////////
// Type-safe accessors to support TypedXMLStreamReader
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/ctc/wstx/sr/BasicStreamReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3150,7 +3150,10 @@ private final boolean handleNsAttrs(char c)
} else {
tb = ac.getAttrBuilder(prefix, localName);
}
tb.pushLocation(getCurrentLocation());
parseAttrValue(c, tb);
tb.pushLocation(getCurrentLocation());


/* 19-Jul-2004, TSa: Need to check that non-default namespace
* URI is NOT empty, as per XML namespace specs, #2,
Expand Down Expand Up @@ -3224,8 +3227,11 @@ private final boolean handleNonNsAttrs(char c)
}

// And then the actual value
tb.pushLocation(getCurrentLocation());
parseAttrValue(c, tb);
tb.pushLocation(getCurrentLocation());
// and then we need to iterate some more

c = (mInputPtr < mInputEnd) ?
mInputBuffer[mInputPtr++] : getNextCharFromCurrent(SUFFIX_IN_ELEMENT);
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/ctc/wstx/util/TextBuilder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.ctc.wstx.util;

import org.codehaus.stax2.XMLStreamLocation2;

import java.util.ArrayList;

/**
* Class similar to {@link StringBuilder}, except that it can be used to
* construct multiple Strings, that will share same underlying character
Expand All @@ -17,6 +21,8 @@ public final class TextBuilder

private String mResultString;

private ArrayList<XMLStreamLocation2> mLocations;

/*
///////////////////////////////////////////////////////////////////////
// Life-cycle:
Expand All @@ -32,6 +38,7 @@ public TextBuilder(int initialSize)
charSize = MAX_LEN;
}
mBuffer = new char[charSize];
mLocations = new ArrayList<XMLStreamLocation2>(initialSize << 1);
}

/**
Expand All @@ -40,6 +47,7 @@ public TextBuilder(int initialSize)
*/
public void reset() {
mBufferLen = 0;
mLocations.clear();
mResultString = null;
}

Expand All @@ -61,6 +69,9 @@ public String getAllValues()
return mResultString;
}

public void pushLocation(XMLStreamLocation2 location) {
mLocations.add(location);
}
/**
* Method that gives access to underlying character buffer
*/
Expand Down Expand Up @@ -131,4 +142,8 @@ private void resize(int needSpaceFor) {
mBuffer = new char[oldLen+addition];
System.arraycopy(old, 0, mBuffer, 0, mBufferLen);
}

public XMLStreamLocation2 getLocation(int index) {
return mLocations.get(index);
}
}