GeoserverConfig.Styles (GeoserverConfig v0.4.0)

Copy Markdown View Source

Provides functions to manage styles in GeoServer via the REST API.

All functions require a GeoserverConfig.Connection as their first argument, except write_sld_file/2 which is a local file operation.

Summary

Functions

Copies a style from one workspace to another or between workspace and global scope.

Creates a new style in GeoServer.

Retrieves the SLD content for a specific style.

Lists all global styles available in GeoServer.

Lists all styles scoped to a specific workspace.

Moves a style from one workspace to another or between workspace and global scope.

Updates an existing style's content.

Writes SLD content to a local file. Does not require a connection.

Functions

copy_style(conn, source_style, source_workspace, target_style, target_workspace, opts \\ [])

Copies a style from one workspace to another or between workspace and global scope.

Parameters

  • conn — a GeoserverConfig.Connection
  • source_style — name of the style to copy
  • source_workspace — source workspace, or nil for global styles
  • target_style — name for the copied style (can be same as source)
  • target_workspace — target workspace, or nil for global scope
  • opts — options including :format (:sld or :css, auto-detected if nil)

Returns

  • {:ok, target_style} on success
  • {:error, reason} on failure

create_style(conn, opts)

Creates a new style in GeoServer.

Parameters

  • conn — a GeoserverConfig.Connection
  • opts — map with:
    • :name (required) — style name
    • :content (required) — style content (SLD XML or CSS)
    • :format:sld (default) or :css
    • :workspace — workspace name (optional, nil for global)
    • :filename — filename (optional)
    • :title — style title (optional)
    • :abstract — style description (optional)
    • :keywords — list of keywords (optional)

Returns

  • {:ok, style_name} on success
  • {:error, %{status: status, body: body}} on HTTP failure
  • {:error, reason} on transport error

delete_style(conn, style_name, workspace \\ nil, opts \\ [])

Deletes a style from GeoServer.

Parameters

  • conn — a GeoserverConfig.Connection
  • style_name — name of the style to delete
  • workspace — workspace of the style, or nil for global styles (default: nil)
  • opts:purge and/or :recurse (both boolean, default false)

Returns

  • {:ok, style_name} on success
  • {:skipped, style_name} if the style does not exist (idempotent)
  • {:error, {:http_error, status, body}} on other HTTP failure
  • {:error, {:request_failed, reason}} on transport error

get_style(conn, workspace, style_name)

Retrieves the SLD content for a specific style.

Pass nil or "" as workspace to fetch a global style.

Returns

  • {:ok, sld_content} on success
  • {:error, {:not_found, style_name}} when the style does not exist
  • {:error, {:http_error, status, body}} on other HTTP failure
  • {:error, {:request_failed, reason}} on transport error

list_styles(conn)

Lists all global styles available in GeoServer.

Returns

  • {:ok, [style]} on success
  • {:error, {:http_error, status, body}} on non-200 response
  • {:error, {:request_failed, reason}} on transport error

list_styles_workspace_specific(conn, workspace)

Lists all styles scoped to a specific workspace.

Returns

  • {:ok, [style]} on success
  • {:error, {:http_error, status, body}} on non-200 response
  • {:error, {:request_failed, reason}} on transport error

move_style(conn, style_name, source_workspace, target_workspace, opts \\ [])

Moves a style from one workspace to another or between workspace and global scope.

Parameters

  • conn — a GeoserverConfig.Connection
  • style_name — name of the style to move
  • source_workspace — source workspace, or nil for global styles
  • target_workspace — target workspace, or nil for global scope
  • opts — options including :purge (boolean, default false)

Returns

  • {:ok, style_name} on success
  • {:error, reason} on failure

update_style(conn, opts)

Updates an existing style's content.

Parameters

  • conn — a GeoserverConfig.Connection
  • opts — map with:
    • :name (required) — style name
    • :content (required) — style content (SLD XML or CSS)
    • :format:sld (default) or :css
    • :workspace — workspace name (optional, nil for global)
    • :filename — filename (optional)

Returns

  • {:ok, style_name} on success
  • {:error, {:http_error, status, body}} on failure
  • {:error, {:request_failed, reason}} on transport error

write_sld_file(style_file_path, sld_content)

Writes SLD content to a local file. Does not require a connection.

Returns

  • {:ok, %{file_path: path, size: bytes}} on success
  • {:error, {:file_write_failed, reason, file_path}} on failure