org.geotools.xml.Parser类的使用及代码示例

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

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

Parser介绍

[英]Main interface to the geotools xml parser.

Schema Resolution

See org.geotools.xml.Configuration javadocs for instructions on how to customize schema resolution. This is often desirable in the case that the instance document being parsed contains invalid uri's in schema imports and includes.
[中]geotools xml解析器的主接口。
####模式解析
见org。地理工具。xml。有关如何自定义模式解析的说明,请参阅Configuration javadocs。如果正在解析的实例文档在模式导入和includes中包含无效的uri,这通常是可取的。

代码示例

代码示例来源:origin: stackoverflow.com

private Route directions(final GeoPoint start, final GeoPoint dest) {
  Parser parser;
  //https://developers.google.com/maps/documentation/directions/#JSON <- get api
  String jsonURL = "http://maps.googleapis.com/maps/api/directions/json?";
  final StringBuffer sBuf = new StringBuffer(jsonURL);
  sBuf.append("origin=");
  sBuf.append(start.getLatitudeE6()/1E6);
  sBuf.append(',');
  sBuf.append(start.getLongitudeE6()/1E6);
  sBuf.append("&destination=");
  sBuf.append(dest.getLatitudeE6()/1E6);
  sBuf.append(',');
  sBuf.append(dest.getLongitudeE6()/1E6);
  sBuf.append("&sensor=true&mode=driving");
  parser = new GoogleParser(sBuf.toString());
  Route r =  parser.parse();
  return r;
}

代码示例来源:origin: stackoverflow.com

var mid_parser = new Parser();
Parser.apply(mid_parser, mid_patterns);

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

@Test
public void testNativeType() throws Exception {
  Parser p = new Parser(getXmlConfiguration11());
  NativeType nativ =
      (NativeType)
          p.parse(
              new ByteArrayInputStream(
                  "<wfs:Native safeToIgnore='true' xmlns:wfs='http://www.opengis.net/wfs'>here is some text</wfs:Native>"
                      .getBytes()));
  assertEquals("here is some text", nativ.getValue());
}

代码示例来源:origin: stackoverflow.com

byte[] raw = content.getContent();
ContentHandler handler = new BodyContentHandler();
Metadata metadata = new Metadata();
Parser parser = new AutoDetectParser();
parser.parse(new ByteArrayInputStream(raw), handler, metadata, new ParseContext());
LOG.info("content: " + handler.toString());

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

@Test
public void testInsert() throws Exception {
  WFSConfiguration xmlConfiguration11 = getXmlConfiguration11();
  Parser p = new Parser(xmlConfiguration11);
  p.setHandleMixedContent(true);
      (TransactionType) p.parse(new ByteArrayInputStream(request.getBytes()));
  InsertElementType insert = (InsertElementType) obj.getInsert().get(0);
  SimpleFeature feature = (SimpleFeature) insert.getFeature().get(0);

代码示例来源:origin: stackoverflow.com

ByteArrayInputStream bai = new ByteArrayInputStream(pByte);
   ContentHandler contenthandler = new BodyContentHandler();
   Metadata metadata = new Metadata();
   Parser parser = new AutoDetectParser();
   try {
      parser.parse(bai, contenthandler, metadata);
   } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
   } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
   } catch (TikaException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
   }           
   System.out.println("Mime: " + metadata.get(Metadata.CONTENT_TYPE));
   return metadata.get(Metadata.CONTENT_TYPE);

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

@Override
public Object decode(InputStream input) throws Exception {
  Parser p = getParser(configuration);
  byte[] streamBytes = null;
  if (LOGGER.isLoggable(Level.FINEST)) {
    // allow WFS result to be logged for debugging purposes
    // WFS result can be large, so use only for debugging
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ByteStreams.copy(input, outputStream);
    streamBytes = outputStream.toByteArray();
    input = new ByteArrayInputStream(streamBytes);
  }
  Object result = p.parse(input);
  if (result instanceof FeatureCollectionType) {
    FeatureCollectionType fct = (FeatureCollectionType) result;
    return decode(fct);
  } else {
    if (LOGGER.isLoggable(Level.FINEST)) {
      LOGGER.log(
          Level.FINEST,
          "Decoding the following WFS response did not result in an object of type FeatureCollectionType: \n"
              + new String(streamBytes));
    }
    throw new IllegalArgumentException(
        "Decoded WFS result is not a feature collection, got a: " + result);
  }
}

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

Filter filter;
final byte[] rawContent = string.getBytes();
InputStream input = new ByteArrayInputStream(rawContent);
  Parser parser_1_0_0 = new Parser(configuration);
  parser_1_0_0.setEntityResolver(resolverProvider.getEntityResolver());
  filter = (Filter) parser_1_0_0.parse(input);
} catch (Exception e) {
    input = new ByteArrayInputStream(rawContent);
    Configuration configuration =
        new org.geotools.filter.v1_1.OGCConfiguration();
    Parser parser_1_1_0 = new Parser(configuration);
    parser_1_1_0.setEntityResolver(resolverProvider.getEntityResolver());
    filter = (Filter) parser_1_1_0.parse(input);

代码示例来源: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());
}

代码示例来源:origin: stackoverflow.com

ContentHandler contenthandler = new BodyContentHandler();
Metadata metadata = new Metadata();
metadata.set(Metadata.RESOURCE_NAME_KEY, f.getName());
Parser parser = new AutoDetectParser();
// OOXMLParser parser = new OOXMLParser();
parser.parse(is, contenthandler, metadata);
System.out.println("Mime: " + metadata.get(Metadata.CONTENT_TYPE));
System.out.println("Title: " + metadata.get(Metadata.TITLE));
System.out.println("Author: " + metadata.get(Metadata.AUTHOR));
System.out.println("content: " + contenthandler.toString());

代码示例来源:origin: stackoverflow.com

HttpGet httpget = new HttpGet("http://url.here"); 
 HttpEntity entity = null;
 HttpClient client = new DefaultHttpClient();
 HttpResponse response = client.execute(httpget);
 entity = response.getEntity();
 if (entity != null) {
   InputStream instream = entity.getContent();
   BodyContentHandler handler = new BodyContentHandler();
   Metadata metadata = new Metadata();
   Parser parser = new AutoDetectParser();
   parser.parse( instream, handler, metadata, new ParseContext());
   String plainText = handler.toString();
   FileWriter writer = new FileWriter( "/scratch/cache/output.txt");
   writer.write( plainText );
   writer.close();
   System.out.println( "done");
 }

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
     String fileLocation = "C:/desktopname/songs/song.mp3";
     try {
     InputStream input = new FileInputStream(new File(fileLocation));
     ContentHandler handler = new DefaultHandler();
     Metadata metadata = new Metadata();
     Parser parser = new Mp3Parser();
     ParseContext parseCtx = new ParseContext();
     parser.parse(input, handler, metadata, parseCtx);
     input.close();
     // List all metadata
     String[] metadataNames = metadata.names();
     for(String name : metadataNames){
     System.out.println(name + ": " + metadata.get(name));
     }
     // Retrieve the necessary info from metadata
     // Names - title, xmpDM:artist etc. - mentioned below may differ based
     System.out.println("----------------------------------------------");
     System.out.println("Title: " + metadata.get("title"));
     System.out.println("Artists: " + metadata.get("xmpDM:artist"));
     System.out.println("Composer : "+metadata.get("xmpDM:composer"));
     System.out.println("Genre : "+metadata.get("xmpDM:genre"));
     System.out.println("Album : "+metadata.get("xmpDM:album"));
     } catch (Exception e) { } 
 }

代码示例来源:origin: stackoverflow.com

InputStream is = new FileInputStream("/home/rahul/Music/03 - I Like Your Music.mp3");

Parser parser = new AutoDetectParser();
BodyContentHandler handler = new BodyContentHandler();

Metadata metadata = new Metadata();
parser.parse(is, handler, metadata, new ParseContext());

String handler = handler.toString();
System.out.println("Handler data: " + handler);
System.out.println(metadata.get(Metadata.CREATION_DATE));
System.out.println(metadata.get(Metadata.LAST_MODIFIED));

代码示例来源:origin: stackoverflow.com

Metadata metadata = new Metadata();
metadata.set(Metadata.RESOURCE_NAME_KEY, filename);
ParseContext context = new ParseContext();

Parser parser = new AutoDetectParser();
parser.parse(input, textHandler, metadata, new ParseContext());

代码示例来源: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/wcs1_1

public Object read(Object request, Reader reader, Map kvp) throws Exception {
    //create the parser instance
    Parser parser = new Parser(configuration);
    parser.setValidating(true);
    parser.setFailOnValidationError(true);
    parser.setStrict(true);
    
    // parse
    Object parsed;
    try {
      parsed = parser.parse(reader);
    } catch(Exception e) {
      throw new WcsException("Parsing failed, the xml request is most probably not compliant to the wcs schema", e);
    }
    
    return parsed;
  }
}

代码示例来源:origin: stackoverflow.com

TikaInputStream docxStream = TikaInputStream.get(new File("some-doc.docx"));
TikaInputStream pdfStream = TikaInputStream.get(new File("some-doc.pdf"));

ContentHandler handler = new DefaultContentHandler();
Metadata docxMeta = new Metadata();
Metadata pdfMeta = new Metadata();
ParseContext pc = new ParseContext();

Parser parser = TikaConfig.getDefaultConfig().getParser();

parser.parse(docxStream, handler, docxMeta, pc);
parser.parse(pdfStream, handler, pdfMeta, pc);

int docxParagraphCount = docxMeta.getInt(Office.PARAGRAPH_COUNT);
int pdfParagraphCount = pdfMeta.getInt(Office.PARAGRAPH_COUNT);

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

@SuppressWarnings("rawtypes")
  public Object read(Object request, Reader reader, Map kvp) throws Exception {
    // create the parser instance
    Parser parser = new Parser(configuration);
    parser.setEntityResolver(resolverProvider.getEntityResolver());

    // uncomment this once we have a working validator (now it fails due to
    // xlink issues)
    //        parser.setValidating(true);
    //        parser.setFailOnValidationError(true);
    //        parser.setStrict(true);

    // parse
    Object parsed;
    try {
      parsed = parser.parse(reader);
    } catch (Exception e) {
      throw new WcsException(
          "Parsing failed, the xml request is most probably not compliant to the wcs 2.0.1 schema",
          e);
    }

    return parsed;
  }
}

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

@Override
public Object decode(InputStream input) throws Exception {
  Parser p = new Parser( xml );
  return p.parse( input );
}

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

} else if (FILTER.equals(language)) {
  try {
    Parser parser = new Parser(new OGCConfiguration());
    parser.setFailOnValidationError(true);
    parser.setValidating(true);
    parser.setEntityResolver(resolverProvider.getEntityResolver());
    parser.getNamespaces().declarePrefix("ogc", OGC.NAMESPACE);
    Filter filter = (Filter) parser.parse(new StringReader(constraint));
    query.getConstraint().setFilter(filter);
    query.getConstraint().setVersion("1.1.0");

相关文章