1 /*
2 * Copyright 2003 - 2013 The eFaps Team
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * Revision: $Rev$
17 * Last Changed: $Date$
18 * Last Changed By: $Author$
19 */
20
21 package org.efaps.update.schema.help;
22
23 import java.net.URL;
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Set;
28
29 import org.efaps.update.AbstractUpdate;
30 import org.efaps.update.LinkInstance;
31 import org.efaps.util.EFapsException;
32
33 /**
34 * TODO comment!
35 *
36 * @author The eFaps Team
37 * @version $Id$
38 */
39 public class HelpMenuUpdate
40 extends AbstractUpdate
41 {
42 /** Link from menu to child command / menu. */
43 private static final Link LINK2CHILD = new OrderedLink("Admin_Help_Menu2Menu",
44 "FromLink",
45 "Admin_Help_Menu", "ToLink");
46
47 /** Link from menu to type as type tree menu. */
48 private static final Link LINK2WIKI = new Link("Admin_Help_Menu2Wiki",
49 "FromLink",
50 "Admin_Program_Wiki", "ToLink");
51
52 /**
53 * Set of all links for wiki menus.
54 */
55 private static final Set<Link> ALLLINKS = new HashSet<Link>();
56 static {
57 HelpMenuUpdate.ALLLINKS.add(HelpMenuUpdate.LINK2CHILD);
58 HelpMenuUpdate.ALLLINKS.add(HelpMenuUpdate.LINK2WIKI);
59 }
60
61 /**
62 * Constructor calling the super constructor.
63 * @param _url URL to the xml definition file.
64 */
65 public HelpMenuUpdate(final URL _url)
66 {
67 super(_url, "Admin_Help_Menu", HelpMenuUpdate.ALLLINKS);
68 }
69
70 /**
71 * {@inheritDoc}
72 */
73 @Override
74 protected AbstractDefinition newDefinition()
75 {
76 return new WikiMenuDefinition();
77 }
78
79 /**
80 * Definition for the wiki menu.
81 */
82 protected class WikiMenuDefinition
83 extends AbstractDefinition
84 {
85
86 /**
87 * {@inheritDoc}
88 * @throws EFapsException
89 */
90 @Override
91 protected void readXML(final List<String> _tags,
92 final Map<String, String> _attributes,
93 final String _text)
94 throws EFapsException
95 {
96 final String value = _tags.get(0);
97 if ("childs".equals(value)) {
98 if (_tags.size() > 1) {
99 final String subValue = _tags.get(1);
100 if ("child".equals(subValue)) {
101 addLink(HelpMenuUpdate.LINK2CHILD, new LinkInstance(_text));
102 } else {
103 super.readXML(_tags, _attributes, _text);
104 }
105 }
106 } else if ("target".equals(value)) {
107 if (_tags.size() == 2) {
108 final String subValue = _tags.get(1);
109 if ("wiki".equals(subValue)) {
110 addLink(HelpMenuUpdate.LINK2WIKI, new LinkInstance(_text));
111 }
112 }
113 } else {
114 super.readXML(_tags, _attributes, _text);
115 }
116 }
117 }
118 }