javax.xml.stream.Location Java Examples

The following examples show how to use javax.xml.stream.Location. 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: StreamBootstrapper.java    From woodstox with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: JBossAllXMLElementReader.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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);
}
 
Example #3
Source File: TestTreatCharRefAsEnts.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public void testReturnEntityForCharReference() throws Exception
{
    
    String XML = "<root>text &amp; 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());
}
 
Example #4
Source File: StandaloneDeploymentUnicityTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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));
    }
}
 
Example #5
Source File: SAX2StAXBaseWriter.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public Location getCurrentLocation() {
        if (docLocator != null) {
                return new SAXLocation(docLocator);
        } else {
                return null;
        }

}
 
Example #6
Source File: WstxSAXParser.java    From woodstox with Apache License 2.0 5 votes vote down vote up
@Override
public String getSystemId() {
    if (mScanner != null) {
        Location loc = mScanner.getLocation();
        return loc.getSystemId();
    }
    return null;
}
 
Example #7
Source File: WstxSAXParser.java    From woodstox with Apache License 2.0 5 votes vote down vote up
@Override
public int getColumnNumber()
{
    if (mScanner != null) {
        Location loc = mScanner.getLocation();
        return loc.getColumnNumber();
    }
    return -1;
}
 
Example #8
Source File: DummyEvent.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void setLocation(Location loc){
    if (loc == null) {
        fLocation = nowhere;
    } else {
        fLocation = loc;
    }
}
 
Example #9
Source File: FailureLocation.java    From cxf with Apache License 2.0 5 votes vote down vote up
public FailureLocation(Location loc, String docURI) {
    this.location = loc;
    this.documentURI = docURI;
    if (documentURI == null) {
        documentURI = loc.getSystemId();
    }
}
 
Example #10
Source File: WSDLParserExtensionFacade.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private Locator getLocator(XMLStreamReader reader) {
    Location location = reader.getLocation();
        LocatorImpl loc = new LocatorImpl();
        loc.setSystemId(location.getSystemId());
        loc.setLineNumber(location.getLineNumber());
    return loc;
}
 
Example #11
Source File: CompactNsContext.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public CompactNsContext(Location loc,
                        String[] namespaces, int nsLen,
                        int firstLocal)
{
    mLocation = loc;
    mNamespaces = namespaces;
    mNsLength = nsLen;
    mFirstLocalNs = firstLocal;
}
 
Example #12
Source File: InputElementStack.java    From woodstox with Apache License 2.0 5 votes vote down vote up
/**
     * 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;
}
 
Example #13
Source File: WSDLParserExtensionFacade.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private Locator getLocator(XMLStreamReader reader) {
    Location location = reader.getLocation();
        LocatorImpl loc = new LocatorImpl();
        loc.setSystemId(location.getSystemId());
        loc.setLineNumber(location.getLineNumber());
    return loc;
}
 
Example #14
Source File: LocatableWebServiceException.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #15
Source File: EdFiParserProcessorTest.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
@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"));

}
 
Example #16
Source File: StartDocumentEvent.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #17
Source File: EventLocation.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static Location getNilLocation() {
    return new EventLocation();
}
 
Example #18
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 #19
Source File: DummyEvent.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public Location getLocation(){
    return fLocation;
}
 
Example #20
Source File: XMLStreamException2.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public XMLStreamException2(String msg, Location location) {
    super(msg, location);
}
 
Example #21
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;
}
 
Example #22
Source File: WEntityReference.java    From woodstox with Apache License 2.0 4 votes vote down vote up
/**
 * This constructor gets called for undeclared/defined entities: we will
 * still know the name (from the reference), but not how it's defined
 * (since it is not defined).
 */
public WEntityReference(Location loc, String name)
{
    super(loc, (EntityDeclaration) null);
    mName = name;
}
 
Example #23
Source File: JBossDeploymentStructureParser13.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static XMLStreamException endOfDocument(final Location location) {
    return ServerLogger.ROOT_LOGGER.unexpectedEndOfDocument(location);
}
 
Example #24
Source File: StaxEventXMLReader.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void handleStartDocument(final XMLEvent event) throws SAXException {
	if (event.isStartDocument()) {
		StartDocument startDocument = (StartDocument) event;
		String xmlVersion = startDocument.getVersion();
		if (StringUtils.hasLength(xmlVersion)) {
			this.xmlVersion = xmlVersion;
		}
		if (startDocument.encodingSet()) {
			this.encoding = startDocument.getCharacterEncodingScheme();
		}
	}
	if (getContentHandler() != null) {
		final Location location = event.getLocation();
		getContentHandler().setDocumentLocator(new Locator2() {
			@Override
			public int getColumnNumber() {
				return (location != null ? location.getColumnNumber() : -1);
			}
			@Override
			public int getLineNumber() {
				return (location != null ? location.getLineNumber() : -1);
			}
			@Override
			@Nullable
			public String getPublicId() {
				return (location != null ? location.getPublicId() : null);
			}
			@Override
			@Nullable
			public String getSystemId() {
				return (location != null ? location.getSystemId() : null);
			}
			@Override
			public String getXMLVersion() {
				return xmlVersion;
			}
			@Override
			@Nullable
			public String getEncoding() {
				return encoding;
			}
		});
		getContentHandler().startDocument();
	}
}
 
Example #25
Source File: TextBuffer.java    From woodstox with Apache License 2.0 4 votes vote down vote up
/**
 * Pass-through decode method called to find find the next token,
 * decode it, and repeat the process as long as there are more
 * tokens and the array decoder accepts more entries.
 * All tokens processed will be "consumed", such that they will
 * not be visible via buffer.
 *
 * @return Number of tokens decoded; 0 means that no (more) tokens
 *    were found from this buffer.
 */
public int decodeElements(TypedArrayDecoder tad, InputProblemReporter rep)
    throws TypedXMLStreamException
{
    int count = 0;

    /* First: for simplicity, we require a single flat buffer to
     * decode from. Second: to be able to update start location
     * (to keep track of what's available), we need to fake that
     * we are using a shared buffer (since that has offset)
     */
    if (mInputStart < 0) {
        if (mHasSegments) {
            mInputBuffer = buildResultArray();
            mInputLen = mInputBuffer.length;
            // let's also clear segments since they are not needed any more
            clearSegments();
        } else {
            // just current buffer, easier to fake
            mInputBuffer = mCurrentSegment;
            mInputLen = mCurrentSize;
        }
        mInputStart = 0;
    }

    // And then let's decode
    int ptr = mInputStart;
    final int end = ptr + mInputLen;
    final char[] buf = mInputBuffer;
    int start = ptr;

    try {
        decode_loop:
        while (ptr < end) {
            // First, any space to skip?
            while (buf[ptr] <= INT_SPACE) {
                if (++ptr >= end) {
                    break decode_loop;
                }
            }
            // Then let's figure out non-space char (token)
            start = ptr;
            ++ptr;
            while (ptr < end && buf[ptr] > INT_SPACE) {
                ++ptr;
            }
            ++count;
            int tokenEnd = ptr;
            ++ptr; // to skip trailing space (or, beyond end)
            // And there we have it
            if (tad.decodeValue(buf, start, tokenEnd)) {
                break;
            }
        }
    } catch (IllegalArgumentException iae) {
        // Need to convert to a checked stream exception

        /* Hmmh. This is probably not an accurate location... but
         * we can't do much better as content we have has been
         * normalized already.
         */
        Location loc = rep.getLocation();
        // -1 to move it back after being advanced earlier (to skip trailing space)
        String lexical = new String(buf, start, (ptr-start-1));
        throw new TypedXMLStreamException(lexical, iae.getMessage(), loc, iae);
    } finally {
        mInputStart = ptr;
        mInputLen = end-ptr;
    }
    return count;
}
 
Example #26
Source File: XMLEventFactoryImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void setLocation(javax.xml.stream.Location location) {
    this.location = location;
}
 
Example #27
Source File: XMLEventFactoryWrapper.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setLocation(Location location) {
    defaultImpl.setLocation(location);
}
 
Example #28
Source File: PicketBoxMessages.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Message(id = 85, value = "Missing required attribute(s): %s")
XMLStreamException missingRequiredAttributes(String attributes, @Param Location location);
 
Example #29
Source File: StreamReaderDelegate.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public Location getLocation() {
  return reader.getLocation();
}
 
Example #30
Source File: DomainControllerLogger.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@LogMessage(level = Level.WARN)
@Message(id = 1, value = "Ignoring 'include' child of 'socket-binding-group' %s")
void warnIgnoringSocketBindingGroupInclude(Location location);