Java Code Examples for javax.xml.stream.Location#getLineNumber()

The following examples show how to use javax.xml.stream.Location#getLineNumber() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IOUtilities.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: LocationImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
LocationImpl(Location loc){
    systemId = loc.getSystemId();
    publicId = loc.getPublicId();
    lineNo = loc.getLineNumber();
    colNo = loc.getColumnNumber();
    charOffset = loc.getCharacterOffset();
}
 
Example 3
Source File: LocationImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
LocationImpl(Location loc){
    systemId = loc.getSystemId();
    publicId = loc.getPublicId();
    lineNo = loc.getLineNumber();
    colNo = loc.getColumnNumber();
    charOffset = loc.getCharacterOffset();
}
 
Example 4
Source File: LocationImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
LocationImpl(Location loc){
    systemId = loc.getSystemId();
    publicId = loc.getPublicId();
    lineNo = loc.getLineNumber();
    colNo = loc.getColumnNumber();
    charOffset = loc.getCharacterOffset();
}
 
Example 5
Source File: StaxUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 6
Source File: SimpleLocation.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@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 ());
}
 
Example 7
Source File: LocationImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
LocationImpl(Location loc){
    systemId = loc.getSystemId();
    publicId = loc.getPublicId();
    lineNo = loc.getLineNumber();
    colNo = loc.getColumnNumber();
    charOffset = loc.getCharacterOffset();
}
 
Example 8
Source File: LocationImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
LocationImpl(Location loc){
    systemId = loc.getSystemId();
    publicId = loc.getPublicId();
    lineNo = loc.getLineNumber();
    colNo = loc.getColumnNumber();
    charOffset = loc.getCharacterOffset();
}
 
Example 9
Source File: LocationImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
LocationImpl(Location loc){
    systemId = loc.getSystemId();
    publicId = loc.getPublicId();
    lineNo = loc.getLineNumber();
    colNo = loc.getColumnNumber();
    charOffset = loc.getCharacterOffset();
}
 
Example 10
Source File: AbstractDefinitionValidator.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void addError(Location loc, String msg) {
    String errMsg = loc != null ? "line " + loc.getLineNumber() + " of " : "";
    errMsg = errMsg + def.getDocumentBaseURI() + " " + msg;
    addErrorMessage(errMsg);
}
 
Example 11
Source File: AbstractObjectImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
AbstractObjectImpl(XMLStreamReader xsr) {
    Location loc = xsr.getLocation();
    this.lineNumber = loc.getLineNumber();
    this.systemId = loc.getSystemId();
}
 
Example 12
Source File: AbstractObjectImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
AbstractObjectImpl(XMLStreamReader xsr) {
    Location loc = xsr.getLocation();
    this.lineNumber = loc.getLineNumber();
    this.systemId = loc.getSystemId();
}
 
Example 13
Source File: AbstractObjectImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
AbstractObjectImpl(XMLStreamReader xsr) {
    Location loc = xsr.getLocation();
    this.lineNumber = loc.getLineNumber();
    this.systemId = loc.getSystemId();
}
 
Example 14
Source File: StaxXmlPullParser.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Override
public int getLineNumber() {
    Location location = xmlStreamReader.getLocation();
    return location.getLineNumber();
}
 
Example 15
Source File: XMLReadException.java    From ts-reaktive with MIT License 4 votes vote down vote up
private XMLReadException(RuntimeException cause, Location location) {
    super(cause.getMessage() + " at " + location.getLineNumber() + ":" + location.getColumnNumber(), cause);
}
 
Example 16
Source File: EdFiEntity.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
public EdFiEntity(Location location, Object entity) {
    this.lineNumber = location.getLineNumber();
    this.columnNumber = location.getColumnNumber();
    this.entity = entity;
}
 
Example 17
Source File: AbstractObjectImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
AbstractObjectImpl(XMLStreamReader xsr) {
    Location loc = xsr.getLocation();
    this.lineNumber = loc.getLineNumber();
    this.systemId = loc.getSystemId();
}
 
Example 18
Source File: ParsingUtils.java    From galleon with Apache License 2.0 4 votes vote down vote up
public static String error(String msg, Location location) {
    return "ParseError at [row,col]:["+location.getLineNumber()+","+
            location.getColumnNumber()+"]\n"+
            "Message: "+msg;
}
 
Example 19
Source File: MavenProducerSpecXmlParser10.java    From galleon with Apache License 2.0 4 votes vote down vote up
private static String getParserMessage(String msg, Location location) {
    return "ParseError at [row,col]:["+location.getLineNumber()+","+
            location.getColumnNumber()+"]\n"+
            "Message: "+msg;
}
 
Example 20
Source File: MavenChannelSpecXmlParser10.java    From galleon with Apache License 2.0 4 votes vote down vote up
private static String getParserMessage(String msg, Location location) {
    return "ParseError at [row,col]:["+location.getLineNumber()+","+
            location.getColumnNumber()+"]\n"+
            "Message: "+msg;
}