下面列出了org.xml.sax.Attributes#getIndex ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* SAX2: Receive notification of the beginning of an element.
*/
public void startElement(String uri, String localName,
String qname, Attributes attributes)
throws SAXException
{
super.startElement(uri, localName, qname, attributes);
handleTextEscaping();
if (m_wsfilter != null) {
// Look for any xml:space attributes
// Depending on the implementation of attributes, this
// might be faster than looping through all attributes. ILENE
final int index = attributes.getIndex(XMLSPACE_STRING);
if (index >= 0) {
xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
}
}
}
/**
* SAX2: Receive notification of the beginning of an element.
*/
public void startElement(String uri, String localName,
String qname, Attributes attributes)
throws SAXException
{
super.startElement(uri, localName, qname, attributes);
handleTextEscaping();
if (m_wsfilter != null) {
// Look for any xml:space attributes
// Depending on the implementation of attributes, this
// might be faster than looping through all attributes. ILENE
final int index = attributes.getIndex(XMLSPACE_STRING);
if (index >= 0) {
xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
}
}
}
/**
* SAX2: Receive notification of the beginning of an element.
*/
public void startElement(String uri, String localName,
String qname, Attributes attributes)
throws SAXException
{
super.startElement(uri, localName, qname, attributes);
handleTextEscaping();
if (m_wsfilter != null) {
// Look for any xml:space attributes
// Depending on the implementation of attributes, this
// might be faster than looping through all attributes. ILENE
final int index = attributes.getIndex(XMLSPACE_STRING);
if (index >= 0) {
xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
}
}
}
/**
* SAX2: Receive notification of the beginning of an element.
*/
public void startElement(String uri, String localName,
String qname, Attributes attributes)
throws SAXException
{
super.startElement(uri, localName, qname, attributes);
handleTextEscaping();
if (m_wsfilter != null) {
// Look for any xml:space attributes
// Depending on the implementation of attributes, this
// might be faster than looping through all attributes. ILENE
final int index = attributes.getIndex(XMLSPACE_STRING);
if (index >= 0) {
xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
}
}
}
/**
* SAX2: Receive notification of the beginning of an element.
*/
public void startElement(String uri, String localName,
String qname, Attributes attributes)
throws SAXException
{
super.startElement(uri, localName, qname, attributes);
handleTextEscaping();
if (m_wsfilter != null) {
// Look for any xml:space attributes
// Depending on the implementation of attributes, this
// might be faster than looping through all attributes. ILENE
final int index = attributes.getIndex(XMLSPACE_STRING);
if (index >= 0) {
xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
}
}
}
/**
* SAX2: Receive notification of the beginning of an element.
*/
public void startElement(String uri, String localName,
String qname, Attributes attributes)
throws SAXException
{
super.startElement(uri, localName, qname, attributes);
handleTextEscaping();
if (m_wsfilter != null) {
// Look for any xml:space attributes
// Depending on the implementation of attributes, this
// might be faster than looping through all attributes. ILENE
final int index = attributes.getIndex(XMLSPACE_STRING);
if (index >= 0) {
xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
}
}
}
/**
* SAX2: Receive notification of the beginning of an element.
*/
public void startElement(String uri, String localName,
String qname, Attributes attributes)
throws SAXException
{
super.startElement(uri, localName, qname, attributes);
handleTextEscaping();
if (m_wsfilter != null) {
// Look for any xml:space attributes
// Depending on the implementation of attributes, this
// might be faster than looping through all attributes. ILENE
final int index = attributes.getIndex(XMLSPACE_STRING);
if (index >= 0) {
xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
}
}
}
/**
* SAX2: Receive notification of the beginning of an element.
*/
public void startElement(String uri, String localName,
String qname, Attributes attributes)
throws SAXException
{
super.startElement(uri, localName, qname, attributes);
handleTextEscaping();
if (m_wsfilter != null) {
// Look for any xml:space attributes
// Depending on the implementation of attributes, this
// might be faster than looping through all attributes. ILENE
final int index = attributes.getIndex(XMLSPACE_STRING);
if (index >= 0) {
xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
}
}
}
/**
* SAX2: Receive notification of the beginning of an element.
*/
public void startElement(String uri, String localName,
String qname, Attributes attributes)
throws SAXException
{
super.startElement(uri, localName, qname, attributes);
handleTextEscaping();
if (m_wsfilter != null) {
// Look for any xml:space attributes
// Depending on the implementation of attributes, this
// might be faster than looping through all attributes. ILENE
final int index = attributes.getIndex(XMLSPACE_STRING);
if (index >= 0) {
xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
}
}
}
/**
* SAX2: Receive notification of the beginning of an element.
*/
public void startElement(String uri, String localName,
String qname, Attributes attributes)
throws SAXException
{
super.startElement(uri, localName, qname, attributes);
handleTextEscaping();
if (m_wsfilter != null) {
// Look for any xml:space attributes
// Depending on the implementation of attributes, this
// might be faster than looping through all attributes. ILENE
final int index = attributes.getIndex(XMLSPACE_STRING);
if (index >= 0) {
xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
}
}
}
@Test
public void test() throws Exception {
XMLReader xmlReader = createXMLReader();
final ValidatorHandler validatorHandler = createValidatorHandler(XSD);
xmlReader.setContentHandler(validatorHandler);
DefaultHandler handler = new DefaultHandler() {
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (!"ns:test".equals(qName)) {
return;
}
TypeInfoProvider infoProvider = validatorHandler.getTypeInfoProvider();
if (infoProvider == null) {
throw new SAXException("Can't obtain TypeInfoProvider object.");
}
int index = attributes.getIndex("id");
if (index == -1) {
throw new SAXException("The attribute 'id' is not in the list.");
}
Assert.assertTrue(infoProvider.isSpecified(index));
index = attributes.getIndex("date");
if (index == -1) {
throw new SAXException("The attribute 'date' is not in the list.");
}
Assert.assertFalse(infoProvider.isSpecified(index));
System.out.println("OK");
}
};
validatorHandler.setContentHandler(handler);
parse(xmlReader, XML);
}
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
TypeInfoProvider typeInfoProvider = validatorHandler.getTypeInfoProvider();
int index = atts.getIndex("orderid");
if (index != -1) {
System.out.println(" Index " + index);
System.out.println(" ElementType " + typeInfoProvider.getElementTypeInfo().getTypeName());
assertEquals(typeInfoProvider.getAttributeTypeInfo(index).getTypeName(), "string");
assertTrue(typeInfoProvider.isSpecified(index));
assertFalse(typeInfoProvider.isIdAttribute(index));
}
}
static JaxBeanInfo parseXsiType(UnmarshallingContext.State state, TagName ea, @Nullable JaxBeanInfo defaultBeanInfo) throws SAXException {
UnmarshallingContext context = state.getContext();
JaxBeanInfo beanInfo = null;
// look for @xsi:type
Attributes atts = ea.atts;
int idx = atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"type");
if(idx>=0) {
// we'll consume the value only when it's a recognized value,
// so don't consume it just yet.
String value = atts.getValue(idx);
QName type = DatatypeConverterImpl._parseQName(value,context);
if(type==null) {
reportError(Messages.NOT_A_QNAME.format(value),true);
} else {
if(defaultBeanInfo!=null && defaultBeanInfo.getTypeNames().contains(type))
// if this xsi:type is something that the default type can already handle,
// let it do so. This is added as a work around to bug https://jax-ws.dev.java.net/issues/show_bug.cgi?id=195
// where a redundant xsi:type="xs:dateTime" causes JAXB to unmarshal XMLGregorianCalendar,
// where Date is expected.
// this is not a complete fix, as we still won't be able to handle simple type substitution in general,
// but none-the-less
return defaultBeanInfo;
beanInfo = context.getJAXBContext().getGlobalType(type);
if(beanInfo==null) { // let's report an error
if (context.parent.hasEventHandler() // is somebody listening?
&& context.shouldErrorBeReported()) { // should we report error?
String nearest = context.getJAXBContext().getNearestTypeName(type);
if(nearest!=null)
reportError(Messages.UNRECOGNIZED_TYPE_NAME_MAYBE.format(type,nearest),true);
else
reportError(Messages.UNRECOGNIZED_TYPE_NAME.format(type),true);
}
}
// TODO: resurrect the following check
// else
// if(!target.isAssignableFrom(actual)) {
// reportError(context,
// Messages.UNSUBSTITUTABLE_TYPE.format(value,actual.getName(),target.getName()),
// true);
// actual = targetBeanInfo; // ditto
// }
}
}
return beanInfo;
}
static JaxBeanInfo parseXsiType(UnmarshallingContext.State state, TagName ea, @Nullable JaxBeanInfo defaultBeanInfo) throws SAXException {
UnmarshallingContext context = state.getContext();
JaxBeanInfo beanInfo = null;
// look for @xsi:type
Attributes atts = ea.atts;
int idx = atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"type");
if(idx>=0) {
// we'll consume the value only when it's a recognized value,
// so don't consume it just yet.
String value = atts.getValue(idx);
QName type = DatatypeConverterImpl._parseQName(value,context);
if(type==null) {
reportError(Messages.NOT_A_QNAME.format(value),true);
} else {
if(defaultBeanInfo!=null && defaultBeanInfo.getTypeNames().contains(type))
// if this xsi:type is something that the default type can already handle,
// let it do so. This is added as a work around to bug https://jax-ws.dev.java.net/issues/show_bug.cgi?id=195
// where a redundant xsi:type="xs:dateTime" causes JAXB to unmarshal XMLGregorianCalendar,
// where Date is expected.
// this is not a complete fix, as we still won't be able to handle simple type substitution in general,
// but none-the-less
return defaultBeanInfo;
beanInfo = context.getJAXBContext().getGlobalType(type);
if(beanInfo==null) { // let's report an error
if (context.parent.hasEventHandler() // is somebody listening?
&& context.shouldErrorBeReported()) { // should we report error?
String nearest = context.getJAXBContext().getNearestTypeName(type);
if(nearest!=null)
reportError(Messages.UNRECOGNIZED_TYPE_NAME_MAYBE.format(type,nearest),true);
else
reportError(Messages.UNRECOGNIZED_TYPE_NAME.format(type),true);
}
}
// TODO: resurrect the following check
// else
// if(!target.isAssignableFrom(actual)) {
// reportError(context,
// Messages.UNSUBSTITUTABLE_TYPE.format(value,actual.getName(),target.getName()),
// true);
// actual = targetBeanInfo; // ditto
// }
}
}
return beanInfo;
}
static JaxBeanInfo parseXsiType(UnmarshallingContext.State state, TagName ea, @Nullable JaxBeanInfo defaultBeanInfo) throws SAXException {
UnmarshallingContext context = state.getContext();
JaxBeanInfo beanInfo = null;
// look for @xsi:type
Attributes atts = ea.atts;
int idx = atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"type");
if(idx>=0) {
// we'll consume the value only when it's a recognized value,
// so don't consume it just yet.
String value = atts.getValue(idx);
QName type = DatatypeConverterImpl._parseQName(value,context);
if(type==null) {
reportError(Messages.NOT_A_QNAME.format(value),true);
} else {
if(defaultBeanInfo!=null && defaultBeanInfo.getTypeNames().contains(type))
// if this xsi:type is something that the default type can already handle,
// let it do so. This is added as a work around to bug https://jax-ws.dev.java.net/issues/show_bug.cgi?id=195
// where a redundant xsi:type="xs:dateTime" causes JAXB to unmarshal XMLGregorianCalendar,
// where Date is expected.
// this is not a complete fix, as we still won't be able to handle simple type substitution in general,
// but none-the-less
return defaultBeanInfo;
beanInfo = context.getJAXBContext().getGlobalType(type);
if(beanInfo==null) { // let's report an error
if (context.parent.hasEventHandler() // is somebody listening?
&& context.shouldErrorBeReported()) { // should we report error?
String nearest = context.getJAXBContext().getNearestTypeName(type);
if(nearest!=null)
reportError(Messages.UNRECOGNIZED_TYPE_NAME_MAYBE.format(type,nearest),true);
else
reportError(Messages.UNRECOGNIZED_TYPE_NAME.format(type),true);
}
}
// TODO: resurrect the following check
// else
// if(!target.isAssignableFrom(actual)) {
// reportError(context,
// Messages.UNSUBSTITUTABLE_TYPE.format(value,actual.getName(),target.getName()),
// true);
// actual = targetBeanInfo; // ditto
// }
}
}
return beanInfo;
}
static JaxBeanInfo parseXsiType(UnmarshallingContext.State state, TagName ea, @Nullable JaxBeanInfo defaultBeanInfo) throws SAXException {
UnmarshallingContext context = state.getContext();
JaxBeanInfo beanInfo = null;
// look for @xsi:type
Attributes atts = ea.atts;
int idx = atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"type");
if(idx>=0) {
// we'll consume the value only when it's a recognized value,
// so don't consume it just yet.
String value = atts.getValue(idx);
QName type = DatatypeConverterImpl._parseQName(value,context);
if(type==null) {
reportError(Messages.NOT_A_QNAME.format(value),true);
} else {
if(defaultBeanInfo!=null && defaultBeanInfo.getTypeNames().contains(type))
// if this xsi:type is something that the default type can already handle,
// let it do so. This is added as a work around to bug https://jax-ws.dev.java.net/issues/show_bug.cgi?id=195
// where a redundant xsi:type="xs:dateTime" causes JAXB to unmarshal XMLGregorianCalendar,
// where Date is expected.
// this is not a complete fix, as we still won't be able to handle simple type substitution in general,
// but none-the-less
return defaultBeanInfo;
beanInfo = context.getJAXBContext().getGlobalType(type);
if(beanInfo==null) { // let's report an error
if (context.parent.hasEventHandler() // is somebody listening?
&& context.shouldErrorBeReported()) { // should we report error?
String nearest = context.getJAXBContext().getNearestTypeName(type);
if(nearest!=null)
reportError(Messages.UNRECOGNIZED_TYPE_NAME_MAYBE.format(type,nearest),true);
else
reportError(Messages.UNRECOGNIZED_TYPE_NAME.format(type),true);
}
}
// TODO: resurrect the following check
// else
// if(!target.isAssignableFrom(actual)) {
// reportError(context,
// Messages.UNSUBSTITUTABLE_TYPE.format(value,actual.getName(),target.getName()),
// true);
// actual = targetBeanInfo; // ditto
// }
}
}
return beanInfo;
}
static JaxBeanInfo parseXsiType(UnmarshallingContext.State state, TagName ea, @Nullable JaxBeanInfo defaultBeanInfo) throws SAXException {
UnmarshallingContext context = state.getContext();
JaxBeanInfo beanInfo = null;
// look for @xsi:type
Attributes atts = ea.atts;
int idx = atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"type");
if(idx>=0) {
// we'll consume the value only when it's a recognized value,
// so don't consume it just yet.
String value = atts.getValue(idx);
QName type = DatatypeConverterImpl._parseQName(value,context);
if(type==null) {
reportError(Messages.NOT_A_QNAME.format(value),true);
} else {
if(defaultBeanInfo!=null && defaultBeanInfo.getTypeNames().contains(type))
// if this xsi:type is something that the default type can already handle,
// let it do so. This is added as a work around to bug https://jax-ws.dev.java.net/issues/show_bug.cgi?id=195
// where a redundant xsi:type="xs:dateTime" causes JAXB to unmarshal XMLGregorianCalendar,
// where Date is expected.
// this is not a complete fix, as we still won't be able to handle simple type substitution in general,
// but none-the-less
return defaultBeanInfo;
beanInfo = context.getJAXBContext().getGlobalType(type);
if(beanInfo==null) { // let's report an error
if (context.parent.hasEventHandler() // is somebody listening?
&& context.shouldErrorBeReported()) { // should we report error?
String nearest = context.getJAXBContext().getNearestTypeName(type);
if(nearest!=null)
reportError(Messages.UNRECOGNIZED_TYPE_NAME_MAYBE.format(type,nearest),true);
else
reportError(Messages.UNRECOGNIZED_TYPE_NAME.format(type),true);
}
}
// TODO: resurrect the following check
// else
// if(!target.isAssignableFrom(actual)) {
// reportError(context,
// Messages.UNSUBSTITUTABLE_TYPE.format(value,actual.getName(),target.getName()),
// true);
// actual = targetBeanInfo; // ditto
// }
}
}
return beanInfo;
}
static JaxBeanInfo parseXsiType(UnmarshallingContext.State state, TagName ea, @Nullable JaxBeanInfo defaultBeanInfo) throws SAXException {
UnmarshallingContext context = state.getContext();
JaxBeanInfo beanInfo = null;
// look for @xsi:type
Attributes atts = ea.atts;
int idx = atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"type");
if(idx>=0) {
// we'll consume the value only when it's a recognized value,
// so don't consume it just yet.
String value = atts.getValue(idx);
QName type = DatatypeConverterImpl._parseQName(value,context);
if(type==null) {
reportError(Messages.NOT_A_QNAME.format(value),true);
} else {
if(defaultBeanInfo!=null && defaultBeanInfo.getTypeNames().contains(type))
// if this xsi:type is something that the default type can already handle,
// let it do so. This is added as a work around to bug https://jax-ws.dev.java.net/issues/show_bug.cgi?id=195
// where a redundant xsi:type="xs:dateTime" causes JAXB to unmarshal XMLGregorianCalendar,
// where Date is expected.
// this is not a complete fix, as we still won't be able to handle simple type substitution in general,
// but none-the-less
return defaultBeanInfo;
beanInfo = context.getJAXBContext().getGlobalType(type);
if(beanInfo==null) { // let's report an error
if (context.parent.hasEventHandler() // is somebody listening?
&& context.shouldErrorBeReported()) { // should we report error?
String nearest = context.getJAXBContext().getNearestTypeName(type);
if(nearest!=null)
reportError(Messages.UNRECOGNIZED_TYPE_NAME_MAYBE.format(type,nearest),true);
else
reportError(Messages.UNRECOGNIZED_TYPE_NAME.format(type),true);
}
}
// TODO: resurrect the following check
// else
// if(!target.isAssignableFrom(actual)) {
// reportError(context,
// Messages.UNSUBSTITUTABLE_TYPE.format(value,actual.getName(),target.getName()),
// true);
// actual = targetBeanInfo; // ditto
// }
}
}
return beanInfo;
}
static JaxBeanInfo parseXsiType(UnmarshallingContext.State state, TagName ea, @Nullable JaxBeanInfo defaultBeanInfo) throws SAXException {
UnmarshallingContext context = state.getContext();
JaxBeanInfo beanInfo = null;
// look for @xsi:type
Attributes atts = ea.atts;
int idx = atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"type");
if(idx>=0) {
// we'll consume the value only when it's a recognized value,
// so don't consume it just yet.
String value = atts.getValue(idx);
QName type = DatatypeConverterImpl._parseQName(value,context);
if(type==null) {
reportError(Messages.NOT_A_QNAME.format(value),true);
} else {
if(defaultBeanInfo!=null && defaultBeanInfo.getTypeNames().contains(type))
// if this xsi:type is something that the default type can already handle,
// let it do so. This is added as a work around to bug https://jax-ws.dev.java.net/issues/show_bug.cgi?id=195
// where a redundant xsi:type="xs:dateTime" causes JAXB to unmarshal XMLGregorianCalendar,
// where Date is expected.
// this is not a complete fix, as we still won't be able to handle simple type substitution in general,
// but none-the-less
return defaultBeanInfo;
beanInfo = context.getJAXBContext().getGlobalType(type);
if(beanInfo==null) { // let's report an error
if (context.parent.hasEventHandler() // is somebody listening?
&& context.shouldErrorBeReported()) { // should we report error?
String nearest = context.getJAXBContext().getNearestTypeName(type);
if(nearest!=null)
reportError(Messages.UNRECOGNIZED_TYPE_NAME_MAYBE.format(type,nearest),true);
else
reportError(Messages.UNRECOGNIZED_TYPE_NAME.format(type),true);
}
}
// TODO: resurrect the following check
// else
// if(!target.isAssignableFrom(actual)) {
// reportError(context,
// Messages.UNSUBSTITUTABLE_TYPE.format(value,actual.getName(),target.getName()),
// true);
// actual = targetBeanInfo; // ditto
// }
}
}
return beanInfo;
}
static JaxBeanInfo parseXsiType(UnmarshallingContext.State state, TagName ea, @Nullable JaxBeanInfo defaultBeanInfo) throws SAXException {
UnmarshallingContext context = state.getContext();
JaxBeanInfo beanInfo = null;
// look for @xsi:type
Attributes atts = ea.atts;
int idx = atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"type");
if(idx>=0) {
// we'll consume the value only when it's a recognized value,
// so don't consume it just yet.
String value = atts.getValue(idx);
QName type = DatatypeConverterImpl._parseQName(value,context);
if(type==null) {
reportError(Messages.NOT_A_QNAME.format(value),true);
} else {
if(defaultBeanInfo!=null && defaultBeanInfo.getTypeNames().contains(type))
// if this xsi:type is something that the default type can already handle,
// let it do so. This is added as a work around to bug https://jax-ws.dev.java.net/issues/show_bug.cgi?id=195
// where a redundant xsi:type="xs:dateTime" causes JAXB to unmarshal XMLGregorianCalendar,
// where Date is expected.
// this is not a complete fix, as we still won't be able to handle simple type substitution in general,
// but none-the-less
return defaultBeanInfo;
beanInfo = context.getJAXBContext().getGlobalType(type);
if(beanInfo==null) { // let's report an error
if (context.parent.hasEventHandler() // is somebody listening?
&& context.shouldErrorBeReported()) { // should we report error?
String nearest = context.getJAXBContext().getNearestTypeName(type);
if(nearest!=null)
reportError(Messages.UNRECOGNIZED_TYPE_NAME_MAYBE.format(type,nearest),true);
else
reportError(Messages.UNRECOGNIZED_TYPE_NAME.format(type),true);
}
}
// TODO: resurrect the following check
// else
// if(!target.isAssignableFrom(actual)) {
// reportError(context,
// Messages.UNSUBSTITUTABLE_TYPE.format(value,actual.getName(),target.getName()),
// true);
// actual = targetBeanInfo; // ditto
// }
}
}
return beanInfo;
}