当前位置: 首页>>代码示例>>Java>>正文


Java Attributes.getIndex方法代码示例

本文整理汇总了Java中org.xml.sax.Attributes.getIndex方法的典型用法代码示例。如果您正苦于以下问题:Java Attributes.getIndex方法的具体用法?Java Attributes.getIndex怎么用?Java Attributes.getIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.xml.sax.Attributes的用法示例。


在下文中一共展示了Attributes.getIndex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startElement

import org.xml.sax.Attributes; //导入方法依赖的package包/类
/**
 * 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());
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:SAXImpl.java

示例2: test

import org.xml.sax.Attributes; //导入方法依赖的package包/类
@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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:Bug4970951.java

示例3: startElement

import org.xml.sax.Attributes; //导入方法依赖的package包/类
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));
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:TypeInfoProviderTest.java

示例4: startElement

import org.xml.sax.Attributes; //导入方法依赖的package包/类
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    super.startElement(uri, localName, qName, attrs);

    // read metaInfo
    if (attrs != null && attrs.getIndex(ENTITY_ATTR_ID) >= 0) {

        this.osmId = Long.valueOf(attrs.getValue(ENTITY_ATTR_ID));

        String inVersion = attrs.getValue(ENTITY_ATTR_VERSION);
        final int version = Integer.valueOf(inVersion == null ? "0" : inVersion);

        String inChangesetId = attrs.getValue(ENTITY_ATTR_CHANGESET);
        final int changesetId = Integer.valueOf(inChangesetId == null ? "0" : inChangesetId);

        final String timestamp = attrs.getValue(ENTITY_ATTR_TIMESTAMP);
        final String userName = attrs.getValue(ENTITY_ATTR_USER);

        String inUserId = attrs.getValue(ENTITY_ATTR_USERID);
        final int userId = Integer.valueOf(inUserId == null ? "0" : inUserId);

        this.metaInfo = OSM.metaInfo(version, changesetId, timestamp, userName, userId);
    }

    switch (qName) {
        case NODE_ELEMENT:
            this.latitude = Double.valueOf(attrs.getValue(NODE_ATTR_LAT));
            this.longitude = Double.valueOf(attrs.getValue(NODE_ATTR_LONG));
            break;

        case WAY_ELEMENT:
        case RELATION_ELEMENT:
            // Nothing to do here
            break;

        case TAG_ELEMENT:
            final String key = attrs.getValue(TAG_ATTR_KEY);
            if (!key.equalsIgnoreCase("created_by"))
                this.tagsMap.put(key, attrs.getValue(TAG_ATTR_VALUE));
            break;

        case WAY_ND_ELEMENT:
            final long refNodeId = Long.valueOf(attrs.getValue(WAY_ND_ATTR_REF));
            this.nodeIds.add(refNodeId);
            break;

        case MEMBER_ELEMENT:
            final long refId = Long.valueOf(attrs.getValue(MEMBER_ATTR_REF));
            final Type type = Type.valueOf(attrs.getValue(MEMBER_ATTR_TYPE).toLowerCase());
            final String role = attrs.getValue(MEMBER_ATTR_ROLE);

            this.members.add(OSM.member(type, refId, role));
            break;

        default:
            break;
    }


    LOGGER.debug("Element parsing started - qname: {}, meta: {}", qName, "");
}
 
开发者ID:millij,项目名称:osm-processor,代码行数:62,代码来源:OsmSaxHandler.java

示例5: parseXsiType

import org.xml.sax.Attributes; //导入方法依赖的package包/类
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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:50,代码来源:XsiTypeLoader.java


注:本文中的org.xml.sax.Attributes.getIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。