Clover Coverage Report - Impex Parent 1.0.21-SNAPSHOT (Aggregated)
Coverage timestamp: Tue Feb 8 2011 11:33:53 EST
../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
39   153   27   1.86
12   104   0.69   21
21     1.29  
1    
 
  SchemaMorpher       Line # 7 39 0% 27 72 0% 0.0
 
No Tests
 
1    package org.apache.torque.mojo.morph;
2   
3    import org.apache.commons.lang.StringUtils;
4    import org.apache.commons.logging.Log;
5    import org.apache.commons.logging.LogFactory;
6   
 
7    public class SchemaMorpher extends Morpher {
8    private static final Log log = LogFactory.getLog(SchemaMorpher.class);
9   
10    // Ant impex has kfs hard coded
11    String antSchemaName = "kfs";
12    // Token we can look for to help identify this schema XML file as an Impex file generated by the Ant process
13    String antSchemaToken = "name=\"" + antSchemaName + "\"";
14    // Ant impex is hard coded to database.dtd
15    String antDTDString = "\"database.dtd\"";
16    // The Kuali database.dtd
17    String newDTDString = "\"http://www.kuali.org/dtd/database.dtd\"";
18    // Ant impex comment
19    String antComment = "<!-- Autogenerated by KualiTorqueJDBCTransformTask! -->";
20    // Maven impex comment
21    String newComment = "<!-- Autogenerated by the Maven Impex Plugin -->";
22    // Ant prologue
23    String antPrologue = "<?xml version=\"1.0\"?>";
24    // New prologue
25    String newPrologue = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
26   
 
27  0 toggle public SchemaMorpher() {
28  0 this(null, null);
29    }
30   
 
31  0 toggle public SchemaMorpher(MorphRequest morphRequest, String artifactId) {
32  0 super();
33  0 this.artifactId = artifactId;
34  0 this.morphRequest = morphRequest;
35    }
36   
37    /**
38    * Attempt to determine if this content is from an Ant Impex XML export
39    */
 
40  0 toggle protected boolean isAntImpexSchemaXML(String contents) {
41  0 if (contents == null) {
42  0 return false;
43    }
44  0 if (contents.indexOf(antSchemaToken) == -1) {
45  0 return false;
46    }
47  0 if (contents.indexOf(antDTDString) == -1) {
48  0 return false;
49    }
50  0 if (contents.indexOf(antComment) == -1) {
51  0 return false;
52    }
53    // All 3 tokens we know about were present in the String
54    // Pretty good chance it is content from an Ant Impex export
55  0 return true;
56    }
57   
58    /**
59    * Return true if we need to morph this file
60    */
 
61  0 toggle protected boolean isMorphNeeded(String contents) {
62  0 if (!isAntImpexSchemaXML(contents)) {
63  0 log.warn("Unable to determine if this is a schema exported from Ant Impex");
64    }
65   
66    // Look for the DTD the Maven Impex Plugin uses
67  0 int pos = contents.indexOf(newDTDString);
68   
69  0 if (pos == -1) {
70    // It isn't there so we should morph
71  0 return true;
72    } else {
73    // It is already there, we are good to go
74  0 return false;
75    }
76    }
77   
78    /**
79    * Morph an Ant Impex XML file into a Maven Impex Plugin XML file
80    */
 
81  0 toggle @Override
82    protected String getMorphedContents(String contents) {
83  0 contents = StringUtils.replace(contents, antDTDString, newDTDString);
84  0 contents = StringUtils.replace(contents, antComment, newComment);
85  0 contents = StringUtils.replace(contents, antPrologue, newPrologue);
86  0 return StringUtils.replace(contents, "name=\"" + antSchemaName + "\">", "name=\"" + getArtifactId() + "\">");
87    }
88   
 
89  0 toggle public String getAntSchemaName() {
90  0 return antSchemaName;
91    }
92   
 
93  0 toggle public void setAntSchemaName(String defaultSchemaName) {
94  0 this.antSchemaName = defaultSchemaName;
95    }
96   
 
97  0 toggle public String getAntSchemaToken() {
98  0 return antSchemaToken;
99    }
100   
 
101  0 toggle public void setAntSchemaToken(String defaultSchemaToken) {
102  0 this.antSchemaToken = defaultSchemaToken;
103    }
104   
 
105  0 toggle public String getAntDTDString() {
106  0 return antDTDString;
107    }
108   
 
109  0 toggle public void setAntDTDString(String defaultDTDString) {
110  0 this.antDTDString = defaultDTDString;
111    }
112   
 
113  0 toggle public String getNewDTDString() {
114  0 return newDTDString;
115    }
116   
 
117  0 toggle public void setNewDTDString(String newDTDString) {
118  0 this.newDTDString = newDTDString;
119    }
120   
 
121  0 toggle public String getAntComment() {
122  0 return antComment;
123    }
124   
 
125  0 toggle public void setAntComment(String defaultComment) {
126  0 this.antComment = defaultComment;
127    }
128   
 
129  0 toggle public String getNewComment() {
130  0 return newComment;
131    }
132   
 
133  0 toggle public void setNewComment(String newComment) {
134  0 this.newComment = newComment;
135    }
136   
 
137  0 toggle public String getAntPrologue() {
138  0 return antPrologue;
139    }
140   
 
141  0 toggle public void setAntPrologue(String antPrologue) {
142  0 this.antPrologue = antPrologue;
143    }
144   
 
145  0 toggle public String getNewPrologue() {
146  0 return newPrologue;
147    }
148   
 
149  0 toggle public void setNewPrologue(String newPrologue) {
150  0 this.newPrologue = newPrologue;
151    }
152   
153    }