本文整理汇总了Java中org.geotools.xml.Parser类的典型用法代码示例。如果您正苦于以下问题:Java Parser类的具体用法?Java Parser怎么用?Java Parser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Parser类属于org.geotools.xml包,在下文中一共展示了Parser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initRequestParser
import org.geotools.xml.Parser; //导入依赖的package包/类
public static void initRequestParser(Parser parser, WFSInfo wfs, GeoServer geoServer, Map kvp) {
//check the strict flag to determine if we should validate or not
Boolean strict = (Boolean) kvp.get("strict");
if ( strict == null ) {
strict = Boolean.FALSE;
}
//check for cite compliance, we always validate for cite
if ( wfs.isCiteCompliant() ) {
strict = Boolean.TRUE;
}
parser.setValidating(strict.booleanValue());
WFSURIHandler.addToParser(geoServer, parser);
Catalog catalog = geoServer.getCatalog();
//"inject" namespace mappings
parser.getNamespaces().add(new CatalogNamespaceSupport(catalog));
}
示例2: handle
import org.geotools.xml.Parser; //导入依赖的package包/类
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
String requestName = request.getParameter("REQUEST");
if ("GetCapabilities".equalsIgnoreCase(requestName)) {
response.setContentType("application/xml");
response.setStatus(HttpServletResponse.SC_OK);
filterPortAndCopyToResponse(getClass().getResourceAsStream("capabilities_1_0_0.xml"), response);
} else if ("DescribeFeatureType".equalsIgnoreCase(requestName)) {
response.setContentType("text/xml");
response.setStatus(HttpServletResponse.SC_OK);
filterPortAndCopyToResponse(getClass().getResourceAsStream("describeFeatureType.xml"), response);
} else if ("GetFeature".equalsIgnoreCase(requestName)) {
response.setContentType("text/xml; subtype=gml/2.1.2; charset=UTF-8");
response.setStatus(HttpServletResponse.SC_OK);
// create the parser with the filter 1.0 configuration
Configuration configuration = new org.geotools.filter.v1_0.OGCConfiguration();
Parser parser = new Parser(configuration);
try {
Map map = (Map) parser.parse(request.getInputStream());
lastFilter = (Filter) ((Map) map.get("Query")).get("Filter");
} catch (Exception e) {
e.printStackTrace();
}
filterPortAndCopyToResponse(getClass().getResourceAsStream("getFeature.xml"), response);
}
}
示例3: checkGMLFootprint
import org.geotools.xml.Parser; //导入依赖的package包/类
/**
* Check GML Footprint validity
*/
private boolean checkGMLFootprint (String footprint)
{
try
{
Configuration configuration = new GMLConfiguration ();
Parser parser = new Parser (configuration);
parser.parse (new InputSource (new StringReader (footprint)));
return true;
}
catch (Exception e)
{
LOGGER.error("Error in extracted footprint: " + e.getMessage());
return false;
}
}
示例4: checkGMLFootprint
import org.geotools.xml.Parser; //导入依赖的package包/类
/**
* Check GML Footprint validity
*/
public static boolean checkGMLFootprint (String footprint)
{
try
{
Configuration configuration = new GMLConfiguration ();
Parser parser = new Parser (configuration);
Geometry geom =
(Geometry) parser.parse (new InputSource (
new StringReader (footprint)));
if (!geom.isEmpty() && !geom.isValid())
{
LOGGER.error("Wrong footprint");
return false;
}
}
catch (Exception e)
{
LOGGER.error("Error in extracted footprint: " + e.getMessage());
return false;
}
return true;
}
示例5: checkValidationErrors
import org.geotools.xml.Parser; //导入依赖的package包/类
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;
}
}
}
示例6: checkGMLFootprint
import org.geotools.xml.Parser; //导入依赖的package包/类
/**
* Check GML Footprint validity
*/
private boolean checkGMLFootprint (String footprint)
{
try
{
Configuration configuration = new GMLConfiguration ();
Parser parser = new Parser (configuration);
parser.parse (new InputSource (new StringReader (footprint)));
return true;
}
catch (Exception e)
{
LOGGER.error("Error in extracted footprint: " + e.getMessage());
return false;
}
}
示例7: parseGML3
import org.geotools.xml.Parser; //导入依赖的package包/类
/**
* Parses GML3 without specifying a schema location.
*/
public static void parseGML3() throws Exception {
InputStream in = GMLParsing.class.getResourceAsStream( "states.xml");
GMLConfiguration gml = new GMLConfiguration();
Parser parser = new Parser(gml);
parser.setStrict(false);
FeatureCollection features = (FeatureCollection) parser.parse(in);
FeatureIterator i = features.features();
int nfeatures = 0;
while( i.hasNext() ) {
SimpleFeature f = (SimpleFeature) i.next();
System.out.println(f.getID());
nfeatures++;
}
System.out.println("Number of features: " + nfeatures);
}
示例8: schemaParseGML3
import org.geotools.xml.Parser; //导入依赖的package包/类
/**
* Parses GML3 by specifying the schema location.
* <p>
* This example first transforms the original file states.xml, and sets its
* schemaLocation to the states.xsd file.
* </p>
*/
public static void schemaParseGML3() throws Exception {
File xml = setSchemaLocation();
InputStream in = new FileInputStream(xml);
GMLConfiguration gml = new GMLConfiguration();
Parser parser = new Parser(gml);
parser.setStrict(false);
FeatureCollection features = (FeatureCollection) parser.parse(in);
FeatureIterator i = features.features();
int nfeatures = 0;
while( i.hasNext() ) {
SimpleFeature f = (SimpleFeature) i.next();
System.out.println(f.getID());
nfeatures++;
}
System.out.println("Number of features: " + nfeatures);
}
示例9: parseAndInsert
import org.geotools.xml.Parser; //导入依赖的package包/类
public void parseAndInsert() throws Exception {
KMLConfiguration configuration = new KMLConfiguration();
Parser parser = new Parser(configuration);
StringReader reader = new StringReader(kml);
SimpleFeature root = (SimpleFeature) parser.parse(reader);
List<SimpleFeature> features = collect(root);
for (SimpleFeature feature : features) {
String name1 = (String) feature.getAttribute("NAME_0");
String name2 = (String) feature.getAttribute("NAME_1");
String name3 = (String) feature.getAttribute("NAME_2");
String name = (String) feature.getAttribute("name");
String code = (String) feature.getAttribute("HASC_2");
if (name1 != null && name2 != null && name3 != null)
name = name1 + " - " + name2 + " - " + name3;
String subKml = getNextKml();
insertLocation(name, code, subKml);
}
}
示例10: parseRequest
import org.geotools.xml.Parser; //导入依赖的package包/类
public static Object parseRequest(Parser parser, Reader reader, WFSInfo wfs) throws Exception {
//set the input source with the correct encoding
InputSource source = new InputSource(reader);
source.setEncoding(wfs.getGeoServer().getSettings().getCharset());
return parser.parse(source);
}
示例11: read
import org.geotools.xml.Parser; //导入依赖的package包/类
public Object read(Object request, Reader reader, Map kvp) throws Exception {
//TODO: refactor this method to use WFSXmlUtils
Catalog catalog = geoServer.getCatalog();
//check the strict flag to determine if we should validate or not
Boolean strict = (Boolean) kvp.get("strict");
if ( strict == null ) {
strict = Boolean.FALSE;
}
//create the parser instance
Parser parser = new Parser(configuration);
parser.setEntityResolver(entityResolverProvider.getEntityResolver());
//"inject" namespace mappings
parser.getNamespaces().add(new CatalogNamespaceSupport(catalog));
//set validation based on strict or not
parser.setValidating(strict.booleanValue());
WFSURIHandler.addToParser(geoServer, parser);
//parse
Object parsed = parser.parse(reader);
//if strict was set, check for validation errors and throw an exception
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());
}
throw exception;
}
return parsed;
}
示例12: read
import org.geotools.xml.Parser; //导入依赖的package包/类
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);
parser.setEntityResolver(entityResolverProvider.getEntityResolver());
WFSXmlUtils.initRequestParser(parser, wfs, geoServer, kvp);
Object parsed = WFSXmlUtils.parseRequest(parser, reader, wfs);
WFSXmlUtils.checkValidationErrors(parser, this);
return parsed;
}
示例13: GML321GeotoolsParserImpl
import org.geotools.xml.Parser; //导入依赖的package包/类
/**
* <p>Constructor for GML321GeotoolsParserImpl.</p>
*
* @param SRID a int.
* @param strictParsing a boolean.
* @param strictValidating a boolean.
*/
public GML321GeotoolsParserImpl(final int SRID, final boolean strictParsing, final boolean strictValidating) {
this.parserThreadLocal = new ThreadLocal<Parser>() {
@Override
protected Parser initialValue() {
return buildParser(SRID, strictParsing, strictValidating);
}
};
LOGGER.info("Create a parser for SRID: {}, strictParsing: {}, strictValidating: {}", SRID, strictParsing, strictValidating);
}
示例14: buildParser
import org.geotools.xml.Parser; //导入依赖的package包/类
private Parser buildParser(int SRID, boolean strictParsing, boolean strictValidating) {
GMLConfiguration configuration = new GMLConfiguration(true);
GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), SRID);
configuration.setGeometryFactory(geometryFactory);
Parser parser = new Parser(configuration);
parser.setStrict(strictParsing);
parser.setValidating(strictValidating);
return parser;
}
示例15: parseWfs
import org.geotools.xml.Parser; //导入依赖的package包/类
@Override
protected Object parseWfs(InputStream is) throws IOException, SAXException, ParserConfigurationException {
try {
Parser parser = new Parser(m_configuration);
return parser.parse(is);
} finally {
is.close();
}
}