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

项目:openjdk-jdk10    文件:Issue58Test.java   
@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());
    }
}
项目:javify    文件:SAXParser.java   
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;
        }
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:LocatableWebServiceException.java   
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;
}
项目:OpenJSharp    文件:ExternalAttachmentsUnmarshaller.java   
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;
}
项目:OpenJSharp    文件:LocatableWebServiceException.java   
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;
}
项目:OpenJSharp    文件: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;
}
项目:OpenJSharp    文件:SAX2StAXBaseWriter.java   
public Location getCurrentLocation() {
        if (docLocator != null) {
                return new SAXLocation(docLocator);
        } else {
                return null;
        }

}
项目:OpenJSharp    文件:StaxErrorReporter.java   
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 "";
        }

    };
}
项目:OpenJSharp    文件: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;
}
项目:OpenJSharp    文件:DummyEvent.java   
void setLocation(Location loc){
    if (loc == null) {
        fLocation = nowhere;
    } else {
        fLocation = loc;
    }
}
项目:OpenJSharp    文件:LocationImpl.java   
LocationImpl(Location loc){
    systemId = loc.getSystemId();
    publicId = loc.getPublicId();
    lineNo = loc.getLineNumber();
    colNo = loc.getColumnNumber();
    charOffset = loc.getCharacterOffset();
}
项目:openjdk-jdk10    文件:ExternalAttachmentsUnmarshaller.java   
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;
}
项目:openjdk-jdk10    文件:LocatableWebServiceException.java   
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;
}
项目:openjdk-jdk10    文件: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;
}
项目:openjdk-jdk10    文件:SAX2StAXBaseWriter.java   
public Location getCurrentLocation() {
        if (docLocator != null) {
                return new SAXLocation(docLocator);
        } else {
                return null;
        }

}
项目:openjdk-jdk10    文件:StaxErrorReporter.java   
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 "";
        }

    };
}
项目:openjdk-jdk10    文件: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;
}
项目:openjdk-jdk10    文件:DummyEvent.java   
void setLocation(Location loc){
    if (loc == null) {
        fLocation = nowhere;
    } else {
        fLocation = loc;
    }
}
项目:openjdk-jdk10    文件:LocationImpl.java   
LocationImpl(Location loc){
    systemId = loc.getSystemId();
    publicId = loc.getPublicId();
    lineNo = loc.getLineNumber();
    colNo = loc.getColumnNumber();
    charOffset = loc.getCharacterOffset();
}
项目:openjdk-jdk10    文件:XMLEventLocationTest.java   
@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);
}
项目:openjdk9    文件:ExternalAttachmentsUnmarshaller.java   
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;
}
项目:openjdk9    文件:LocatableWebServiceException.java   
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;
}
项目:openjdk9    文件: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;
}
项目:javify    文件:DTDImpl.java   
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;
}
项目:javify    文件:NotationDeclarationImpl.java   
protected NotationDeclarationImpl(Location location,
                                  String name, String publicId,
                                  String systemId)
{
  super(location);
  this.name = name;
  this.publicId = publicId;
  this.systemId = systemId;
}
项目:javify    文件:StartDocumentImpl.java   
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;
}
项目:openjdk9    文件:LocationImpl.java   
LocationImpl(Location loc){
    systemId = loc.getSystemId();
    publicId = loc.getPublicId();
    lineNo = loc.getLineNumber();
    colNo = loc.getColumnNumber();
    charOffset = loc.getCharacterOffset();
}
项目:playground    文件:Main.java   
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());
        }
    }
项目:javify    文件:NamespaceImpl.java   
protected NamespaceImpl(Location location, String prefix, String uri,
                        boolean specified)
{
  super(location);
  this.prefix = prefix;
  this.uri = uri;
  this.specified = specified;
}
项目:MultiObjective_Rec    文件:FilePrinter.java   
public void printLocations(String path, ArrayList<Location> locations) throws FileNotFoundException {
    //print location list to file
    FileOutputStream fos;
    fos = new FileOutputStream(path,true);
    PrintStream ps = new PrintStream(fos);

    for(Location l:locations){
        ps.println(l.toString());
    }

    ps.flush();
    ps.close();
}
项目:MultiObjective_Rec    文件:ConsolePrinter.java   
public void printLocations(String path, ArrayList<Location> locations) {
    if(debugPrint == false)
    {
        return;
    }
    //print location list to console
    for(Location l:locations){
        System.out.println(l.toString());
    }
}
项目:team-explorer-everywhere    文件:DOMStreamReader.java   
@Override
public Location getLocation() {
    return new Location() {

        @Override
        public int getCharacterOffset() {
            return 0;
        }

        @Override
        public int getColumnNumber() {
            return 0;
        }

        @Override
        public int getLineNumber() {
            return 0;
        }

        @Override
        public String getPublicId() {
            return null;
        }

        @Override
        public String getSystemId() {
            return null;
        }

    };
}
项目:xmlsec-gost    文件:XMLSecurityStreamReader.java   
@Override
public Location getLocation() {
    return new Location() {
        @Override
        public int getLineNumber() {
            return -1;
        }

        @Override
        public int getColumnNumber() {
            return -1;
        }

        @Override
        public int getCharacterOffset() {
            return -1;
        }

        @Override
        public String getPublicId() {
            return null;
        }

        @Override
        public String getSystemId() {
            return null;
        }
    };
}
项目:javify    文件:EntityDeclarationImpl.java   
protected EntityDeclarationImpl(Location location,
                                String publicId, String systemId,
                                String name, String notationName,
                                String replacementText, String baseUri)
{
  super(location);
  this.publicId = publicId;
  this.systemId = systemId;
  this.name = name;
  this.notationName = notationName;
  this.replacementText = replacementText;
  this.baseUri = baseUri;
}
项目:spring    文件:StaxStreamXMLReader.java   
private void handleDtd() throws SAXException {
    if (getLexicalHandler() != null) {
        javax.xml.stream.Location location = this.reader.getLocation();
        getLexicalHandler().startDTD(null, location.getPublicId(), location.getSystemId());
    }
    if (getLexicalHandler() != null) {
        getLexicalHandler().endDTD();
    }
}
项目:ts-reaktive    文件:XMLReadException.java   
public static XMLReadException wrap(RuntimeException cause, Location location) {
    if (cause instanceof XMLReadException) {
        return (XMLReadException) cause;
    } else {
        return new XMLReadException(cause, location);
    }
}
项目:Camel    文件:StaxStreamXMLReader.java   
private void handleDtd() throws SAXException {
    if (getLexicalHandler() != null) {
        javax.xml.stream.Location location = reader.getLocation();
        getLexicalHandler().startDTD(null, location.getPublicId(), location.getSystemId());
    }
    if (getLexicalHandler() != null) {
        getLexicalHandler().endDTD();
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:ExternalAttachmentsUnmarshaller.java   
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;
}
项目:javify    文件:CharactersImpl.java   
protected CharactersImpl(Location location,
                         String data, boolean whitespace, boolean cdata,
                         boolean ignorableWhitespace)
{
  super(location);
  this.data = data;
  this.whitespace = whitespace;
  this.cdata = cdata;
  this.ignorableWhitespace = ignorableWhitespace;
}
项目:javify    文件:StartElementImpl.java   
protected StartElementImpl(Location location,
                           QName name, List attributes, List namespaces,
                           NamespaceContext namespaceContext)
{
  super(location);
  this.name = name;
  this.attributes = attributes;
  this.namespaces = namespaces;
  this.namespaceContext = namespaceContext;
}