下面列出了javax.xml.stream.Location#getLineNumber ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Returns the parameters for an error message saying that an error occurred while processing a file.
* This method uses the information provided by methods like {@link LineNumberReader#getLineNumber()}
* or {@link XMLStreamReader#getLocation()} if the given {@code store} is one of the supported types.
*
* @param format abbreviation of the file format (e.g. "CSV", "GML", "WKT", <i>etc</i>).
* @param filename name of the file or the data store.
* @param store the input or output object, or {@code null}.
* @return the parameters for a localized error message for a file that can not be processed.
*
* @since 0.8
*/
@SuppressWarnings("fallthrough")
public static Object[] errorMessageParameters(final String format, final String filename, final Object store) {
int line = 0;
int column = 0;
if (store instanceof XMLStreamReader) {
final Location location = ((XMLStreamReader) store).getLocation();
line = location.getLineNumber() + 1;
column = location.getColumnNumber() + 1;
} else if (store instanceof LineNumberReader) {
line = ((LineNumberReader) store).getLineNumber();
}
final Object[] params = new Object[(line == 0) ? 2 : (column == 0) ? 3 : 4];
switch (params.length) {
default: // Fallthrough everywhere
case 4: params[3] = column;
case 3: params[2] = line;
case 2: params[1] = filename;
case 1: params[0] = format;
case 0: break;
}
return params;
}
LocationImpl(Location loc){
systemId = loc.getSystemId();
publicId = loc.getPublicId();
lineNo = loc.getLineNumber();
colNo = loc.getColumnNumber();
charOffset = loc.getCharacterOffset();
}
private static boolean addLocation(Document doc, Node node,
Location loc,
boolean recordLoc) {
if (recordLoc && loc != null && (loc.getColumnNumber() != 0 || loc.getLineNumber() != 0)) {
try {
final int charOffset = loc.getCharacterOffset();
final int colNum = loc.getColumnNumber();
final int linNum = loc.getLineNumber();
final String pubId = loc.getPublicId() == null ? doc.getDocumentURI() : loc.getPublicId();
final String sysId = loc.getSystemId() == null ? doc.getDocumentURI() : loc.getSystemId();
Location loc2 = new Location() {
public int getCharacterOffset() {
return charOffset;
}
public int getColumnNumber() {
return colNum;
}
public int getLineNumber() {
return linNum;
}
public String getPublicId() {
return pubId;
}
public String getSystemId() {
return sysId;
}
};
node.setUserData("location", loc2, LocationUserDataHandler.INSTANCE);
} catch (Throwable ex) {
//possibly not DOM level 3, won't be able to record this then
return false;
}
}
return recordLoc;
}
@Nullable
public static SimpleLocation create (@Nullable final Location aLocator)
{
if (aLocator == null)
return null;
return new SimpleLocation (StringHelper.getConcatenatedOnDemand (aLocator.getPublicId (),
"/",
aLocator.getSystemId ()),
aLocator.getLineNumber (),
aLocator.getColumnNumber ());
}
LocationImpl(Location loc){
systemId = loc.getSystemId();
publicId = loc.getPublicId();
lineNo = loc.getLineNumber();
colNo = loc.getColumnNumber();
charOffset = loc.getCharacterOffset();
}
LocationImpl(Location loc){
systemId = loc.getSystemId();
publicId = loc.getPublicId();
lineNo = loc.getLineNumber();
colNo = loc.getColumnNumber();
charOffset = loc.getCharacterOffset();
}
LocationImpl(Location loc){
systemId = loc.getSystemId();
publicId = loc.getPublicId();
lineNo = loc.getLineNumber();
colNo = loc.getColumnNumber();
charOffset = loc.getCharacterOffset();
}
LocationImpl(Location loc){
systemId = loc.getSystemId();
publicId = loc.getPublicId();
lineNo = loc.getLineNumber();
colNo = loc.getColumnNumber();
charOffset = loc.getCharacterOffset();
}
LocationImpl(Location loc){
systemId = loc.getSystemId();
publicId = loc.getPublicId();
lineNo = loc.getLineNumber();
colNo = loc.getColumnNumber();
charOffset = loc.getCharacterOffset();
}
AbstractObjectImpl(XMLStreamReader xsr) {
Location loc = xsr.getLocation();
this.lineNumber = loc.getLineNumber();
this.systemId = loc.getSystemId();
}
private static String getParserMessage(String msg, Location location) {
return "ParseError at [row,col]:["+location.getLineNumber()+","+
location.getColumnNumber()+"]\n"+
"Message: "+msg;
}
private static String getParserMessage(String msg, Location location) {
return "ParseError at [row,col]:["+location.getLineNumber()+","+
location.getColumnNumber()+"]\n"+
"Message: "+msg;
}
public static String error(String msg, Location location) {
return "ParseError at [row,col]:["+location.getLineNumber()+","+
location.getColumnNumber()+"]\n"+
"Message: "+msg;
}
AbstractObjectImpl(XMLStreamReader xsr) {
Location loc = xsr.getLocation();
this.lineNumber = loc.getLineNumber();
this.systemId = loc.getSystemId();
}
public EdFiEntity(Location location, Object entity) {
this.lineNumber = location.getLineNumber();
this.columnNumber = location.getColumnNumber();
this.entity = entity;
}
private XMLReadException(RuntimeException cause, Location location) {
super(cause.getMessage() + " at " + location.getLineNumber() + ":" + location.getColumnNumber(), cause);
}
@Override
public int getLineNumber() {
Location location = xmlStreamReader.getLocation();
return location.getLineNumber();
}
AbstractObjectImpl(XMLStreamReader xsr) {
Location loc = xsr.getLocation();
this.lineNumber = loc.getLineNumber();
this.systemId = loc.getSystemId();
}
AbstractObjectImpl(XMLStreamReader xsr) {
Location loc = xsr.getLocation();
this.lineNumber = loc.getLineNumber();
this.systemId = loc.getSystemId();
}
public void addError(Location loc, String msg) {
String errMsg = loc != null ? "line " + loc.getLineNumber() + " of " : "";
errMsg = errMsg + def.getDocumentBaseURI() + " " + msg;
addErrorMessage(errMsg);
}