summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Young <consult.awy@gmail.com>2015-04-30 16:12:17 (GMT)
committerAlan Young <consult.awy@gmail.com>2015-05-01 08:18:03 (GMT)
commit6385fd0f848ffd829ca52a04a90989730a10616f (patch)
tree53aaf2b63d2a974c3fa26429c6d235203ff9893b /src/com/isode/stroke/parser/payloadparsers/SecurityLabelsCatalogParser.java
parentcd8e073cabc9a39abb14527b6e968ece1586b7ec (diff)
downloadstroke-6385fd0f848ffd829ca52a04a90989730a10616f.zip
stroke-6385fd0f848ffd829ca52a04a90989730a10616f.tar.bz2
Add parser & serializer for SecurityLabel & SecurityLabelsCatalog
Change visibility of some methods in SecurityLabel & SecurityLabelsCatalog and provide default values for strings and collections in those clases. Change-Id: I1ea3f6b20deac1d1ac7999dd304e2e755d5e7c8a
Diffstat (limited to 'src/com/isode/stroke/parser/payloadparsers/SecurityLabelsCatalogParser.java')
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/SecurityLabelsCatalogParser.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/com/isode/stroke/parser/payloadparsers/SecurityLabelsCatalogParser.java b/src/com/isode/stroke/parser/payloadparsers/SecurityLabelsCatalogParser.java
new file mode 100644
index 0000000..b27aab9
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/SecurityLabelsCatalogParser.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2010-2015, Isode Limited, London, England.
+ * All rights reserved.
+ */
+
+package com.isode.stroke.parser.payloadparsers;
+
+import com.isode.stroke.elements.SecurityLabel;
+import com.isode.stroke.elements.SecurityLabelsCatalog;
+import com.isode.stroke.jid.JID;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.parser.GenericPayloadParser;
+
+public class SecurityLabelsCatalogParser extends GenericPayloadParser<SecurityLabelsCatalog> {
+
+ private int level_ = 0;
+ private final static int TopLevel = 0;
+ private final static int PayloadLevel = 1;
+ private final static int ItemLevel = 2;
+ private final static int LabelLevel = 3;
+
+ private final SecurityLabelParserFactory labelParserFactory_;
+ private SecurityLabelParser labelParser_;
+ private SecurityLabelsCatalog.Item currentItem_;
+
+ public SecurityLabelsCatalogParser() {
+ super(new SecurityLabelsCatalog());
+ labelParserFactory_ = new SecurityLabelParserFactory();
+ }
+
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ ++level_;
+ if (level_ == PayloadLevel) {
+ getPayloadInternal().setTo(new JID(attributes.getAttribute("to")));
+ getPayloadInternal().setName(attributes.getAttribute("name"));
+ getPayloadInternal().setDescription(attributes.getAttribute("desc"));
+ }
+ else if (level_ == ItemLevel && "item".equals(element) && "urn:xmpp:sec-label:catalog:2".equals(ns)) {
+ currentItem_ = new SecurityLabelsCatalog.Item();
+ currentItem_.setSelector(attributes.getAttribute("selector"));
+ currentItem_.setIsDefault(attributes.getBoolAttribute("default", false));
+ }
+ else if (level_ == LabelLevel) {
+ assert(labelParser_ == null);
+ if (labelParserFactory_.canParse(element, ns, attributes)) {
+ labelParser_ = (SecurityLabelParser)(labelParserFactory_.createPayloadParser());
+ assert (labelParser_) != null;
+ }
+ }
+
+ if (labelParser_ != null) {
+ labelParser_.handleStartElement(element, ns, attributes);
+ }
+ }
+
+ public void handleEndElement(String element, String ns) {
+ if (labelParser_ != null) {
+ labelParser_.handleEndElement(element, ns);
+ }
+ if (level_ == LabelLevel && labelParser_ != null && currentItem_ != null) {
+ SecurityLabel currentLabel = labelParser_.getLabelPayload();
+ assert (currentLabel) != null;
+ currentItem_.setLabel(currentLabel);
+ labelParser_ = null;
+ }
+ else if (level_ == ItemLevel && "item".equals(element) && "urn:xmpp:sec-label:catalog:2".equals(ns)) {
+ if (currentItem_ != null) {
+ getPayloadInternal().addItem(currentItem_);
+ currentItem_ = null;
+ }
+ }
+ --level_;
+ }
+
+ public void handleCharacterData(String data) {
+ if (labelParser_ != null) {
+ labelParser_.handleCharacterData(data);
+ }
+ }
+
+}