本文整理汇总了Java中javax.xml.transform.dom.DOMLocator类的典型用法代码示例。如果您正苦于以下问题:Java DOMLocator类的具体用法?Java DOMLocator怎么用?Java DOMLocator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DOMLocator类属于javax.xml.transform.dom包,在下文中一共展示了DOMLocator类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTransformerExceptionLocationData
import javax.xml.transform.dom.DOMLocator; //导入依赖的package包/类
/**
* Try to get the best possible location data for a TransformerException.
*
* @param transformerException TransformerException to process
* @param defaultSystemId System Id to use if none is found in the TransformerException.
* @return ExtendedLocationData
*/
public static ExtendedLocationData getTransformerExceptionLocationData(TransformerException transformerException, String defaultSystemId) {
final SourceLocator locator = transformerException.getLocator();
if (locator == null && defaultSystemId == null) {
return null;
} else if (locator == null) {
return new ExtendedLocationData(defaultSystemId, -1, -1, null);
} else {
String description;
if (locator instanceof DOMLocator) {
description = ((DOMLocator) locator).getOriginatingNode().getNodeName();
} else if (locator.getClass().getName().equals("net.sf.saxon.instruct.InstructionDetails")
|| locator.getClass().getName().equals("org.orbeon.saxon.instruct.InstructionDetails")) {
try {
description = locator.getClass().getMethod("getInstructionName", new Class[]{}).invoke(locator).toString();
} catch (Exception e) {
// Let's not consider this a real issue, just clear the description
description = null;
}
} else {
description = null;
}
return new ExtendedLocationData((locator.getSystemId() != null) ? locator.getSystemId() : defaultSystemId, locator.getLineNumber(), locator.getColumnNumber(), description);
}
}
示例2: getLocationMessage
import javax.xml.transform.dom.DOMLocator; //导入依赖的package包/类
private static String getLocationMessage(SourceLocator loc,
XPathContext context)
{
String locmessage = "";
String systemId = null;
int lineNumber = -1;
if (loc instanceof DOMLocator && !"null".equals(((DOMLocator)loc).getOriginatingNode().getNodeName()))
{
locmessage += "at " +
((DOMLocator)loc).getOriginatingNode().getNodeName() + ' ';
}
else if (loc instanceof InstructionInfoProvider) {
String instructionName = getInstructionName(((InstructionInfoProvider)loc),
context);
if (instructionName != null && !"".equals(instructionName)) {
locmessage += "at " + instructionName + ' ';
}
systemId = ((InstructionInfoProvider)loc).getInstructionInfo()
.getSystemId();
lineNumber = ((InstructionInfoProvider)loc).getInstructionInfo()
.getLineNumber();
}
if (lineNumber == -1) {
lineNumber = loc.getLineNumber();
}
if (lineNumber != -1) {
locmessage += "on line " + lineNumber + ' ';
}
if (loc.getColumnNumber() != -1) {
locmessage += "column " + loc.getColumnNumber() + ' ';
}
if (systemId == null) {
systemId = loc.getSystemId();
}
if (systemId != null) {
locmessage += "of " + systemId + ':';
}
return locmessage;
}