1 package org.apache.torque.mojo.morph;
2
3 import org.codehaus.plexus.util.StringUtils;
4
5 public class DataMorpher extends Morpher {
6
7 String antPrologue = "<?xml version=\"1.0\"?>";
8
9 String newPrologue = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
10
11
12 String antDocType = "<!DOCTYPE dataset SYSTEM \"data.dtd\">";
13
14 public DataMorpher() {
15 this(null, null);
16 }
17
18 public DataMorpher(MorphRequest morphRequest, String artifactId) {
19 super(morphRequest, artifactId);
20 }
21
22 protected String getNewDocType() {
23 return "<!DOCTYPE dataset SYSTEM \"" + getArtifactId() + ".dtd\">";
24 }
25
26 protected String getMorphedContents(String contents) {
27 contents = StringUtils.replace(contents, antPrologue, newPrologue);
28 return StringUtils.replace(contents, antDocType, getNewDocType());
29 }
30
31
32
33
34 protected boolean isMorphNeeded(String contents) {
35
36 int pos = contents.indexOf(getNewDocType());
37
38 if (pos == -1) {
39
40 return true;
41 } else {
42
43 return false;
44 }
45 }
46
47 public String getAntPrologue() {
48 return antPrologue;
49 }
50
51 public void setAntPrologue(String antPrologue) {
52 this.antPrologue = antPrologue;
53 }
54
55 public String getNewPrologue() {
56 return newPrologue;
57 }
58
59 public void setNewPrologue(String newPrologue) {
60 this.newPrologue = newPrologue;
61 }
62
63 }