Skip to content

Commit 6e3a1f7

Browse files
committed
[XMLBEANS-660] Add Locale enter and exit to XML Cursor attribute handling. Thanks to waa-ben. This closes #24
git-svn-id: https://svn.apache.org/repos/asf/xmlbeans/trunk@1928724 13f79535-47bb-0310-9956-ffa450edef68
1 parent 9eb296f commit 6e3a1f7

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/main/java/org/apache/xmlbeans/impl/store/Cur.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2923,10 +2923,12 @@ public void attr(QName name, String value) {
29232923
text(value, 0, value.length());
29242924
end();
29252925
if (isId) {
2926+
_locale.enter();
29262927
Cur c1 = x.tempCur();
29272928
c1.toRoot();
29282929
Xobj doc = c1._xobj;
29292930
c1.release();
2931+
_locale.exit();
29302932
if (doc instanceof DocumentXobj) {
29312933
((DocumentXobj) doc).addIdElement(value,
29322934
x._parent.getDom());
@@ -3425,4 +3427,4 @@ void setId(String id) {
34253427
public Locale getLocale() {
34263428
return _locale;
34273429
}
3428-
}
3430+
}

src/test/java/xmlcursor/checkin/StoreTests.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.apache.xmlbeans.*;
1919
import org.apache.xmlbeans.XmlCursor.TokenType;
2020
import org.apache.xmlbeans.XmlCursor.XmlBookmark;
21+
import org.apache.xmlbeans.impl.store.Locale;
2122
import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
2223
import org.junit.jupiter.api.Assertions;
2324
import org.junit.jupiter.api.Disabled;
@@ -26,6 +27,7 @@
2627
import org.junit.jupiter.params.provider.ValueSource;
2728
import org.xml.sax.*;
2829
import org.xml.sax.ext.LexicalHandler;
30+
import org.xml.sax.helpers.AttributesImpl;
2931
import xmlcursor.common.Common;
3032

3133
import javax.xml.namespace.QName;
@@ -1950,6 +1952,38 @@ void testSaxParser() throws Exception {
19501952
assertEquals(x1.xmlText(), x2.xmlText());
19511953
}
19521954

1955+
@Test
1956+
void testSaxHandlerIdDetection() throws SAXException{
1957+
final XmlOptions emptyXmlOptions = new XmlOptions();
1958+
final String schemaUri = "http://example.com/schema";
1959+
1960+
final Locale loc = Locale.getLocale(null, null);
1961+
final AttributesImpl attrs = new AttributesImpl();
1962+
1963+
// The QName must be "id" as that's now enough for an attribute to be treated as an ID
1964+
attrs.addAttribute(
1965+
schemaUri,
1966+
"localIgnored",
1967+
"id",
1968+
"CDATA",
1969+
"anId"
1970+
);
1971+
1972+
loc.getSchemaTypeLoader().newXmlSaxHandler(null, emptyXmlOptions);
1973+
ContentHandler xmlSaxHandler = Locale.newSaxHandler(
1974+
loc.getSchemaTypeLoader(),
1975+
null,
1976+
emptyXmlOptions
1977+
).getContentHandler();
1978+
1979+
xmlSaxHandler.startElement(
1980+
schemaUri,
1981+
"localIgnored",
1982+
"sa:someName",
1983+
attrs
1984+
);
1985+
}
1986+
19531987
@Test
19541988
void testAdditionalNamespaces() throws Exception {
19551989
String xml = "<a xmlns:a='aNS'><a:b/></a>";

0 commit comments

Comments
 (0)