From 566d17f731637df6828bdf32502a0fb123882dbe Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Thu, 9 Oct 2003 11:41:45 +0000 Subject: Initial import --- .../directory/parser/DirectoryMessage.java | 130 +++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 src/org/noreply/fancydress/directory/parser/DirectoryMessage.java (limited to 'src/org/noreply/fancydress/directory/parser/DirectoryMessage.java') diff --git a/src/org/noreply/fancydress/directory/parser/DirectoryMessage.java b/src/org/noreply/fancydress/directory/parser/DirectoryMessage.java new file mode 100644 index 0000000..81ce6e2 --- /dev/null +++ b/src/org/noreply/fancydress/directory/parser/DirectoryMessage.java @@ -0,0 +1,130 @@ +package org.noreply.fancydress.directory.parser; + +import java.util.*; + +/** + * Hold all sections and entries that are in a directory. + * + * This class holds all sections and entries of a directory. All data + * are stored in sections, which in turn hold entries of key:value pairs. + * + * The values themselves are not yet parsed, nor is the content + * cryptographically verified. + * + * The DirectoryParser returns an object of this class. + * + * @see org.noreply.fancydress.directory.Directory + * @see DirectoryParser + * @see DirectorySection + * @see DirectoryEntry + */ +public class DirectoryMessage implements Cloneable { + /** + * List of directory sections + */ + private ArrayList sections; + + /** + * Default constructor. + * + * Creates a new DirectoryMessage, adding section to + * the section list. + * + * @param section First section of the directory. It is used directly, not copied. + */ + public DirectoryMessage(DirectorySection section) { + this(); + sections.add(section); + } + + /** + * Emty constructor. + * + * Creates a new DirectoryMessage. + */ + public DirectoryMessage() { + sections = new ArrayList(); + } + + /** + * Copy constructor. + * + * Creates a new DirectoryMessage copying all values (recursively) from + * message. + * + * @param message message to copy from. + */ + public DirectoryMessage(DirectoryMessage message) { + this(); + for (Iterator i = message.sections.iterator(); i.hasNext(); ) + sections.add(new DirectorySection((DirectorySection)i.next())); + } + + /** + * Add a section to this message. + * + * @param section Section to add. It is used directly, not copied. + */ + public void addSection(DirectorySection section) { + sections.add(section); + } + + /** + * Blind a value in order to verify or create a signature. + * + * @param section Section in which to blind the entry named. + * @param entry Entry to blind. + * @return The number of entries blinded. + */ + public int blindValue(String section, String entry) { + int count = 0; + for (Iterator i = sections.iterator(); i.hasNext(); ) { + DirectorySection s = (DirectorySection) i.next(); + if (s.getName().equals(section)) + count += s.blindValue(entry); + }; + return count; + } + + /** + * Return the first section with that name + * + * @param section Section to return. + * @return first DirectorySection that matches the name or null. + */ + public DirectorySection getSection(String section) { + int count = 0; + for (Iterator i = sections.iterator(); i.hasNext(); ) { + DirectorySection s = (DirectorySection) i.next(); + if (s.getName().equals(section)) + return s; + }; + return null; + } + + /** + * Return an iterator over the sections. + * + * @return Iterator over sections. + */ + public Iterator getSectionsIterator() { + return sections.iterator(); + } + + /** + * Returns a string representation of the directory. + * + * This representation can be parsed again using the directory parser. + * + * @return a string representation of the object. + */ + public String toString() { + StringBuffer strbuf = new StringBuffer(); + + for (Iterator i = sections.iterator(); i.hasNext(); ) { + Object o = i.next(); + strbuf.append(o.toString()); + } + return strbuf.toString(); + } +} -- cgit v1.2.3