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

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

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
89  {
90  if(geomtype.equals("Polygon")) {
91  writer.writeStartElement("PolyStyle");
92  if(cssMap.containsKey("color")) {
93  writer.writeStartElement("color");
94  writer.writeCharacters(cssMap.get("color"));
95  writer.writeEndElement();
96  writer.writeStartElement("colorMode");
97  writer.writeCharacters("normal");
98  writer.writeEndElement();
99  }
100  if(cssMap.containsKey("fill")) {
101  writer.writeStartElement("fill");
102  writer.writeCharacters(cssMap.get("fill").replace("\\\"","").replace("^","").replace("http","").replace("true","1").replace("false","0").trim());
103  writer.writeEndElement();
104  }
105  if(cssMap.containsKey("stroke")) {
106  writer.writeStartElement("outline");
107  writer.writeCharacters(cssMap.get("stroke").replace("\\\"","").replace("^","").replace("http","").replace("true","1").replace("false","0").trim());
108  writer.writeEndElement();
109  }
110  writer.writeEndElement();
111  }else if(geomtype.equals("LineString")) {
112  writer.writeStartElement("LineStyle");
113  if(cssMap.containsKey("color")) {
114  writer.writeStartElement("color");
115  writer.writeCharacters(cssMap.get("color"));
116  writer.writeEndElement();
117  writer.writeStartElement("colorMode");
118  writer.writeCharacters("normal");
119  writer.writeEndElement();
120  }
121  if(cssMap.containsKey("stroke-width")) {
122  writer.writeStartElement("width");
123  writer.writeCharacters(cssMap.get("stroke-width"));
124  writer.writeEndElement();
125  }
126  writer.writeEndElement();
127  }else if(geomtype.equals("Point")) {
128  if(cssMap.containsKey("color")) {
129  writer.writeStartElement("color");
130  writer.writeCharacters(cssMap.get("color"));
131  writer.writeEndElement();
132  writer.writeStartElement("colorMode");
133  writer.writeCharacters("normal");
134  writer.writeEndElement();
135  }
136  if(cssMap.containsKey("stroke-width")) {
137  writer.writeStartElement("width");
138  writer.writeCharacters(cssMap.get("stroke-width"));
139  writer.writeEndElement();
140  }
141  }
142 
143  }

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.
54  {
55  Map<String,String> result=new TreeMap<String,String>();
56  if(cssString.contains(";")) {
57  for(String statement:cssString.split(";")) {
58  String[] split=statement.split(":");
59  if(!split[1].trim().isEmpty()) {
60  String key=split[0].replace("\\\"","").trim();
61  result.put(key,split[1].replace("\\\"","").replace("^","").replace("http","").replace("true","1").trim());
62  }
63  }
64  }else if(cssString.contains(",")) {
65  for(String statement:cssString.split(",")) {
66  String[] split=statement.split(":");
67  if(!split[1].trim().isEmpty()) {
68  String key=split[0].replace("\\\"","").trim();
69  result.put(key,split[1].replace("\\\"","").replace("^","").replace("http","").replace("true","1").trim());
70  }
71  }
72  }else {
73  String[] split=cssString.split(":");
74  if(!split[1].trim().isEmpty()) {
75  String key=split[0].replace("\\\"","").trim();
76  result.put(key,split[1].replace("\\\"","").replace("^","").replace("http","").replace("true","1").trim());
77  }
78  }
79  return result;
80  }

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.

146  {
147  if(styleobj==null)
148  return "";
149  System.out.println(geometrytype);
150  XMLOutputFactory factory = XMLOutputFactory.newInstance();
151  StringWriter strwriter=new StringWriter();
152  try {
153  XMLStreamWriter writer=new IndentingXMLStreamWriter(factory.createXMLStreamWriter(strwriter));
154 
155  writer.flush();
156  if(geometrytype.contains("Point") && styleobj.pointStyle!=null && !styleobj.pointStyle.trim().isEmpty()) {
157  writer.writeStartElement("IconStyle");
158  writer.writeCharacters("");
159  cssLiteralToKML(cssLiteralToMap(styleobj.pointStyle),"Point",writer);
160  writer.writeStartElement("Icon");
161  writer.writeStartElement("href");
162  writer.writeCharacters(styleobj.pointImage);
163  writer.writeEndElement();
164  writer.writeEndElement();
165  writer.writeEndElement();
166  }
167  if(geometrytype.contains("LineString") && styleobj.lineStringStyle!=null && !styleobj.lineStringStyle.trim().isEmpty()) {
168  cssLiteralToKML(cssLiteralToMap(styleobj.lineStringStyle),"Point",writer);
169  }
170  if(geometrytype.contains("Polygon") && styleobj.polygonStyle!=null && !styleobj.polygonStyle.trim().isEmpty()) {
171  cssLiteralToKML(cssLiteralToMap(styleobj.polygonStyle),"Point",writer);
172  }
173  } catch (XMLStreamException e) {
174  // TODO Auto-generated catch block
175  e.printStackTrace();
176  }
177  return strwriter.toString();
178  }
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:89
Map< String, String > cssLiteralToMap(String cssString)
Converts a CSS literal to a KML representation to include in a KML document.
Definition: KMLStyleFormatter.java:54

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.

44  {
45  // TODO Auto-generated method stub
46  return null;
47  }

◆ 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

◆ 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

◆ tagMap

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

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