下面列出了org.xml.sax.ext.Locator2#javax.xml.stream.Location 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
@Override
public String getSystemId() {
if (mScanner != null) {
Location loc = mScanner.getLocation();
return loc.getSystemId();
}
return null;
}
public void testReturnEntityForCharReference() throws Exception
{
String XML = "<root>text & 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());
}
@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"));
}
public FailureLocation(Location loc, String docURI) {
this.location = loc;
this.documentURI = docURI;
if (documentURI == null) {
documentURI = loc.getSystemId();
}
}
/**
* 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;
}
@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);
}
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;
}
private Locator getLocator(XMLStreamReader reader) {
Location location = reader.getLocation();
LocatorImpl loc = new LocatorImpl();
loc.setSystemId(location.getSystemId());
loc.setLineNumber(location.getLineNumber());
return loc;
}
public CompactNsContext(Location loc,
String[] namespaces, int nsLen,
int firstLocal)
{
mLocation = loc;
mNamespaces = namespaces;
mNsLength = nsLen;
mFirstLocalNs = firstLocal;
}
void setLocation(Location loc){
if (loc == null) {
fLocation = nowhere;
} else {
fLocation = loc;
}
}
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));
}
}
public XMLStreamException2(String msg, Location location) {
super(msg, location);
}
public void setLocation(Location location) {
fLocation = location;
}
@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();
}
}
public static void addXMLLocation(BaseElement element, XMLStreamReader xtr) {
Location location = xtr.getLocation();
element.setXmlRowNumber(location.getLineNumber());
element.setXmlColumnNumber(location.getColumnNumber());
}
public Location getLocation() {
return reader.getLocation();
}
public StartDocumentEvent(String encoding, String version, boolean standalone,Location loc){
this.fStandaloneSet = true;
init(encoding, version, standalone, loc);
}
@Override
public int getColumnNumber() {
Location location = xmlStreamReader.getLocation();
return location.getColumnNumber();
}
Location getLocation() {
return mContext.getValidationLocation();
}
public StaEDISchemaReadException(String message, Location location, Throwable cause) {
super(message, cause);
this.location = location;
}
/**
* 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);
}
}
public Location getLocation(){
return fLocation;
}
@Message(id = 27, value = "%s must be greater than or equal to zero")
XMLStreamException countMustBePositive(Attribute count, @Param Location location);
@Message(id = 377, value = "Unexpected element '%s' encountered. Valid elements are: '%s'")
XMLStreamException unexpectedElement(QName name, StringBuilder possible, @Param Location location);
public EdFiEntity(Location location, Object entity) {
this.lineNumber = location.getLineNumber();
this.columnNumber = location.getColumnNumber();
this.entity = entity;
}