Java 类javax.xml.transform.dom.DOMLocator 实例源码

项目:orbeon-forms    文件:StringErrorListener.java   
/**
 * 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);
    }
}
项目:dash-xtf    文件:XTFSaxonErrorListener.java   
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;
}