org.geotools.xml.Parser.getValidationErrors()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(104)

本文整理了Java中org.geotools.xml.Parser.getValidationErrors()方法的一些代码示例,展示了Parser.getValidationErrors()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser.getValidationErrors()方法的具体详情如下:
包路径:org.geotools.xml.Parser
类名称:Parser
方法名:getValidationErrors

Parser.getValidationErrors介绍

[英]Returns a list of any validation errors that occured while parsing.
[中]返回分析时发生的所有验证错误的列表。

代码示例

代码示例来源:origin: org.geoserver/gs-wfs

public static void checkValidationErrors(Parser parser, XmlRequestReader requestReader) {
  // TODO: HACK, disabling validation for transaction
  if (!"Transaction".equalsIgnoreCase(requestReader.getElement().getLocalPart())) {
    if (!parser.getValidationErrors().isEmpty()) {
      WFSException exception =
          new WFSException("Invalid request", "InvalidParameterValue");
      for (Iterator e = parser.getValidationErrors().iterator(); e.hasNext(); ) {
        Exception error = (Exception) e.next();
        exception.getExceptionText().add(error.getLocalizedMessage());
      }
      throw exception;
    }
  }
}

代码示例来源:origin: geosdi/geo-platform

private List<Exception> validate11(Object input, EntityResolver entityResolver) throws IOException {
  Parser p = createSld11Parser(input, null, entityResolver);
  try {
    p.validate(toReader(input));
    return p.getValidationErrors();
  } catch (Exception e) {
    throw new IOException(e);
  }
}

代码示例来源:origin: org.geoserver/wfsv

public Object read(Object request, Reader reader, Map kvp) throws Exception {
    // TODO: make this configurable?
    configuration.getProperties().add(Parser.Properties.PARSE_UNKNOWN_ELEMENTS);

    Parser parser = new Parser(configuration);

    // set the input source with the correct encoding
    InputSource source = new InputSource(reader);
    source.setEncoding(wfs.getCharSet().name());

    Object parsed = parser.parse(source);

    // valid request? this should definitley be a configuration option
    // TODO: HACK, disabling validation for transaction
    if (!"Transaction".equalsIgnoreCase(getElement().getLocalPart())) {
      if (!parser.getValidationErrors().isEmpty()) {
        WFSException exception = new WFSException("Invalid request", "InvalidParameterValue");

        for (Iterator e = parser.getValidationErrors().iterator(); e.hasNext();) {
          Exception error = (Exception) e.next();
          exception.getExceptionText().add(error.getLocalizedMessage());
        }

        throw exception;
      }
    }

    return parsed;
  }
}

代码示例来源:origin: org.geoserver.extension/wps-core

@SuppressWarnings("unchecked")
  public Object read(Object request, Reader reader, Map kvp) throws Exception {
    Parser parser = new Parser(configuration);
    parser.setValidating(true);

    Object parsed;
    try {
      parsed = parser.parse(reader);
    } catch(Exception e) {
      throw new WPSException("Could not parse XML request.", e);
    }

    if (!parser.getValidationErrors().isEmpty()) {
      WPSException exception = new WPSException("Invalid request", "InvalidParameterValue");

      for(Exception error : (List<Exception>)parser.getValidationErrors()) {
        LOGGER.warning( error.getLocalizedMessage() );
        exception.getExceptionText().add(error.getLocalizedMessage());
      }
    }

    return parsed;
  }
}

代码示例来源:origin: org.geoserver.extension/gs-wps-core

@SuppressWarnings("unchecked")
  public Object read(Object request, Reader reader, Map kvp) throws Exception {
    Parser parser = new Parser(configuration);
    parser.setValidating(true);
    parser.setEntityResolver(resolverProvider.getEntityResolver());

    Object parsed;
    try {
      parsed = parser.parse(reader);
    } catch (Exception e) {
      throw new WPSException("Could not parse XML request.", e);
    }

    if (!parser.getValidationErrors().isEmpty()) {
      WPSException exception = new WPSException("Invalid request", "InvalidParameterValue");

      for (Exception error : (List<Exception>) parser.getValidationErrors()) {
        LOGGER.warning(error.getLocalizedMessage());
        exception.getExceptionText().add(error.getLocalizedMessage());
      }
    }

    return parsed;
  }
}

代码示例来源:origin: org.geoserver.csw/csw-core

@SuppressWarnings("unchecked")
  public Object read(Object request, Reader reader, Map kvp) throws Exception {
    Parser parser = new Parser(configuration);
    parser.setValidating(true);
    parser.setFailOnValidationError(true);
    parser.setStrict(true);

    Object parsed;
    try {
      parsed = parser.parse(reader);
    } catch (Exception e) {
      throw new ServiceException("Could not parse XML request.", e);
    }

    if (!parser.getValidationErrors().isEmpty()) {
      ServiceException exception = new ServiceException("Invalid request",
          "InvalidParameterValue");

      for (Exception error : (List<Exception>) parser.getValidationErrors()) {
        LOGGER.warning(error.getLocalizedMessage());
        exception.getExceptionText().add(error.getLocalizedMessage());
      }
    }

    return parsed;
  }
}

代码示例来源:origin: org.geoserver/gs-wfs

if (strict.booleanValue() && !parser.getValidationErrors().isEmpty()) {
  WFSException exception = new WFSException("Invalid request", "InvalidParameterValue");
  for (Iterator e = parser.getValidationErrors().iterator(); e.hasNext(); ) {
    Exception error = (Exception) e.next();
    exception.getExceptionText().add(error.getLocalizedMessage());

代码示例来源:origin: org.geoserver.csw/gs-csw-core

@SuppressWarnings("unchecked")
  public Object read(Object request, Reader reader, Map kvp) throws Exception {
    Parser parser = new Parser(configuration);
    parser.setValidating(true);
    parser.setFailOnValidationError(true);
    parser.setStrict(true);
    parser.setEntityResolver(resolverProvider.getEntityResolver());

    Object parsed;
    try {
      parsed = parser.parse(reader);
    } catch (Exception e) {
      throw new ServiceException("Could not parse XML request.", e);
    }

    if (!parser.getValidationErrors().isEmpty()) {
      ServiceException exception =
          new ServiceException("Invalid request", "InvalidParameterValue");

      for (Exception error : (List<Exception>) parser.getValidationErrors()) {
        LOGGER.warning(error.getLocalizedMessage());
        exception.getExceptionText().add(error.getLocalizedMessage());
      }
    }

    return parsed;
  }
}

代码示例来源:origin: org.geoserver/wfsv

if (!parser.getValidationErrors().isEmpty()) {
  WFSException exception = new WFSException("Invalid request", "InvalidParameterValue");
  for (Iterator e = parser.getValidationErrors().iterator(); e.hasNext();) {
    Exception error = (Exception) e.next();
    exception.getExceptionText().add(error.getLocalizedMessage());

代码示例来源:origin: org.geoserver.csw/csw-core

/**
 * Validates a document against the
 * 
 * @param dom
 * @param configuration
 */
protected void checkValidationErrors(Document dom, Configuration configuration)
    throws Exception {
  Parser p = new Parser(configuration);
  p.setValidating(true);
  p.parse(new DOMSource(dom));
  if (!p.getValidationErrors().isEmpty()) {
    for (Iterator e = p.getValidationErrors().iterator(); e.hasNext();) {
      SAXParseException ex = (SAXParseException) e.next();
      System.out.println(ex.getLineNumber() + "," + ex.getColumnNumber() + " -"
          + ex.toString());
    }
    fail("Document did not validate.");
  }
}

代码示例来源:origin: org.geoserver.extension/wps-core

/**
 * Validates a document against the 
 * @param dom
 * @param configuration
 */
protected void checkValidationErrors(Document dom, Configuration configuration) throws Exception {
  Parser p = new Parser(configuration);
  p.setValidating( true );
  p.parse( new DOMSource( dom ) );

  if ( !p.getValidationErrors().isEmpty() ) {
    for ( Iterator e = p.getValidationErrors().iterator(); e.hasNext(); ) {
      SAXParseException ex = (SAXParseException) e.next();
      System.out.println( ex.getLineNumber() + "," + ex.getColumnNumber() + " -" + ex.toString()  );
    }
    fail( "Document did not validate.");
  }
}

代码示例来源:origin: org.geoserver/gs-wms

/**
 * Validates a document against the
 *
 * @param dom
 * @param configuration
 */
@SuppressWarnings("rawtypes")
protected void checkWms13ValidationErrors(Document dom) throws Exception {
  Parser p =
      new Parser(
          (Configuration)
              Class.forName("org.geotools.wms.v1_3.WMSConfiguration")
                  .newInstance());
  p.setValidating(true);
  p.parse(new DOMSource(dom));
  if (!p.getValidationErrors().isEmpty()) {
    for (Iterator e = p.getValidationErrors().iterator(); e.hasNext(); ) {
      SAXParseException ex = (SAXParseException) e.next();
      System.out.println(
          ex.getLineNumber() + "," + ex.getColumnNumber() + " -" + ex.toString());
    }
    fail("Document did not validate.");
  }
}

代码示例来源:origin: org.geoserver/gs-wfs

@Test
public void testValid() throws Exception {
  Parser parser = new Parser(configuration());
  parser.parse(getClass().getResourceAsStream("GetFeature.xml"));
  assertEquals(0, parser.getValidationErrors().size());
}

代码示例来源:origin: org.geoserver/gs-wcs2_0

/**
 * Validates a document against the
 *
 * @param dom
 * @param configuration
 */
@SuppressWarnings("rawtypes")
protected void checkValidationErrors(Document dom) throws Exception {
  Parser p = new Parser(new WCSConfiguration());
  p.setValidating(true);
  p.parse(new DOMSource(dom));
  if (!p.getValidationErrors().isEmpty()) {
    for (Iterator e = p.getValidationErrors().iterator(); e.hasNext(); ) {
      SAXParseException ex = (SAXParseException) e.next();
      System.out.println(
          ex.getLineNumber() + "," + ex.getColumnNumber() + " -" + ex.toString());
    }
    fail("Document did not validate.");
  }
}

代码示例来源:origin: org.geoserver/gs-wfs

@Test
  public void testInvalid() throws Exception {
    Parser parser = new Parser(configuration());
    parser.setValidating(true);
    parser.parse(getClass().getResourceAsStream("GetFeature-invalid.xml"));

    assertTrue(parser.getValidationErrors().size() > 0);
  }
}

代码示例来源:origin: org.geoserver/gs-wfs

@Test
public void testValidCapabilitiesDocument() throws Exception {
  print(getAsDOM("wfs?service=WFS&version=2.0.0&request=getCapabilities"));
  InputStream in = get("wfs?service=WFS&version=2.0.0&request=getCapabilities");
  Parser p = new Parser(new WFSConfiguration());
  p.setValidating(true);
  p.validate(in);
  for (Exception e : (List<Exception>) p.getValidationErrors()) {
    System.out.println(e.getLocalizedMessage());
  }
  assertTrue(p.getValidationErrors().isEmpty());
}

代码示例来源:origin: org.geoserver/gs-wfs

@Test
public void testListStoredQueries() throws Exception {
  MockHttpServletResponse response =
      getAsServletResponse("wfs?request=ListStoredQueries&service=wfs&version=2.0.0");
  Document dom = dom(new ByteArrayInputStream(response.getContentAsByteArray()));
  XMLAssert.assertXpathExists(
      "//wfs:StoredQuery[@id = '" + StoredQuery.DEFAULT.getName() + "']", dom);
  // schema validate the response
  FeatureTypeSchemaBuilder sb = new FeatureTypeSchemaBuilder.GML3(getGeoServer());
  WFSConfiguration configuration =
      new WFSConfiguration(getGeoServer(), sb, new org.geoserver.wfs.xml.v1_1_0.WFS(sb));
  Parser parser = new Parser(configuration);
  parser.parse(new ByteArrayInputStream(response.getContentAsByteArray()));
  assertEquals(0, parser.getValidationErrors().size());
}

相关文章