GeoPubby  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...
 
JSONObject formatForWebView (StyleObject obj)
 
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]
 

Package Attributes

Map< String, String > attributeMap
 

Detailed Description

Reads an ontological style description and formats it to GeoJSONCSS.

Constructor & Destructor Documentation

◆ GeoJSONCSSFormatter()

Constructor for this class.

25  {
26  this.styleAttribute="style";
27  this.attributeMap=new TreeMap<>();
28  this.attributeMap.put("fill", "fillColor");
29  this.attributeMap.put("stroke", "color");
30  this.attributeMap.put("stroke-width", "weight");
31  this.attributeMap.put("stroke-linejoin", "lineJoin");
32  }
Map< String, String > attributeMap
Definition: GeoJSONCSSFormatter.java:20
String styleAttribute
Definition: ResultStyleFormatter.java:26

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
46  {
47  JSONObject styleproperties=new JSONObject();
48  if(cssString==null)
49  return styleproperties;
50  if(cssString.contains("^^"))
51  cssString=cssString.substring(0,cssString.indexOf("^^"));
52  if(cssString.contains(";")) {
53  for(String statement:cssString.split(";")) {
54  String[] split=statement.split(":");
55  String key=split[0].replace("\\","").replace("\"","").replace("{","").replace("}","").trim();
56  if(this.attributeMap.containsKey(key)) {
57  key=this.attributeMap.get(key);
58  }
59  styleproperties.put(key,
60  split[1].replace("\\","").replace("\"","").replace("{","").replace("}","").trim());
61  }
62  }else if(cssString.contains(",")) {
63  for(String statement:cssString.split(",")) {
64  String[] split=statement.split(":");
65  String key=split[0].replace("\\","").replace("\"","").replace("{","").replace("}","").trim();
66  if(this.attributeMap.containsKey(key)) {
67  key=this.attributeMap.get(key);
68  }
69  styleproperties.put(key,
70  split[1].replace("\\","").replace("\"","").replace("{","").replace("}","").trim());
71  }
72  }else {
73  String[] split=cssString.split(":");
74  String key=split[0].replace("\\","").replace("\"","").replace("{","").replace("}","").trim();
75  if(this.attributeMap.containsKey(key)) {
76  key=this.attributeMap.get(key);
77  }
78  styleproperties.put(key,
79  split[1].replace("\\","").replace("\"","").replace("{","").replace("}","").trim());
80  }
81  return styleproperties;
82  }

Referenced by GeoJSONCSSFormatter.formatGeometry().

◆ formatFooter()

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

◆ formatForWebView()

JSONObject formatForWebView ( StyleObject  obj)
84  {
85  JSONObject result=new JSONObject();
86  result.put("name", obj.styleName);
87  result.put("id", obj.styleId);
88  result.put("Point", new JSONObject(formatGeometry("Point",obj)));
89  result.put("LineString", new JSONObject(formatGeometry("LineString",obj)));
90  result.put("Polygon", new JSONObject(formatGeometry("Polygon",obj)));
91  return result;
92  }
String formatGeometry(String geometrytype, StyleObject styleobj)
Formats a geometry according to a given geometrytype using information from a given styleobj.
Definition: GeoJSONCSSFormatter.java:95

References GeoJSONCSSFormatter.formatGeometry(), StyleObject.styleId, and StyleObject.styleName.

Referenced by PageURLServlet.doGet().

◆ 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.

95  {
96  if(styleobj==null)
97  return "{}";
98  if(geometrytype.contains("Point")) {
99  JSONObject props=cssLiteralToJSON(styleobj.pointStyle);
100  if(styleobj.pointImage!=null) {
101  JSONObject iconobj=new JSONObject();
102  if(styleobj.pointImage.contains("svg")) {
103  iconobj.put("iconUrl", "url('data:image/svg+xml;utf8,"+styleobj.pointImage+"')");
104  }else if(styleobj.pointImage.contains("http")) {
105  iconobj.put("iconUrl", styleobj.pointImage);
106  }else {
107  iconobj.put("iconUrl", styleobj.pointImage);
108  }
109  JSONArray size=new JSONArray();
110  size.put(32);
111  size.put(32);
112  JSONArray anchor=new JSONArray();
113  size.put(16);
114  size.put(16);
115  iconobj.put("iconSize",size);
116  iconobj.put("iconAnchor", anchor);
117  props.put("icon", iconobj);
118  }
119  System.out.println(props.toString());
120  return props.toString();
121  }
122  if(geometrytype.contains("LineString")) {
123  JSONObject props=cssLiteralToJSON(styleobj.lineStringStyle);
124  if(styleobj.lineStringImage!=null) {
125  JSONObject iconobj=new JSONObject();
126  if(styleobj.lineStringImage.contains("svg")) {
127  iconobj.put("iconUrl", "url('data:image/svg+xml;utf8,"+styleobj.lineStringImage+"')");
128  }else if(styleobj.lineStringImage.contains("http")) {
129  iconobj.put("iconUrl", styleobj.lineStringImage);
130  }else {
131  iconobj.put("iconUrl", styleobj.lineStringImage);
132  }
133  JSONArray size=new JSONArray();
134  size.put(32);
135  size.put(32);
136  JSONArray anchor=new JSONArray();
137  size.put(16);
138  size.put(16);
139  iconobj.put("iconSize",size);
140  iconobj.put("iconAnchor", anchor);
141  props.put("icon", iconobj);
142  }
143  if(styleobj.hatch!=null) {
144  JSONObject hatch=cssLiteralToJSON(styleobj.hatch);
145  props.put("hatch",hatch);
146  }
147  System.out.println(props);
148  return props.toString();
149  }
150  if(geometrytype.contains("Polygon")) {
151  JSONObject props=cssLiteralToJSON(styleobj.polygonStyle);
152  if(styleobj.polygonImage!=null) {
153  JSONObject iconobj=new JSONObject();
154  if(styleobj.polygonImage.contains("svg")) {
155  iconobj.put("iconUrl", "url('data:image/svg+xml;utf8,"+styleobj.polygonImage+"')");
156  }else if(styleobj.polygonImage.contains("http")) {
157  iconobj.put("iconUrl", styleobj.polygonImage);
158  }else {
159  iconobj.put("iconUrl", styleobj.polygonImage);
160  }
161  JSONArray size=new JSONArray();
162  size.put(32);
163  size.put(32);
164  JSONArray anchor=new JSONArray();
165  size.put(16);
166  size.put(16);
167  iconobj.put("iconSize",size);
168  iconobj.put("iconAnchor", anchor);
169  props.put("icon", iconobj);
170  }
171  if(styleobj.hatch!=null) {
172  JSONObject hatch=cssLiteralToJSON(styleobj.hatch);
173  props.put("hatch",hatch);
174  }
175  System.out.println(props);
176  return props.toString();
177  }
178  return "{}";
179  }
JSONObject cssLiteralToJSON(String cssString)
Converts a CSS literal given in the ontology to a JSON representation.
Definition: GeoJSONCSSFormatter.java:46

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

Referenced by GeoJSONCSSFormatter.formatForWebView(), and AbstractGeoJSONWriter.prepareGeoJSONString().

◆ 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.

35  {
36  return null;
37  }

◆ 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
33  {
34  formatString=formatString.toLowerCase();
35  if(resultMap.containsKey(formatString)) {
36  return resultMap.get(formatString);
37  }
38  formatString=formatString.replace("+","");
39  if(formatString.contains("mapcss")) {
40  return resultMap.get("mapcss");
41  }
42  if(formatString.contains("geojsoncss")) {
43  return resultMap.get("geojsoncss");
44  }
45  if(formatString.contains("sld")) {
46  return resultMap.get("sld");
47  }
48  return null;
49  }
static Map< String, ResultStyleFormatter > resultMap
Definition: ResultStyleFormatter.java:18

Member Data Documentation

◆ attributeMap

Map<String,String> attributeMap
package

◆ exposedType

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

◆ lastQueriedElemCount

Integer lastQueriedElemCount =0
inherited

◆ mimeType

String mimeType ="text/plain"
inherited

◆ resultMap

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

◆ styleAttribute

String styleAttribute =""
inherited