1 package net.sf.jpkgmk.prototype;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.ArrayList;
6 import java.util.List;
7
8 import net.sf.jpkgmk.AbstractLineProvider;
9 import net.sf.jpkgmk.pkgmap.PkgMapEntry;
10 import net.sf.jpkgmk.pkgmap.PkgMapEntryComment;
11 import net.sf.jpkgmk.util.StringUtil;
12 import net.sf.jpkgmk.util.VariableResolver;
13 import net.sf.jpkgmk.util.StringUtil.RemoveResult;
14
15 import org.apache.commons.logging.Log;
16 import org.apache.commons.logging.LogFactory;
17
18
19
20
21
22
23
24 public class PrototypeEntryComment extends AbstractLineProvider implements PrototypeEntry
25 {
26 private Log log = LogFactory.getLog(PrototypeEntryComment.class);
27
28 private String comment;
29 private PrototypeEntryType type = PrototypeEntryType.COMMENT;
30
31
32
33
34 private boolean hasWhitespaceSeparator = true;
35
36
37
38
39
40 public PrototypeEntryComment(String comment)
41 {
42 this.comment = comment;
43 }
44
45
46
47
48 public boolean isHasWhitespaceSeparator() {
49 return hasWhitespaceSeparator;
50 }
51
52
53
54
55 public void setHasWhitespaceSeparator(boolean hasWhitespaceSeparator) {
56 this.hasWhitespaceSeparator = hasWhitespaceSeparator;
57 }
58
59 public String getLine() {
60 StringBuffer sb = new StringBuffer();
61 sb.append(this.type.getKey());
62 if(this.hasWhitespaceSeparator) {
63 sb.append(" ");
64 }
65 sb.append(this.comment);
66 return sb.toString();
67 }
68
69 public PrototypeEntryType getType() {
70 return type;
71 }
72
73 public void create(File basedir, VariableResolver variableResolver) throws IOException {
74
75 log.debug("Nothing to do in <create()> for a prototype comment");
76 }
77
78 public List<PkgMapEntry> createPkgMapEntry(File basedir, VariableResolver variableResolver) {
79 PkgMapEntry resultEntry = new PkgMapEntryComment(this.comment);
80 List<PkgMapEntry> result = new ArrayList<PkgMapEntry>();
81 result.add(resultEntry);
82 return result;
83 }
84
85 @Override
86 public String toString() {
87 StringBuffer sb = new StringBuffer();
88 sb.append(this.getClass().getName()).append("[");
89 sb.append("type=").append(this.type);
90 sb.append(",hasWhitespaceSeparater=").append(this.hasWhitespaceSeparator);
91 sb.append(",comment=").append(StringUtil.truncateToMaxLength(this.comment, 20));
92 sb.append("]");
93 return sb.toString();
94 }
95
96
97
98 public static class PrototypeEntryCommentParser implements PrototypeEntryParser
99 {
100
101 public PrototypeEntry parse(String line, PrototypeEntryCommandDefault entryCommandDefault) {
102 RemoveResult removeResult = StringUtil.removePrefix(line, PrototypeEntryType.COMMENT.getKey());
103
104 PrototypeEntryComment result = new PrototypeEntryComment(removeResult.getCleanedString());
105 result.setHasWhitespaceSeparator(removeResult.isHasWhitespaceSeparator());
106 return result;
107 }
108
109 }
110
111 }