Source code: com/aendvari/common/notices/NoticesUtil.java
1 /*
2 * NoticesUtil.java
3 *
4 * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5 *
6 * See the file LICENSE for terms of use.
7 *
8 */
9
10 package com.aendvari.common.notices;
11
12 import java.util.Collection;
13 import java.util.Iterator;
14 import java.util.Map;
15
16 import com.aendvari.common.model.*;
17
18 import com.aendvari.common.osm.*;
19 import com.aendvari.common.model.osm.*;
20
21 /**
22 * <p>Provides various utility methods for the notice classes.</p>
23 *
24 * @author Scott Milne
25 *
26 */
27
28 public class NoticesUtil
29 {
30 /**
31 * <p>Extracts all the notices in their translated form into the given {@link ModelNode}.</p>
32 *
33 * <p>The form in which the notices will placed is:</p>
34 *
35 * <code>
36 * <notice>this is notice 1</notice>
37 * <notice>this is notice 2</notice>
38 * <notice>this is notice 3</notice>
39 * </code>
40 *
41 * @param notices A {@link Notices} instance of the notices to extract.
42 * @param translator A {@link NoticeTranslator} instance for translation.
43 * @param modelNode The {@link ModelNode} to extract notices into.
44 * @param path The {@link Osm} path to which to locate the notices to display.
45 * @param recursive Should the OSM search be recursive.
46 *
47 */
48
49 public static void noticesToModel(Notices notices, NoticeTranslator translator, ModelNode modelNode, String path, boolean recursive)
50 {
51 // get all the specified messages from the translator
52 Collection errorNotices = notices.getNotices(path, recursive);
53 Collection errorStrings = translator.translate(errorNotices);
54
55 // get the model tree
56 ModelTree modelTree = modelNode.getOwnerModelTree();
57
58 // now display them (if any)
59 Iterator noticesIterator = errorStrings.iterator();
60
61 while (noticesIterator.hasNext())
62 {
63 String parsedMsg = (String)noticesIterator.next();
64
65 ModelNode noticeNode = modelTree.createNode("notice", parsedMsg.trim());
66 modelNode.appendChild(noticeNode);
67 }
68 }
69 }
70