コード例 #1
0
ファイル: GsRest.java プロジェクト: mixun/gsrcj
  /**
   * This method does not upload a shapefile via zip. It rather creates a reference to a Shapefile
   * that has already exists in the GS data directory.
   *
   * @param charset defaults to UTF-8 if not set. Charset, that any text content is stored in.
   * @param relpath A path to the file, relative to gsdata dir, e.g. "file:data/water.shp"
   */
  public boolean createDatastoreShapefile(
      String workspace,
      String dsName,
      String dsNamespace,
      String relpath,
      String charset,
      Boolean memoryMappedBuffer,
      Boolean createSpatialIndex,
      Configure autoConfig)
      throws IOException {

    if (autoConfig == Configure.first) autoConfig = null;

    if (relpath == null) throw new IllegalArgumentException("parameter relpath may not be null");

    String createSpatialIndexParam = RestUtil.entryKey("create spatial index", createSpatialIndex);

    String memoryMappedBufferParamter =
        RestUtil.entryKey("memory mapped buffer", memoryMappedBuffer);

    String charsetParamter =
        "<entry key=\"charset\">" + (charset == null ? "UTF-8" : charset) + "</entry>";

    String urlParamter = "<entry key=\"url\">" + relpath + "</entry>";

    String namespaceParamter = "<entry key=\"namespace\">" + dsName + "</entry>";

    String typeParamter = "<type>Shapefile</type>";

    String xml =
        "<dataStore><name>"
            + dsName
            + "</name><enabled>true</enabled>"
            + typeParamter
            + "<connectionParameters>"
            + createSpatialIndexParam
            + memoryMappedBufferParamter
            + charsetParamter
            + urlParamter
            + namespaceParamter
            + typeParamter
            + "</connectionParameters></dataStore>";

    String configureParam = autoConfig == null ? "" : "?configure=" + autoConfig.toString();

    int returnCode =
        sendRESTint(
            METHOD_POST, "/workspaces/" + workspace + "/datastores.xml" + configureParam, xml);
    return 201 == returnCode;
  }