org.apache.xerces.xni.XMLLocator Java Examples

The following examples show how to use org.apache.xerces.xni.XMLLocator. 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: AbstractLSPErrorReporter.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the LSP position from the SAX location.
 * 
 * @param offset   the adjusted offset.
 * @param location the original SAX location.
 * @param document the text document.
 * @return the LSP position from the SAX location.
 */
private static Position toLSPPosition(int offset, XMLLocator location, TextDocument document) {
	if (location != null && offset == location.getCharacterOffset() - 1) {
		return new Position(location.getLineNumber() - 1, location.getColumnNumber() - 1);
	}
	try {
		return document.positionAt(offset);
	} catch (BadLocationException e) {
		return location != null ? new Position(location.getLineNumber() - 1, location.getColumnNumber() - 1) : null;
	}
}
 
Example #2
Source File: XMLModelHandler.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void startDocument(XMLLocator locator, String encoding, NamespaceContext namespaceContext,
		Augmentations augs) throws XNIException {
	this.locator = locator;
	if (xmlModelValidators != null) {
		for (XMLModelValidator validator : xmlModelValidators) {
			validator.startDocument(locator, encoding, namespaceContext, augs);
		}
	}

	if (documentHandler != null) {
		documentHandler.startDocument(locator, encoding, namespaceContext, augs);
	}
}
 
Example #3
Source File: CMXSDDocument.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the offset where the local xs:complexType is declared and -1
 * otherwise.
 * 
 * @param complexType the local complex type
 * @param grammar     the grammar where local complex type is declared.
 * @return the offset where the local xs:complexType is declared and -1
 *         otherwise.
 */
private static int getComplexTypeOffset(XSComplexTypeDefinition complexType, SchemaGrammar grammar) {
	try {
		// Xerces stores in SchemaGrammar instance, the location in 2 arrays:
		// - fCTLocators array of locator
		// - fComplexTypeDecls array of XSComplexTypeDecl

		// As it's not an API, we must use Java Reflection to get those 2 arrays
		Field f = SchemaGrammar.class.getDeclaredField("fCTLocators");
		f.setAccessible(true);
		SimpleLocator[] fCTLocators = (SimpleLocator[]) f.get(grammar);

		// Find the location offset of the given complexType
		XSComplexTypeDecl[] fComplexTypeDecls = getXSComplexTypeDecls(grammar);
		for (int i = 0; i < fComplexTypeDecls.length; i++) {
			if (complexType.equals(fComplexTypeDecls[i])) {
				XMLLocator locator = fCTLocators[i];
				return locator != null ? locator.getCharacterOffset() : -1;
			}
		}
	} catch (Exception e) {
		LOGGER.log(Level.SEVERE,
				"Error while retrieving offset of local xs:complexType'" + complexType.getName() + "'.", e);
	}
	// Offset where xs:complexType is declared cannot be found
	return -1;
}
 
Example #4
Source File: HTMLSAXParser.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void startDocument(XMLLocator arg0,
                          String arg1,
                          NamespaceContext arg2,
                          Augmentations arg3) throws XNIException {
    super.startDocument(arg0, arg1, arg2, arg3);
    buffer = new StringBuffer();
}
 
Example #5
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 5 votes vote down vote up
/** Start document. */
public void startDocument(XMLLocator locator, String encoding, 
                          NamespaceContext nscontext, Augmentations augs) 
    throws XNIException {

    // reset state
    fElementStack.top = 0;
    if (fragmentContextStack_ != null) {
    	fragmentContextStackSize_ = fragmentContextStack_.length;
    	for (int i=0; i<fragmentContextStack_.length; ++i) {
    		final QName name = fragmentContextStack_[i];
        	final Element elt = HTMLElements.getElement(name.localpart);
        	fElementStack.push(new Info(elt, name));
    	}
    	
    }
    else {
    	fragmentContextStackSize_ = 0;
    }
    fSeenAnything = false;
    fSeenDoctype = false;
    fSeenRootElement = false;
    fSeenRootElementEnd = false;
    fSeenHeadElement = false;
    fSeenBodyElement = false;
    

    // pass on event
    if (fDocumentHandler != null) {
    	XercesBridge.getInstance().XMLDocumentHandler_startDocument(fDocumentHandler, locator, encoding, nscontext, augs);
    }

}
 
Example #6
Source File: NekoHtmlDocumentHandler.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void startDocument(XMLLocator arg0, String arg1,
        NamespaceContext arg2, Augmentations arg3) throws XNIException {
  if(DEBUG_UNUSED) {
    Out.println("startDocument");
  }
}
 
Example #7
Source File: AbstractLSPErrorReporter.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
public String reportError(XMLLocator location, String domain, String key, Object[] arguments, short severity,
		Exception exception) throws XNIException {
	// format message
	MessageFormatter messageFormatter = getMessageFormatter(domain);
	String message;
	if (messageFormatter != null) {
		message = messageFormatter.formatMessage(fLocale, key, arguments);
	} else {
		StringBuilder str = new StringBuilder();
		str.append(domain);
		str.append('#');
		str.append(key);
		int argCount = arguments != null ? arguments.length : 0;
		if (argCount > 0) {
			str.append('?');
			for (int i = 0; i < argCount; i++) {
				str.append(arguments[i]);
				if (i < argCount - 1) {
					str.append('&');
				}
			}
		}
		message = str.toString();
	}

	Range adjustedRange = internalToLSPRange(location, key, arguments, xmlDocument);

	if (adjustedRange == null) {
		return null;
	}

	if (!addDiagnostic(adjustedRange, message, toLSPSeverity(severity), key)) {
		return null;
	}

	if (severity == SEVERITY_FATAL_ERROR && !fContinueAfterFatalError && !isIgnoreFatalError(key)) {
		XMLParseException parseException = (exception != null) ? new XMLParseException(location, message, exception)
				: new XMLParseException(location, message);
		throw parseException;
	}
	return message;
}
 
Example #8
Source File: XMLModelDTDValidator.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void setLocator(XMLLocator locator) {
	this.locator = locator;
}
 
Example #9
Source File: LSPSAXParser.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void startDocument(XMLLocator locator, String encoding, NamespaceContext namespaceContext,
		Augmentations augs) throws XNIException {
	this.locator = locator;
	super.startDocument(locator, encoding, namespaceContext, augs);
}
 
Example #10
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 4 votes vote down vote up
/** Start document. */
public void startDocument(XMLLocator locator, String encoding, Augmentations augs) 
    throws XNIException {
    startDocument(locator, encoding, null, augs);
}
 
Example #11
Source File: ScriptFilter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void startDocument( XMLLocator locator, String encoding, Augmentations augs ) throws XNIException {
    _activeScriptBlock = null;
    _systemID = (locator == null) ? "" : (locator.getLiteralSystemId() + "_");
    _scriptIndex = 0;
    super.startDocument( locator, encoding, augs );
}
 
Example #12
Source File: XMLModelSchemaValidator.java    From lemminx with Eclipse Public License 2.0 2 votes vote down vote up
@Override
public void setLocator(XMLLocator locator) {

}
 
Example #13
Source File: AbstractLSPErrorReporter.java    From lemminx with Eclipse Public License 2.0 votes vote down vote up
protected abstract Range toLSPRange(XMLLocator location, String key, Object[] arguments, DOMDocument document); 
Example #14
Source File: XMLModelValidator.java    From lemminx with Eclipse Public License 2.0 votes vote down vote up
void setLocator(XMLLocator locator);