本文整理汇总了Java中javax.xml.stream.Location类的典型用法代码示例。如果您正苦于以下问题:Java Location类的具体用法?Java Location怎么用?Java Location使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Location类属于javax.xml.stream包,在下文中一共展示了Location类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLocation
import javax.xml.stream.Location; //导入依赖的package包/类
@Test
public void testLocation() {
String XML = "<?xml version='1.0' ?>" + "<!DOCTYPE root [\n" + "<!ENTITY intEnt 'internal'>\n" + "<!ENTITY extParsedEnt SYSTEM 'url:dummy'>\n"
+ "<!NOTATION notation PUBLIC 'notation-public-id'>\n" + "<!NOTATION notation2 SYSTEM 'url:dummy'>\n"
+ "<!ENTITY extUnparsedEnt SYSTEM 'url:dummy2' NDATA notation>\n" + "]>\n" + "<root />";
try {
XMLEventReader er = getReader(XML);
XMLEvent evt = er.nextEvent(); // StartDocument
Location loc1 = evt.getLocation();
System.out.println("Location 1: " + loc1.getLineNumber() + "," + loc1.getColumnNumber());
evt = er.nextEvent(); // DTD
// loc1 should not change so its line number should still be 1
Assert.assertTrue(loc1.getLineNumber() == 1);
Location loc2 = evt.getLocation();
System.out.println("Location 2: " + loc2.getLineNumber() + "," + loc2.getColumnNumber());
evt = er.nextEvent(); // root
System.out.println("Location 1: " + loc1.getLineNumber() + "," + loc1.getColumnNumber());
Assert.assertTrue(loc1.getLineNumber() == 1);
Assert.assertTrue(loc2.getLineNumber() == 7);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
示例2: report
import javax.xml.stream.Location; //导入依赖的package包/类
public void report(String message, String errorType,
Object relatedInformation, Location location)
throws XMLStreamException
{
if (errorHandler != null)
{
try
{
errorHandler.warning(new SAXParseException(message, this));
}
catch (SAXException e)
{
XMLStreamException e2 = new XMLStreamException(e.getMessage());
e2.initCause(e);
throw e2;
}
}
}
示例3: toLocation
import javax.xml.stream.Location; //导入依赖的package包/类
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;
}
示例4: unmarshal
import javax.xml.stream.Location; //导入依赖的package包/类
private Map<URI, Policy> unmarshal(final XMLEventReader reader, final StartElement parentElement) throws PolicyException {
XMLEvent event = null;
while (reader.hasNext()) {
try {
event = reader.peek();
switch (event.getEventType()) {
case XMLStreamConstants.START_DOCUMENT:
case XMLStreamConstants.COMMENT:
reader.nextEvent();
break;
case XMLStreamConstants.CHARACTERS:
processCharacters(event.asCharacters(), parentElement, map);
reader.nextEvent();
break;
case XMLStreamConstants.END_ELEMENT:
processEndTag(event.asEndElement(), parentElement);
reader.nextEvent();
return map;
case XMLStreamConstants.START_ELEMENT:
final StartElement element = event.asStartElement();
processStartTag(element, parentElement, reader, map);
break;
case XMLStreamConstants.END_DOCUMENT:
return map;
default:
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0087_UNKNOWN_EVENT(event)));
}
} catch (XMLStreamException e) {
final Location location = event == null ? null : event.getLocation();
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0088_FAILED_PARSE(location)), e);
}
}
return map;
}
示例5: getLocator
import javax.xml.stream.Location; //导入依赖的package包/类
private Locator getLocator(XMLStreamReader reader) {
Location location = reader.getLocation();
LocatorImpl loc = new LocatorImpl();
loc.setSystemId(location.getSystemId());
loc.setLineNumber(location.getLineNumber());
return loc;
}
示例6: getCurrentLocation
import javax.xml.stream.Location; //导入依赖的package包/类
public Location getCurrentLocation() {
if (docLocator != null) {
return new SAXLocation(docLocator);
} else {
return null;
}
}
示例7: convertToStaxLocation
import javax.xml.stream.Location; //导入依赖的package包/类
Location convertToStaxLocation(final XMLLocator location){
return new Location(){
public int getColumnNumber(){
return location.getColumnNumber();
}
public int getLineNumber(){
return location.getLineNumber();
}
public String getPublicId(){
return location.getPublicId();
}
public String getSystemId(){
return location.getLiteralSystemId();
}
public int getCharacterOffset(){
return location.getCharacterOffset();
}
public String getLocationURI(){
return "";
}
};
}
示例8: init
import javax.xml.stream.Location; //导入依赖的package包/类
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;
}
示例9: setLocation
import javax.xml.stream.Location; //导入依赖的package包/类
void setLocation(Location loc){
if (loc == null) {
fLocation = nowhere;
} else {
fLocation = loc;
}
}
示例10: LocationImpl
import javax.xml.stream.Location; //导入依赖的package包/类
LocationImpl(Location loc){
systemId = loc.getSystemId();
publicId = loc.getPublicId();
lineNo = loc.getLineNumber();
colNo = loc.getColumnNumber();
charOffset = loc.getCharacterOffset();
}
示例11: testSetLocation
import javax.xml.stream.Location; //导入依赖的package包/类
@Test
public void testSetLocation() {
XMLEventFactory factory = XMLEventFactory.newInstance();
Location loc = new MyLocation();
factory.setLocation(loc);
XMLEvent event = factory.createComment("some comment");
Assert.assertEquals(event.getLocation().getLineNumber(), 15);
}
示例12: DTDImpl
import javax.xml.stream.Location; //导入依赖的package包/类
protected DTDImpl(Location location,
String body, Object impl, List notations, List entities)
{
super(location);
this.body = body;
this.impl = impl;
this.notations = notations;
this.entities = entities;
}
示例13: NotationDeclarationImpl
import javax.xml.stream.Location; //导入依赖的package包/类
protected NotationDeclarationImpl(Location location,
String name, String publicId,
String systemId)
{
super(location);
this.name = name;
this.publicId = publicId;
this.systemId = systemId;
}
示例14: StartDocumentImpl
import javax.xml.stream.Location; //导入依赖的package包/类
protected StartDocumentImpl(Location location,
String systemId, String encoding,
String xmlVersion, boolean xmlStandalone,
boolean standaloneDeclared,
boolean encodingDeclared)
{
super(location);
this.systemId = systemId;
this.encoding = encoding;
this.xmlVersion = xmlVersion;
this.xmlStandalone = xmlStandalone;
this.standaloneDeclared = standaloneDeclared;
this.encodingDeclared = encodingDeclared;
}
示例15: main
import javax.xml.stream.Location; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length == 0) {
throw new Exception("XML file name should be specified as the first command line argument");
}
File xmlFile = new File(args[0]);
//
// instantiate the factory
//
XMLInputFactory factory = XMLInputFactory.newInstance();
//
// configure the factory
//
//
// get the parser
//
XMLEventReader reader = factory.createXMLEventReader(new FileReader(xmlFile));
//
// iterate, and also manage location
//
while(reader.hasNext()) {
XMLEvent e = reader.nextEvent();
Location location = e.getLocation();
System.out.println(
"[" + location.getLineNumber() + ":" + location.getColumnNumber() + "]: " +
e.toString());
}
}