类javax.xml.stream.Location源码实例Demo

下面列出了怎么用javax.xml.stream.Location的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: woodstox   文件: StreamBootstrapper.java
@Override
protected Location getLocation()
{
    /* Ok; for fixed-size multi-byte encodings, need to divide numbers
     * to get character locations. For variable-length encodings the
     * good thing is that xml declaration only uses shortest codepoints,
     * ie. char count == byte count.
     */
    int total = mInputProcessed + mInputPtr;
    int col = mInputPtr - mInputRowStart;

    if (mBytesPerChar > 1) {
        total /= mBytesPerChar;
        col /= mBytesPerChar;
    }

    return new WstxInputLocation(null, mPublicId, mSystemId,
                                 total - 1, // 0-based
                                 mInputRow, col);
}
 
源代码2 项目: woodstox   文件: WstxSAXParser.java
@Override
public String getSystemId() {
    if (mScanner != null) {
        Location loc = mScanner.getLocation();
        return loc.getSystemId();
    }
    return null;
}
 
源代码3 项目: woodstox   文件: TestTreatCharRefAsEnts.java
public void testReturnEntityForCharReference() throws Exception
{
    
    String XML = "<root>text &amp; more</root>";
    
    BasicStreamReader sr = getReader(XML, true, true, 1);

    assertTokenType(START_ELEMENT, sr.next());
    assertEquals("root", sr.getLocalName());

    assertTokenType(CHARACTERS, sr.next());
    
    assertEquals("text ", sr.getText());
    
    assertTokenType(ENTITY_REFERENCE, sr.next());
    assertEquals("amp", sr.getLocalName());
    EntityDecl ed = sr.getCurrentEntityDecl();
    assertNotNull(ed);
    assertEquals("amp", ed.getName());
    assertEquals("&", ed.getReplacementText());

    // The pure stax way:
    assertEquals("&", sr.getText());

    // Finally, let's see that location info is about right?
    Location loc = sr.getCurrentLocation();
    assertNotNull(loc);
    assertEquals(16, loc.getCharacterOffset());
}
 
源代码4 项目: woodstox   文件: WstxSAXParser.java
@Override
public int getColumnNumber()
{
    if (mScanner != null) {
        Location loc = mScanner.getLocation();
        return loc.getColumnNumber();
    }
    return -1;
}
 
@SuppressWarnings("unchecked")
@Test
public void testReferenceMap() throws Exception {
    init();

   //helper.setMapFile( "deleteHelper/referenceExceptionMap.json" );

    ActionVerb action = ActionVerb.DELETE;
    RecordMetaImpl meta = new RecordMetaImpl("GradeReference", "GradeReference", false, action);
    Location loc = Mockito.mock(Location.class);
    Mockito.when(loc.getLineNumber()).thenReturn(1);
    Mockito.when(loc.getColumnNumber()).thenReturn(1);
    meta.setSourceStartLocation(loc);
    meta.setSourceEndLocation(loc);

    /*
     * building GradeReference
     */
    Map<String, Object> att = new HashMap<String, Object>();
    att.put("StudentReference",new HashMap<String, Object>());
    (( Map<String,Object>)att.get("StudentReference")).put( "StudentIdenity", new HashMap<String, Object>());
    (( Map<String,Object>)(( Map<String,Object>)att.get("StudentReference")).get("StudentIdenity")).
            put("StudentUniqueStateId", "G-800000025");

    att.put("SectionReference",new HashMap<String, Object>());
    (( Map<String,Object>)att.get("SectionReference")).put( "EducationalOrgIdentity", new HashMap<String, Object>());
    (( Map<String,Object>)(( Map<String,Object>)att.get("SectionReference")).get("EducationalOrgIdentity")).
            put("StateOrganizationId", "Daybreak Central High");


    att.put("SchoolYear", "2011-2012");
    Assert.assertFalse(att.containsKey("StudentSectionAssociationReference"));

    helper.mapAttributes(att, "GradeReference");
    Assert.assertTrue(att.containsKey("StudentSectionAssociationReference"));
    Assert.assertTrue(att.get("StudentSectionAssociationReference") instanceof Map );
    Assert.assertTrue( ((Map<String,Object>)att.get("StudentSectionAssociationReference")).
            containsKey("StudentSectionAssociationIdentity"));

}
 
源代码6 项目: cxf   文件: FailureLocation.java
public FailureLocation(Location loc, String docURI) {
    this.location = loc;
    this.documentURI = docURI;
    if (documentURI == null) {
        documentURI = loc.getSystemId();
    }
}
 
源代码7 项目: woodstox   文件: InputElementStack.java
/**
     * Method called to construct a non-transient NamespaceContext instance;
     * generally needed when creating events to return from event-based
     * iterators.
     */
    public BaseNsContext createNonTransientNsContext(Location loc)
    {
        // Have an instance we can reuse? Great!
        if (mLastNsContext != null) {
            return mLastNsContext;
        }

        // No namespaces declared at this point? Easy, as well:
        int totalNsSize = mNamespaces.size();
        if (totalNsSize < 1) {
            return (mLastNsContext = EmptyNamespaceContext.getInstance());
        }

        // Otherwise, we need to create a new non-empty context:
        int localCount = getCurrentNsCount() << 1;
        BaseNsContext nsCtxt = new CompactNsContext
            (loc, /*getDefaultNsURI(),*/
             mNamespaces.asArray(), totalNsSize,
             totalNsSize - localCount);
        /* And it can be shared if there are no new ('local', ie. included
         * within this start element) bindings -- if there are, underlying
         * array might be shareable, but offsets wouldn't be)
         */
        if (localCount == 0) {
            mLastNsContext = nsCtxt;
        }
        return nsCtxt;
}
 
private Locator getLocator(XMLStreamReader reader) {
    Location location = reader.getLocation();
        LocatorImpl loc = new LocatorImpl();
        loc.setSystemId(location.getSystemId());
        loc.setLineNumber(location.getLineNumber());
    return loc;
}
 
private static Locator toLocation(XMLStreamReader xsr) {
    LocatorImpl loc = new LocatorImpl();
    Location in = xsr.getLocation();
    loc.setSystemId(in.getSystemId());
    loc.setPublicId(in.getPublicId());
    loc.setLineNumber(in.getLineNumber());
    loc.setColumnNumber(in.getColumnNumber());
    return loc;
}
 
源代码10 项目: wildfly-core   文件: JBossAllXMLElementReader.java
@Override
public void readElement(final XMLExtendedStreamReader xmlExtendedStreamReader, final JBossAllXmlParseContext jBossXmlParseContext) throws XMLStreamException {
    final Location nsLocation = xmlExtendedStreamReader.getLocation();
    final QName elementName = xmlExtendedStreamReader.getName();
    final Object result = parserDescription.getParser().parse(xmlExtendedStreamReader, jBossXmlParseContext.getDeploymentUnit());
    jBossXmlParseContext.addResult(elementName, result, nsLocation);
}
 
源代码11 项目: openjdk-8-source   文件: StartDocumentEvent.java
protected void init(String encoding, String version, boolean standalone,Location loc) {
    setEventType(XMLStreamConstants.START_DOCUMENT);
    this.fEncodingScheam = encoding;
    this.fVersion = version;
    this.fStandalone = standalone;
    if (encoding != null && !encoding.equals(""))
        this.fEncodingSchemeSet = true;
    else {
        this.fEncodingSchemeSet = false;
        this.fEncodingScheam = "UTF-8";
    }
    this.fLocation = loc;
}
 
源代码12 项目: openjdk-8   文件: WSDLParserExtensionFacade.java
private Locator getLocator(XMLStreamReader reader) {
    Location location = reader.getLocation();
        LocatorImpl loc = new LocatorImpl();
        loc.setSystemId(location.getSystemId());
        loc.setLineNumber(location.getLineNumber());
    return loc;
}
 
源代码13 项目: woodstox   文件: CompactNsContext.java
public CompactNsContext(Location loc,
                        String[] namespaces, int nsLen,
                        int firstLocal)
{
    mLocation = loc;
    mNamespaces = namespaces;
    mNsLength = nsLen;
    mFirstLocalNs = firstLocal;
}
 
源代码14 项目: jdk8u60   文件: DummyEvent.java
void setLocation(Location loc){
    if (loc == null) {
        fLocation = nowhere;
    } else {
        fLocation = loc;
    }
}
 
源代码15 项目: JDKSourceCode1.8   文件: SAX2StAXBaseWriter.java
public Location getCurrentLocation() {
        if (docLocator != null) {
                return new SAXLocation(docLocator);
        } else {
                return null;
        }

}
 
@Test
public void testIncorrectDeployments() throws Exception {
    try { createKernelServicesBuilder(TestModelType.STANDALONE)
        .setXmlResource("standalone_duplicate.xml")
        .createContentRepositoryContent("12345678901234567890")
        .build();
    } catch (XMLStreamException ex) {
        String expectedMessage = ControllerLogger.ROOT_LOGGER.duplicateNamedElement("abc.war", new Location() {
            public int getLineNumber() {
                return 287;
            }

            public int getColumnNumber() {
                return 1;
            }

            public int getCharacterOffset() {
                return 1;
            }

            public String getPublicId() {
                return "";
            }

            public String getSystemId() {
                return "";
            }
        }).getMessage();
        expectedMessage = expectedMessage.substring(expectedMessage.indexOf("WFLYCTL0073:"));
        Assert.assertThat(ex.getMessage(), containsString(expectedMessage));
    }
}
 
源代码17 项目: hottub   文件: XMLStreamException2.java
public XMLStreamException2(String msg, Location location) {
    super(msg, location);
}
 
源代码18 项目: JDKSourceCode1.8   文件: StAXLocationWrapper.java
public void setLocation(Location location) {
    fLocation = location;
}
 
源代码19 项目: openjdk-8   文件: XMLReaderComposite.java
@Override
public Location getLocation() {
    switch (state) {
    case StartTag:
    case EndTag: return new Location() {

        @Override
        public int getLineNumber() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public int getColumnNumber() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public int getCharacterOffset() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public String getPublicId() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getSystemId() {
            // TODO Auto-generated method stub
            return null;
        }

    };
    case Payload:
    default:
        return payloadReader.getLocation();
    }
}
 
源代码20 项目: activiti6-boot2   文件: BpmnXMLUtil.java
public static void addXMLLocation(BaseElement element, XMLStreamReader xtr) {
  Location location = xtr.getLocation();
  element.setXmlRowNumber(location.getLineNumber());
  element.setXmlColumnNumber(location.getColumnNumber());
}
 
源代码21 项目: openjdk-jdk8u   文件: StreamReaderDelegate.java
public Location getLocation() {
  return reader.getLocation();
}
 
源代码22 项目: openjdk-8-source   文件: StartDocumentEvent.java
public StartDocumentEvent(String encoding, String version, boolean standalone,Location loc){
    this.fStandaloneSet = true;
    init(encoding, version, standalone, loc);
}
 
源代码23 项目: Smack   文件: StaxXmlPullParser.java
@Override
public int getColumnNumber() {
    Location location = xmlStreamReader.getLocation();
    return location.getColumnNumber();
}
 
源代码24 项目: woodstox   文件: DTDValidatorBase.java
Location getLocation() {
    return mContext.getValidationLocation();
}
 
源代码25 项目: staedi   文件: StaEDISchemaReadException.java
public StaEDISchemaReadException(String message, Location location, Throwable cause) {
    super(message, cause);
    this.location = location;
}
 
源代码26 项目: gemfirexd-oss   文件: DataReader.java
/**
 * Reads a bean from the given xml stream reader.
 * 
 * @param xmlReader The reader
 */
private void readBean(XMLStreamReader xmlReader) throws XMLStreamException, DdlUtilsXMLException
{
    QName    elemQName  = xmlReader.getName();
    Location location   = xmlReader.getLocation();
    Map      attributes = new HashMap();
    String   tableName  = null;

    for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++)
    {
        QName attrQName = xmlReader.getAttributeName(idx);

        attributes.put(isCaseSensitive() ? attrQName.getLocalPart() : attrQName.getLocalPart().toLowerCase(),
                       xmlReader.getAttributeValue(idx));
    }
    readColumnSubElements(xmlReader, attributes);

    if ("table".equals(elemQName.getLocalPart()))
    {
        tableName = (String)attributes.get("table-name");
    }
    else
    {
        tableName  = elemQName.getLocalPart();
    }

    Table table = _model.findTable(tableName, isCaseSensitive());

    if (table == null)
    {
        _log.warn("Data XML contains an element " + elemQName + " at location " + location +
                  " but there is no table defined with this name. This element will be ignored.");
    }
    else
    {
        DynaBean bean = _model.createDynaBeanFor(table);

        for (int idx = 0; idx < table.getColumnCount(); idx++)
        {
            Column column = table.getColumn(idx);
            String value  = (String)attributes.get(isCaseSensitive() ? column.getName() : column.getName().toLowerCase());

            if (value != null)
            {
                setColumnValue(bean, table, column, value);
            }
        }
        getSink().addBean(bean);
        consumeRestOfElement(xmlReader);
    }
}
 
源代码27 项目: Bytecoder   文件: DummyEvent.java
public Location getLocation(){
    return fLocation;
}
 
源代码28 项目: wildfly-core   文件: ThreadsLogger.java
@Message(id = 27, value = "%s must be greater than or equal to zero")
XMLStreamException countMustBePositive(Attribute count, @Param Location location);
 
源代码29 项目: wildfly-core   文件: ControllerLogger.java
@Message(id = 377, value = "Unexpected element '%s' encountered. Valid elements are: '%s'")
XMLStreamException unexpectedElement(QName name, StringBuilder possible, @Param Location location);
 
源代码30 项目: secure-data-service   文件: EdFiEntity.java
public EdFiEntity(Location location, Object entity) {
    this.lineNumber = location.getLineNumber();
    this.columnNumber = location.getColumnNumber();
    this.entity = entity;
}