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.program;
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 BPM 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 BPMImageUpdate
42 extends AbstractFileUpdate
43 {
44
45 /**
46 * Link from bpm to related image.
47 */
48 private static final Link BPM2IMAGE = new Link("Admin_Program_BPM2Image",
49 "ToLink",
50 "Admin_Program_BPM", "FromLink");
51
52 /**
53 * All specific used links for images.
54 */
55 private static final Set <Link> ALLLINKS = new HashSet<Link>();
56 static {
57 BPMImageUpdate.ALLLINKS.add(BPMImageUpdate.BPM2IMAGE);
58 }
59
60 /**
61 * Default constructor to initialize this BPM report image update
62 * instance for given <code>_url</code>.
63 *
64 * @param _url URL of the file
65 */
66 public BPMImageUpdate(final URL _url)
67 {
68 super(_url, "Admin_Program_BPMImage", BPMImageUpdate.ALLLINKS);
69 }
70
71 /**
72 * Creates new instance of class
73 * {@link BPMImageUpdate.BPMImageDefinition}.
74 *
75 * @return new definition instance
76 * @see JasperImageUpdate.JasperImageDefinition
77 */
78 @Override
79 protected AbstractDefinition newDefinition()
80 {
81 return new BPMImageDefinition();
82 }
83
84 /**
85 * Definition for a Jasper Image.
86 */
87 protected class BPMImageDefinition
88 extends AbstractFileDefinition
89 {
90 /**
91 * Interprets the image specific part of the XML configuration item
92 * file. Following information is read:
93 * <ul>
94 * <li>name of the type for which this image is defined (as type
95 * image); interpreted as {@link ImageUpdate#LINK2TYPE link}</li>
96 * </ul>
97 *
98 * @param _tags current path as list of single tags
99 * @param _attributes attributes for current path
100 * @param _text content for current path
101 * @throws EFapsException on error
102 */
103 @Override
104 protected void readXML(final List<String> _tags,
105 final Map<String, String> _attributes,
106 final String _text)
107 throws EFapsException
108 {
109 final String value = _tags.get(0);
110 if ("processId".equals(value)) {
111 // assigns a type the image for which this image instance is
112 // the type icon
113 addLink(BPMImageUpdate.BPM2IMAGE, new LinkInstance(_text));
114 } else {
115 super.readXML(_tags, _attributes, _text);
116 }
117 }
118
119 }
120 }