diff options
author | Alan Young <consult.awy@gmail.com> | 2015-04-30 16:12:17 (GMT) |
---|---|---|
committer | Alan Young <consult.awy@gmail.com> | 2015-05-01 08:18:03 (GMT) |
commit | 6385fd0f848ffd829ca52a04a90989730a10616f (patch) | |
tree | 53aaf2b63d2a974c3fa26429c6d235203ff9893b /src/com/isode/stroke/parser/payloadparsers/SecurityLabelParser.java | |
parent | cd8e073cabc9a39abb14527b6e968ece1586b7ec (diff) | |
download | stroke-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/SecurityLabelParser.java')
-rw-r--r-- | src/com/isode/stroke/parser/payloadparsers/SecurityLabelParser.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/com/isode/stroke/parser/payloadparsers/SecurityLabelParser.java b/src/com/isode/stroke/parser/payloadparsers/SecurityLabelParser.java new file mode 100644 index 0000000..5370944 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/SecurityLabelParser.java @@ -0,0 +1,80 @@ +/* + * 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.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.SerializingParser; + +public class SecurityLabelParser extends GenericPayloadParser<SecurityLabel> { + + private int level_ = 0; + private final static int TopLevel = 0; + private final static int PayloadLevel = 1; + private final static int DisplayMarkingOrLabelLevel = 2; + private final static int SecurityLabelLevel = 3; + + private SerializingParser labelParser_; + + private String currentText_ = ""; + + public SecurityLabelParser() { + super(new SecurityLabel()); + } + + public void handleStartElement(String element, String ns, AttributeMap attributes) { + ++level_; + if (level_ == DisplayMarkingOrLabelLevel) { + if ("displaymarking".equals(element)) { + currentText_ = ""; + getPayloadInternal().setBackgroundColor(attributes.getAttribute("bgcolor")); + getPayloadInternal().setForegroundColor(attributes.getAttribute("fgcolor")); + } + else if ("label".equals(element) || "equivalentlabel".equals(element)) { + assert(labelParser_ == null); + labelParser_ = new SerializingParser(); + } + } + else if (level_ >= SecurityLabelLevel && labelParser_ != null) { + labelParser_.handleStartElement(element, ns, attributes); + } + } + + public void handleEndElement(String element, String ns) { + if (level_ == DisplayMarkingOrLabelLevel) { + if ("displaymarking".equals(element)) { + getPayloadInternal().setDisplayMarking(currentText_); + } + else if (labelParser_ != null) { + if ("label".equals(element)) { + getPayloadInternal().setLabel(labelParser_.getResult()); + } + else { + getPayloadInternal().addEquivalentLabel(labelParser_.getResult()); + } + labelParser_ = null; + } + } + else if (labelParser_ != null && level_ >= SecurityLabelLevel) { + labelParser_.handleEndElement(element, ns); + } + --level_; + } + + public void handleCharacterData(String data) { + if (labelParser_ != null) { + labelParser_.handleCharacterData(data); + } + else { + currentText_ += data; + } + } + + public SecurityLabel getLabelPayload() { + return getPayloadInternal(); + } +} |