aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/shared/model
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-01-27 18:15:09 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2013-01-27 18:15:09 +1300
commite49a792fcd72617122738891de67a39b386cb365 (patch)
tree8dd876daa5b5eae8ff9ec826fe659843cd931843 /src/org/traccar/web/shared/model
parent611494b77c8906d3fe7fd02039c5ede323b1fde4 (diff)
downloadtrackermap-web-e49a792fcd72617122738891de67a39b386cb365.tar.gz
trackermap-web-e49a792fcd72617122738891de67a39b386cb365.tar.bz2
trackermap-web-e49a792fcd72617122738891de67a39b386cb365.zip
Add simple XML parser
Diffstat (limited to 'src/org/traccar/web/shared/model')
-rw-r--r--src/org/traccar/web/shared/model/XmlParser.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/org/traccar/web/shared/model/XmlParser.java b/src/org/traccar/web/shared/model/XmlParser.java
new file mode 100644
index 00000000..f19c75a8
--- /dev/null
+++ b/src/org/traccar/web/shared/model/XmlParser.java
@@ -0,0 +1,40 @@
+package org.traccar.web.shared.model;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import com.google.gwt.regexp.shared.MatchResult;
+import com.google.gwt.regexp.shared.RegExp;
+
+public class XmlParser {
+
+ public static List<String> enumerateElements(String input) {
+ List<String> list = new LinkedList<String>();
+
+ RegExp parser = RegExp.compile("<([^/<][^<]*)>", "g");
+ MatchResult result = parser.exec(input);
+ while (result.getGroupCount() > 0) {
+ list.add(result.getGroup(1));
+ result = parser.exec(input);
+ }
+
+ return list;
+ }
+
+ public static String getElement(String input, String key) {
+
+ StringBuilder pattern = new StringBuilder();
+ pattern.append("<").append(key).append(">");
+ pattern.append("([^<]*)");
+ pattern.append("</").append(key).append(">");
+
+ RegExp parser = RegExp.compile(pattern.toString());
+ MatchResult result = parser.exec(input);
+ if (result.getGroupCount() > 0) {
+ return result.getGroup(1);
+ }
+
+ return null;
+ }
+
+}