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.ui;
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.LinkInstance;
30 import org.efaps.update.schema.AbstractFileUpdate;
31 import org.efaps.util.EFapsException;
32
33 /**
34 * Handles the import / update of images for eFaps read from a XML
35 * configuration item file (for the meta data) and the image itself as binary
36 * file.
37 *
38 * @author The eFaps Team
39 * @version $Id$
40 */
41 public class ImageUpdate
42 extends AbstractFileUpdate
43 {
44 /**
45 * Link from menu to type as type tree menu.
46 */
47 private static final Link LINK2TYPE = new UniqueLink("Admin_UI_LinkIsTypeIconFor", "From",
48 "Admin_DataModel_Type", "To");
49
50 /**
51 * All specific used links for images.
52 */
53 private static final Set <Link> ALLLINKS = new HashSet<Link>();
54 static {
55 ImageUpdate.ALLLINKS.add(ImageUpdate.LINK2TYPE);
56 }
57
58 /**
59 * Default constructor to initialize this image update instance for given
60 * <code>_url</code>.
61 *
62 * @param _url URL of the file
63 */
64 public ImageUpdate(final URL _url)
65 {
66 super(_url, "Admin_UI_Image", ImageUpdate.ALLLINKS);
67 }
68
69 /**
70 * Creates new instance of class {@link ImageUpdate.ImageDefinition}.
71 *
72 * @return new definition instance
73 * @see ImageUpdate.ImageDefinition
74 */
75 @Override
76 protected AbstractDefinition newDefinition()
77 {
78 return new ImageDefinition();
79 }
80
81 /**
82 * Handles the definition of one version for an image defined within XML
83 * configuration item file.
84 */
85 protected class ImageDefinition
86 extends AbstractFileDefinition
87 {
88 /**
89 * Interprets the image specific part of the XML configuration item
90 * file. Following information is read:
91 * <ul>
92 * <li>name of the type for which this image is defined (as type
93 * image); interpreted as {@link ImageUpdate#LINK2TYPE link}</li>
94 * </ul>
95 *
96 * @param _tags current path as list of single tags
97 * @param _attributes attributes for current path
98 * @param _text content for current path
99 * @throws EFapsException on error
100 */
101 @Override
102 protected void readXML(final List<String> _tags,
103 final Map<String, String> _attributes,
104 final String _text)
105 throws EFapsException
106 {
107 final String value = _tags.get(0);
108 if ("type".equals(value)) {
109 // assigns a type the image for which this image instance is
110 // the type icon
111 addLink(ImageUpdate.LINK2TYPE, new LinkInstance(_text));
112 } else {
113 super.readXML(_tags, _attributes, _text);
114 }
115 }
116 }
117 }