semanticwfs  Version 0.1.0.0
GeoJSONCSSFormatter Class Reference

Reads an ontological style description and formats it to GeoJSONCSS. More...

Inheritance diagram for GeoJSONCSSFormatter:
Collaboration diagram for GeoJSONCSSFormatter:

Public Member Functions

 GeoJSONCSSFormatter ()
 Constructor for this class. More...
 
String formatter (ResultSet results, String featuretype) throws XMLStreamException
 
JSONObject cssLiteralToJSON (String cssString)
 Converts a CSS literal given in the ontology to a JSON representation. More...
 
String formatGeometry (String geometrytype, StyleObject styleobj)
 Formats a geometry according to a given geometrytype using information from a given styleobj. More...
 
String formatHeader ()
 
String formatFooter ()
 

Static Public Member Functions

static ResultStyleFormatter getFormatter (String formatString)
 Gets a style formatter for a chosen style type. More...
 

Public Attributes

Integer lastQueriedElemCount =0
 
String mimeType ="text/plain"
 
String exposedType ="application/vnd.geo+json"
 
String styleAttribute =""
 

Static Public Attributes

static Map< String, ResultStyleFormatterresultMap =new TreeMap<String, ResultStyleFormatter>()
 

Static Package Functions

 [static initializer]
 

Detailed Description

Reads an ontological style description and formats it to GeoJSONCSS.

Constructor & Destructor Documentation

◆ GeoJSONCSSFormatter()

Constructor for this class.

18  {
19  this.styleAttribute="style";
20  }
String styleAttribute
Definition: ResultStyleFormatter.java:24

References ResultStyleFormatter.styleAttribute.

Member Function Documentation

◆ [static initializer]()

[static initializer]
staticpackageinherited

◆ cssLiteralToJSON()

JSONObject cssLiteralToJSON ( String  cssString)

Converts a CSS literal given in the ontology to a JSON representation.

Parameters
cssStringthe literal value
Returns
the JSON object to contain the style information
32  {
33  JSONObject styleproperties=new JSONObject();
34  if(cssString==null)
35  return styleproperties;
36  cssString=cssString.substring(0,cssString.indexOf("^^"));
37  if(cssString.contains(";")) {
38  for(String statement:cssString.split(";")) {
39  String[] split=statement.split(":");
40  styleproperties.put(split[0].replace("\\","").replace("\"","").replace("{","").replace("}","").trim(),
41  split[1].replace("\\","").replace("\"","").replace("{","").replace("}","").trim());
42  }
43  }else if(cssString.contains(",")) {
44  for(String statement:cssString.split(",")) {
45  String[] split=statement.split(":");
46  styleproperties.put(split[0].replace("\\","").replace("\"","").replace("{","").replace("}","").trim(),
47  split[1].replace("\\","").replace("\"","").replace("{","").replace("}","").trim());
48  }
49  }else {
50  String[] split=cssString.split(":");
51  styleproperties.put(split[0].replace("\\","").replace("\"","").replace("{","").replace("}","").trim(),
52  split[1].replace("\\","").replace("\"","").replace("{","").replace("}","").trim());
53  }
54  return styleproperties;
55  }

Referenced by GeoJSONCSSFormatter.formatGeometry().

◆ formatFooter()

String formatFooter ( )
inherited
78  {
79  return "";
80  }

◆ formatGeometry()

String formatGeometry ( String  geometrytype,
StyleObject  styleobj 
)

Formats a geometry according to a given geometrytype using information from a given styleobj.

Parameters
geometrytypethe geometry
styleobjthe styleobject to use for formatting
Returns
the formatString to use for styling

Reimplemented from ResultStyleFormatter.

58  {
59  if(geometrytype.contains("Point")) {
60  JSONObject props=cssLiteralToJSON(styleobj.pointStyle);
61  if(styleobj.pointImage!=null) {
62  JSONObject iconobj=new JSONObject();
63  if(styleobj.pointImage.contains("svg")) {
64  iconobj.put("iconUrl", "url('data:image/svg+xml;utf8,"+styleobj.pointImage+"')");
65  }else if(styleobj.pointImage.contains("http")) {
66  iconobj.put("iconUrl", styleobj.pointImage);
67  }else {
68  iconobj.put("iconUrl", styleobj.pointImage);
69  }
70  JSONArray size=new JSONArray();
71  size.put(32);
72  size.put(32);
73  JSONArray anchor=new JSONArray();
74  size.put(16);
75  size.put(16);
76  iconobj.put("iconSize",size);
77  iconobj.put("iconAnchor", anchor);
78  props.put("icon", iconobj);
79  }
80  System.out.println(props.toString());
81  return props.toString();
82  }
83  if(geometrytype.contains("LineString")) {
84  JSONObject props=cssLiteralToJSON(styleobj.lineStringStyle);
85  if(styleobj.lineStringImage!=null) {
86  JSONObject iconobj=new JSONObject();
87  if(styleobj.lineStringImage.contains("svg")) {
88  iconobj.put("iconUrl", "url('data:image/svg+xml;utf8,"+styleobj.lineStringImage+"')");
89  }else if(styleobj.lineStringImage.contains("http")) {
90  iconobj.put("iconUrl", styleobj.lineStringImage);
91  }else {
92  iconobj.put("iconUrl", styleobj.lineStringImage);
93  }
94  JSONArray size=new JSONArray();
95  size.put(32);
96  size.put(32);
97  JSONArray anchor=new JSONArray();
98  size.put(16);
99  size.put(16);
100  iconobj.put("iconSize",size);
101  iconobj.put("iconAnchor", anchor);
102  props.put("icon", iconobj);
103  }
104  if(styleobj.hatch!=null) {
105  JSONObject hatch=cssLiteralToJSON(styleobj.hatch);
106  props.put("hatch",hatch);
107  }
108  System.out.println(props);
109  return props.toString();
110  }
111  if(geometrytype.contains("Polygon")) {
112  JSONObject props=cssLiteralToJSON(styleobj.polygonStyle);
113  if(styleobj.polygonImage!=null) {
114  JSONObject iconobj=new JSONObject();
115  if(styleobj.polygonImage.contains("svg")) {
116  iconobj.put("iconUrl", "url('data:image/svg+xml;utf8,"+styleobj.polygonImage+"')");
117  }else if(styleobj.polygonImage.contains("http")) {
118  iconobj.put("iconUrl", styleobj.polygonImage);
119  }else {
120  iconobj.put("iconUrl", styleobj.polygonImage);
121  }
122  JSONArray size=new JSONArray();
123  size.put(32);
124  size.put(32);
125  JSONArray anchor=new JSONArray();
126  size.put(16);
127  size.put(16);
128  iconobj.put("iconSize",size);
129  iconobj.put("iconAnchor", anchor);
130  props.put("icon", iconobj);
131  }
132  if(styleobj.hatch!=null) {
133  JSONObject hatch=cssLiteralToJSON(styleobj.hatch);
134  props.put("hatch",hatch);
135  }
136  System.out.println(props);
137  return props.toString();
138  }
139  return "{}";
140  }
JSONObject cssLiteralToJSON(String cssString)
Converts a CSS literal given in the ontology to a JSON representation.
Definition: GeoJSONCSSFormatter.java:32

References GeoJSONCSSFormatter.cssLiteralToJSON(), StyleObject.hatch, StyleObject.lineStringImage, StyleObject.lineStringStyle, StyleObject.pointImage, StyleObject.pointStyle, StyleObject.polygonImage, and StyleObject.polygonStyle.

◆ formatHeader()

String formatHeader ( )
inherited
74  {
75  return "";
76  }

◆ formatter()

String formatter ( ResultSet  results,
String  featuretype 
) throws XMLStreamException
Parameters
results
featuretype
Returns
Exceptions
XMLStreamException

Reimplemented from ResultStyleFormatter.

23  {
24  return null;
25  }

◆ getFormatter()

static ResultStyleFormatter getFormatter ( String  formatString)
staticinherited

Gets a style formatter for a chosen style type.

Parameters
formatStringthe formatString indicating a given style type
Returns
a ResultStyleFormatter generating the chosen style type
31  {
32  formatString=formatString.toLowerCase();
33  if(resultMap.containsKey(formatString)) {
34  return resultMap.get(formatString);
35  }
36  formatString=formatString.replace("+","");
37  if(formatString.contains("mapcss")) {
38  return resultMap.get("mapcss");
39  }
40  if(formatString.contains("geojsoncss")) {
41  return resultMap.get("geojsoncss");
42  }
43  if(formatString.contains("sld")) {
44  return resultMap.get("sld");
45  }
46  return null;
47  }
static Map< String, ResultStyleFormatter > resultMap
Definition: ResultStyleFormatter.java:16

Member Data Documentation

◆ exposedType

String exposedType ="application/vnd.geo+json"
inherited

Referenced by SLDFormatter.formatter().

◆ lastQueriedElemCount

Integer lastQueriedElemCount =0
inherited

◆ mimeType

String mimeType ="text/plain"
inherited

◆ resultMap

Map<String,ResultStyleFormatter> resultMap =new TreeMap<String, ResultStyleFormatter>()
staticinherited

◆ styleAttribute