semanticwfs  Version 0.1.0.0
SimpleStyleFormatter Class Reference

Reads an ontological style description and formats it according to the mapbox simple style specification. More...

Inheritance diagram for SimpleStyleFormatter:
Collaboration diagram for SimpleStyleFormatter:

Public Member Functions

 SimpleStyleFormatter ()
 Constructor for this class. More...
 
JSONObject cssLiteralToJSON (String cssString)
 Converts a CSS literal given in the ontology to a JSON representation. More...
 
String formatter (ResultSet results, String featuretype) throws XMLStreamException
 
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 according to the mapbox simple style specification.

Constructor & Destructor Documentation

◆ SimpleStyleFormatter()

Constructor for this class.

18  {
19  this.styleAttribute="properties";
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
27  {
28  JSONObject styleproperties=new JSONObject();
29  if(cssString==null)
30  return styleproperties;
31  cssString=cssString.substring(0,cssString.indexOf("^^"));
32  if(cssString.contains(";")) {
33  for(String statement:cssString.split(";")) {
34  String[] split=statement.split(":");
35  styleproperties.put(split[0].replace("\\","").replace("\"","").replace("{","").replace("}","").trim(),
36  split[1].replace("\\","").replace("\"","").replace("{","").replace("}","").trim());
37  }
38  }else if(cssString.contains(",")) {
39  for(String statement:cssString.split(",")) {
40  String[] split=statement.split(":");
41  styleproperties.put(split[0].replace("\\","").replace("\"","").replace("{","").replace("}","").trim(),
42  split[1].replace("\\","").replace("\"","").replace("{","").replace("}","").trim());
43  }
44  }else {
45  String[] split=cssString.split(":");
46  styleproperties.put(split[0].replace("\\","").replace("\"","").replace("{","").replace("}","").trim(),
47  split[1].replace("\\","").replace("\"","").replace("{","").replace("}","").trim());
48  }
49  return styleproperties;
50  }

Referenced by SimpleStyleFormatter.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.

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

References SimpleStyleFormatter.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.

53  {
54  // TODO Auto-generated method stub
55  return null;
56  }

◆ 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