* @param file - String
* @return Gml
*/
@SuppressWarnings("unchecked")
private static Gml parseGml(String input, boolean isFile) {
Gml gml = null;
// TODO return null if the gml is a file and its path or type is incorrect
// TODO xsd validation ???
// Get document
Document document = getDocument(input, isFile);
String root = "/*[name()='GML' or name()='gml']";
// Get version
Element rootNode = (Element) JDomParsingUtils.selectSingleNode(document, root);
String version = rootNode.getAttributeValue("spec");
// TODO parsing factory with version
String expression = root+"/tag/header/client/child::*";
List<Element> elements = (List<Element>) JDomParsingUtils.selectNodes(document, expression);
gml = new Gml();
// Get Client
GmlClient client = new GmlClient();
if (null != elements) {
setGmlGenericContainer(elements, client);
}
gml.client = client;
// Get Environment
if (null == version || version.equalsIgnoreCase("0.1a") || version.equalsIgnoreCase("0.1b")) {
expression = root+"/tag/environment/child::*";
}
else {
expression = root+"/tag/header/environment/child::*";
}
elements = (List<Element>) JDomParsingUtils.selectNodes(document, expression);
GmlEnvironment environment = getGmlEnvironment(elements);
gml.environment = environment;
// TODO loop through all tags or skip multiple tags
// Get Drawing
expression = root+"/tag/drawing/child::*";
elements = (List<Element>) JDomParsingUtils.selectNodes(document, expression);
ArrayList<GmlStroke> gmlStrokes = new ArrayList<GmlStroke>();
gmlStrokes.addAll(getGmlDrawing(elements));
gml.addStrokes(gmlStrokes);
return gml;
}