コード例 #1
0
ファイル: Xml.java プロジェクト: fxprunayre/core-geonetwork
  /**
   * Called by all validation methods to do the real guts of the validation job.
   *
   * @param schema
   * @param xml
   * @param eh
   * @throws Exception
   */
  private static void validateRealGuts(Schema schema, Element xml, ErrorHandler eh)
      throws Exception {

    Resolver resolver = ResolverWrapper.getInstance();

    ValidatorHandler vh = schema.newValidatorHandler();
    vh.setResourceResolver(resolver.getXmlResolver());
    vh.setErrorHandler(eh);

    SAXOutputter so = new SAXOutputter(vh);
    eh.setSo(so);

    so.output(xml);
  }
コード例 #2
0
ファイル: Xml.java プロジェクト: fxprunayre/core-geonetwork
    public void addMessage(SAXParseException exception, String typeOfError) {
      if (errorCount == 0) xpaths = new Element("xsderrors", ns);
      errorCount++;

      Element elem = (Element) so.getLocator().getNode();
      Element x = new Element("xpath", ns);
      try {
        String xpath = jeeves.utils.XPath.getXPath(elem);
        // -- remove the first element to ensure XPath fits XML passed with
        // -- root element
        if (xpath.startsWith("/")) {
          int ind = xpath.indexOf('/', 1);
          if (ind != -1) {
            xpath = xpath.substring(ind + 1);
          } else {
            xpath = "."; // error to be placed on the root element
          }
        }
        x.setText(xpath);
      } catch (JDOMException e) {
        e.printStackTrace();
        x.setText("nopath");
      }
      String message = exception.getMessage() + " (Element: " + elem.getQualifiedName();
      String parentName;
      if (!elem.isRootElement()) {
        Element parent = (Element) elem.getParent();
        if (parent != null) parentName = parent.getQualifiedName();
        else parentName = "Unknown";
      } else {
        parentName = "/";
      }
      message += " with parent element: " + parentName + ")";

      Element m = new Element("message", ns).setText(message);
      Element errorType = new Element("typeOfError", ns).setText(typeOfError);
      Element errorNumber = new Element("errorNumber", ns).setText(String.valueOf(errorCount));
      Element e = new Element("error", ns);
      e.addContent(errorType);
      e.addContent(errorNumber);
      e.addContent(m);
      e.addContent(x);
      xpaths.addContent(e);
    }