1 /***
2 * Created on Aug 5, 2005, Copyright UC Regents
3 */
4 package wise2.converter;
5
6 import java.io.IOException;
7 import java.io.InputStream;
8 import java.net.URL;
9 import java.util.List;
10 import java.util.jar.JarOutputStream;
11
12 import net.sf.sail.core.beans.Pod;
13 import net.sf.sail.core.util.BinaryUtils;
14
15 import org.dom4j.Node;
16 import org.telscenter.pas.beans.PasStep;
17 import org.telscenter.pas.hint.Hint;
18 import org.telscenter.pas.properties.HintSet;
19
20 /***
21 * @author turadg
22 */
23 abstract public class AbstractStepConverter {
24
25 protected Pod pod;
26
27 protected JarOutputStream podArchiveOutputStream;
28
29 protected IProjectUploadProvider uploadProvider;
30
31 public Pod getPod() {
32 return pod;
33 }
34
35 public void setPod(Pod pod) {
36 this.pod = pod;
37 }
38
39 protected Node stepNode;
40
41 /***
42 * @param stepNode
43 */
44 public void setStepNode(Node stepNode) {
45 this.stepNode = stepNode;
46 }
47
48 /***
49 * @return
50 */
51 protected abstract PasStep getTypedPasStep();
52
53 public PasStep getPasStep() {
54 PasStep step = getTypedPasStep();
55 step.setTitle(getStepTitle());
56 step.setHintSet(getStepHints());
57 return step;
58 }
59
60 protected String getStepTitle() {
61 Node titleNode = stepNode.selectSingleNode("title");
62 String title = (titleNode == null) ? "UNDEFINED_TITLE" : titleNode
63 .getText();
64 return title;
65 }
66
67 public void setPodArchiveOutputStream(JarOutputStream podArchiveOutputStream) {
68 this.podArchiveOutputStream = podArchiveOutputStream;
69 }
70
71 /***
72 * @param filename
73 * @param source
74 * @return
75 * @throws IOException
76 */
77 protected URL addToArchive(String filename, InputStream source)
78 throws IOException {
79 return BinaryUtils.addToArchive(pod, podArchiveOutputStream, filename,
80 source);
81 }
82
83 /***
84 * @param uploadProvider
85 */
86 public void setUploadProvider(IProjectUploadProvider uploadProvider) {
87 this.uploadProvider = uploadProvider;
88 }
89
90 /***
91 * @return
92 */
93 @SuppressWarnings("unchecked")
94 protected HintSet getStepHints() {
95 List<Node> list = stepNode.selectNodes("hint");
96 HintSet hintSet = new HintSet();
97 for (Node node : list) {
98 Hint hint = new Hint();
99 hint.setText(node.getText());
100 hintSet.add(hint);
101 }
102 return hintSet;
103 }
104
105 }