1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.codehaus.mojo.castor;
18
19 import java.io.File;
20 import java.io.FileReader;
21 import java.io.FileWriter;
22
23 import org.apache.maven.plugin.AbstractMojo;
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.plugins.annotations.LifecyclePhase;
26 import org.apache.maven.plugins.annotations.Mojo;
27 import org.apache.maven.plugins.annotations.Parameter;
28 import org.codehaus.plexus.util.FileUtils;
29 import org.exolab.castor.xml.dtd.Converter;
30
31
32
33
34
35
36
37
38
39 @Mojo(name = "dtdToXsd", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
40 public class ConvertDTD2XSDMojo
41 extends AbstractMojo
42 {
43
44
45
46
47 @Parameter(property = "source", required = true)
48 private File source;
49
50
51
52
53 @Parameter(property = "dest", required = true)
54 private File dest;
55
56
57
58
59
60
61 public void execute()
62 throws MojoExecutionException
63 {
64 if ( !source.exists() )
65 {
66 throw new MojoExecutionException( "Source DTD " + source + " does not exists." );
67 }
68
69 File destDir = dest.getParentFile();
70
71 if ( destDir != null && !destDir.exists() )
72 {
73 FileUtils.mkdir( destDir.getAbsolutePath() );
74 }
75
76 try
77 {
78 FileWriter writer = new FileWriter( dest );
79 Converter converter = new Converter();
80 converter.convertDTDtoSchema( new FileReader( source ), writer );
81 writer.close();
82 }
83 catch ( Exception e )
84 {
85 throw new MojoExecutionException( "Castor execution failed", e );
86 }
87 }
88
89
90
91
92
93
94 public void setSource( final File source )
95 {
96 this.source = source;
97 }
98
99
100
101
102
103
104
105 public void setDest( final File dest )
106 {
107 this.dest = dest;
108 }
109
110 }