semanticwfs  Version 0.1.0.0
KMLStyleFormatter Class Reference

Reads an ontological style description and formats it to KML Styles. More...

Inheritance diagram for KMLStyleFormatter:
Collaboration diagram for KMLStyleFormatter:

Public Member Functions

 KMLStyleFormatter ()
 Constructor for this class. More...
 
String formatter (ResultSet results, String featuretype) throws XMLStreamException
 
Map< String, String > cssLiteralToMap (String cssString)
 Converts a CSS literal to a KML representation to include in a KML document. More...
 
void cssLiteralToKML (Map< String, String > cssMap, String geomtype, XMLStreamWriter writer) throws XMLStreamException
 Converts a CSS literal which has been converted to a map to KML and appends it to the XML produced by the writer. 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

Map< String, Map< String, String > > tagMap
 A map which includes tags which are relevant for specific geometry types. More...
 
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 KML Styles.

Constructor & Destructor Documentation

◆ KMLStyleFormatter()

Constructor for this class.

30  {
31  this.tagMap=new TreeMap<>();
32  this.tagMap.put("Point",new TreeMap<String,String>());
33  this.tagMap.put("LineString",new TreeMap<String,String>());
34  this.tagMap.get("LineString").put("stroke","");
35  this.tagMap.get("LineString").put("stroke-width","width");
36  this.tagMap.put("Polygon",new TreeMap<String,String>());
37  this.tagMap.get("Polygon").put("stroke","");
38  this.tagMap.get("Polygon").put("stroke-width","width");
39  }
Map< String, Map< String, String > > tagMap
A map which includes tags which are relevant for specific geometry types.
Definition: KMLStyleFormatter.java:25

Member Function Documentation

◆ [static initializer]()

[static initializer]
staticpackageinherited

◆ cssLiteralToKML()

void cssLiteralToKML ( Map< String, String >  cssMap,
String  geomtype,
XMLStreamWriter  writer 
) throws XMLStreamException

Converts a CSS literal which has been converted to a map to KML and appends it to the XML produced by the writer.

Parameters
cssMapthe map of css statements
geomtypethe geometry type to which the CSS style is applied
writerthe XMLStreamWriter to write the results with
Exceptions
XMLStreamExceptionwhen a XML writing error occurs
87  {
88  if(geomtype.equals("Polygon")) {
89  writer.writeStartElement("PolyStyle");
90  if(cssMap.containsKey("color")) {
91  writer.writeStartElement("color");
92  writer.writeCharacters(cssMap.get("color"));
93  writer.writeEndElement();
94  writer.writeStartElement("colorMode");
95  writer.writeCharacters("normal");
96  writer.writeEndElement();
97  }
98  if(cssMap.containsKey("fill")) {
99  writer.writeStartElement("fill");
100  writer.writeCharacters(cssMap.get("fill").replace("\\\"","").replace("^","").replace("http","").replace("true","1").replace("false","0").trim());
101  writer.writeEndElement();
102  }
103  if(cssMap.containsKey("stroke")) {
104  writer.writeStartElement("outline");
105  writer.writeCharacters(cssMap.get("stroke").replace("\\\"","").replace("^","").replace("http","").replace("true","1").replace("false","0").trim());
106  writer.writeEndElement();
107  }
108  writer.writeEndElement();
109  }else if(geomtype.equals("LineString")) {
110  writer.writeStartElement("LineStyle");
111  if(cssMap.containsKey("color")) {
112  writer.writeStartElement("color");
113  writer.writeCharacters(cssMap.get("color"));
114  writer.writeEndElement();
115  writer.writeStartElement("colorMode");
116  writer.writeCharacters("normal");
117  writer.writeEndElement();
118  }
119  if(cssMap.containsKey("stroke-width")) {
120  writer.writeStartElement("width");
121  writer.writeCharacters(cssMap.get("stroke-width"));
122  writer.writeEndElement();
123  }
124  writer.writeEndElement();
125  }else if(geomtype.equals("Point")) {
126  if(cssMap.containsKey("color")) {
127  writer.writeStartElement("color");
128  writer.writeCharacters(cssMap.get("color"));
129  writer.writeEndElement();
130  writer.writeStartElement("colorMode");
131  writer.writeCharacters("normal");
132  writer.writeEndElement();
133  }
134  if(cssMap.containsKey("stroke-width")) {
135  writer.writeStartElement("width");
136  writer.writeCharacters(cssMap.get("stroke-width"));
137  writer.writeEndElement();
138  }
139  }
140 
141  }

Referenced by KMLStyleFormatter.formatGeometry().

◆ cssLiteralToMap()

Map<String,String> cssLiteralToMap ( String  cssString)

Converts a CSS literal to a KML representation to include in a KML document.

Parameters
cssStringthe css String contained in the literal
Returns
A map of style attributes to include into the KML representation.
52  {
53  Map<String,String> result=new TreeMap<String,String>();
54  if(cssString.contains(";")) {
55  for(String statement:cssString.split(";")) {
56  String[] split=statement.split(":");
57  if(!split[1].trim().isEmpty()) {
58  String key=split[0].replace("\\\"","").trim();
59  result.put(key,split[1].replace("\\\"","").replace("^","").replace("http","").replace("true","1").trim());
60  }
61  }
62  }else if(cssString.contains(",")) {
63  for(String statement:cssString.split(",")) {
64  String[] split=statement.split(":");
65  if(!split[1].trim().isEmpty()) {
66  String key=split[0].replace("\\\"","").trim();
67  result.put(key,split[1].replace("\\\"","").replace("^","").replace("http","").replace("true","1").trim());
68  }
69  }
70  }else {
71  String[] split=cssString.split(":");
72  if(!split[1].trim().isEmpty()) {
73  String key=split[0].replace("\\\"","").trim();
74  result.put(key,split[1].replace("\\\"","").replace("^","").replace("http","").replace("true","1").trim());
75  }
76  }
77  return result;
78  }

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

144  {
145  if(styleobj==null)
146  return "";
147  System.out.println(geometrytype);
148  XMLOutputFactory factory = XMLOutputFactory.newInstance();
149  StringWriter strwriter=new StringWriter();
150  try {
151  XMLStreamWriter writer=new IndentingXMLStreamWriter(factory.createXMLStreamWriter(strwriter));
152 
153  writer.flush();
154  if(geometrytype.contains("Point") && styleobj.pointStyle!=null && !styleobj.pointStyle.trim().isEmpty()) {
155  writer.writeStartElement("IconStyle");
156  writer.writeCharacters("");
157  cssLiteralToKML(cssLiteralToMap(styleobj.pointStyle),"Point",writer);
158  writer.writeStartElement("Icon");
159  writer.writeStartElement("href");
160  writer.writeCharacters(styleobj.pointImage);
161  writer.writeEndElement();
162  writer.writeEndElement();
163  writer.writeEndElement();
164  }
165  if(geometrytype.contains("LineString") && styleobj.lineStringStyle!=null && !styleobj.lineStringStyle.trim().isEmpty()) {
166  cssLiteralToKML(cssLiteralToMap(styleobj.lineStringStyle),"Point",writer);
167  }
168  if(geometrytype.contains("Polygon") && styleobj.polygonStyle!=null && !styleobj.polygonStyle.trim().isEmpty()) {
169  cssLiteralToKML(cssLiteralToMap(styleobj.polygonStyle),"Point",writer);
170  }
171  } catch (XMLStreamException e) {
172  // TODO Auto-generated catch block
173  e.printStackTrace();
174  }
175  return strwriter.toString();
176  }
void cssLiteralToKML(Map< String, String > cssMap, String geomtype, XMLStreamWriter writer)
Converts a CSS literal which has been converted to a map to KML and appends it to the XML produced by...
Definition: KMLStyleFormatter.java:87
Map< String, String > cssLiteralToMap(String cssString)
Converts a CSS literal to a KML representation to include in a KML document.
Definition: KMLStyleFormatter.java:52

References KMLStyleFormatter.cssLiteralToKML(), KMLStyleFormatter.cssLiteralToMap(), StyleObject.lineStringStyle, StyleObject.pointImage, StyleObject.pointStyle, 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.

42  {
43  // TODO Auto-generated method stub
44  return null;
45  }

◆ 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

◆ tagMap

Map<String,Map<String,String> > tagMap

A map which includes tags which are relevant for specific geometry types.