dvi2epub enables you to convert DVI file to EPUB format.
Revision | be8eb643fd924865fc1839090cf332c0c3c07d2e (tree) |
---|---|
Time | 2012-03-27 18:02:58 |
Author | Takeyuki NAGAO <nagaotakeyuki@gmai...> |
Commiter | Takeyuki NAGAO |
Auto-save
@@ -1,14 +1,55 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
31 | + */ | |
32 | + | |
1 | 33 | package jp.sourceforge.dvibrowser.dvi2epub; |
2 | 34 | |
35 | +import java.awt.image.BufferedImage; | |
36 | +import java.io.File; | |
37 | +import java.io.IOException; | |
3 | 38 | import java.util.Arrays; |
4 | 39 | |
40 | +import javax.imageio.ImageIO; | |
41 | + | |
5 | 42 | import jp.sourceforge.dvibrowser.dvi2epub.cmd.AnnotatedCommand; |
6 | 43 | import jp.sourceforge.dvibrowser.dvi2epub.cmd.Command; |
7 | 44 | import jp.sourceforge.dvibrowser.dvi2epub.cmd.CommandException; |
8 | 45 | import jp.sourceforge.dvibrowser.dvi2epub.cmd.CommandUtils; |
9 | -import jp.sourceforge.dvibrowser.dvi2epub.opt.BooleanValueOption; | |
10 | -import jp.sourceforge.dvibrowser.dvi2epub.opt.IntValueOption; | |
11 | -import jp.sourceforge.dvibrowser.dvi2epub.opt.StringValueOption; | |
46 | +import jp.sourceforge.dvibrowser.dvicore.DviException; | |
47 | +import jp.sourceforge.dvibrowser.dvicore.DviRect; | |
48 | +import jp.sourceforge.dvibrowser.dvicore.api.DviDocument; | |
49 | +import jp.sourceforge.dvibrowser.dvicore.api.DviPage; | |
50 | +import jp.sourceforge.dvibrowser.dvicore.ctx.DefaultDviContext; | |
51 | +import jp.sourceforge.dvibrowser.dvicore.ctx.DviToolkit; | |
52 | +import jp.sourceforge.dvibrowser.dvicore.gui.swing.ViewSpec; | |
12 | 53 | |
13 | 54 | public class Dvi2EpubCmd extends AnnotatedCommand { |
14 | 55 |
@@ -18,33 +59,29 @@ public class Dvi2EpubCmd extends AnnotatedCommand { | ||
18 | 59 | |
19 | 60 | @Override |
20 | 61 | protected int processCommandLine() throws CommandException { |
21 | - System.out.println("Arguments: " + Arrays.toString(getArgs())); | |
22 | - return Command.EXIT_SUCCESS; | |
23 | - } | |
24 | - | |
25 | - @BooleanValueOption(description = "Show this message", longName=Command.NULL, shortName="d") | |
26 | - public void wantHelp(boolean want) | |
27 | - { | |
28 | - System.out.println("Overridden help: " + want); | |
29 | - super.wantHelp(want); | |
30 | - } | |
31 | - | |
32 | - @BooleanValueOption(description = "test", longName = "debug", shortName = "d") | |
33 | - public void wantDebug(boolean want) | |
34 | - { | |
35 | - System.out.println("test"); | |
36 | - } | |
37 | - | |
38 | - @StringValueOption(description = "test2", longName = "debug2", shortName = "x", value = Command.NULL) | |
39 | - public void setParam1(String s) | |
40 | - { | |
41 | - System.out.println("test2: " + s); | |
42 | - } | |
43 | - | |
44 | - @IntValueOption(description = "test3", longName = "debug3", shortName = "i", value = 3) | |
45 | - public void setParam2(int s) | |
46 | - { | |
47 | - System.out.println("test3: " + s); | |
62 | + try { | |
63 | + DefaultDviContext ctx = new DefaultDviContext(); | |
64 | + ViewSpec viewSpec = new ViewSpec(ctx); | |
65 | + for (String path : getArgs()) { | |
66 | + File file = new File(path); | |
67 | + DviDocument doc = ctx.openDviDocument(file); | |
68 | + DviToolkit toolkit = ctx.getDviToolkit(); | |
69 | + for (DviPage page : doc.getPages()) { | |
70 | + int pn = page.getPageNumber() + 1; | |
71 | + DviRect[] bboxes = toolkit.computeBoundingBoxes(doc, viewSpec.getResolution()); | |
72 | + DviRect bbox = DviRect.union(bboxes); | |
73 | + bbox = bbox.addPadding(8); | |
74 | + BufferedImage img = toolkit.renderToBufferedImage(page, bbox, viewSpec); | |
75 | + String filename = String.format("sample/page%06d.png", pn); | |
76 | + File png = new File(filename); | |
77 | + ImageIO.write(img, "PNG", png); | |
78 | + System.out.printf("[%d]", pn); | |
79 | + } | |
80 | + } | |
81 | + return Command.EXIT_SUCCESS; | |
82 | + } catch (Exception e) { | |
83 | + throw new CommandException(e); | |
84 | + } | |
48 | 85 | } |
49 | 86 | |
50 | 87 | @Override |
@@ -1,44 +0,0 @@ | ||
1 | -package jp.sourceforge.dvibrowser.dvi2epub; | |
2 | - | |
3 | -import jp.sourceforge.dvibrowser.dvi2epub.reflect.Dispatcher; | |
4 | -import jp.sourceforge.dvibrowser.dvi2epub.reflect.MemberWalkerException; | |
5 | - | |
6 | -public class Test1 { | |
7 | - public void test(String data) | |
8 | - { | |
9 | - System.out.println("String data: " + data); | |
10 | - } | |
11 | - | |
12 | - public void test(Object o) | |
13 | - { | |
14 | - System.out.println("Object data: " + o); | |
15 | - } | |
16 | - | |
17 | - public static void main(String[] args) throws MemberWalkerException { | |
18 | - Test1 test1 = new Test1(); | |
19 | - Object o = "hoge"; | |
20 | - String s = "foo"; | |
21 | - System.out.println("Class: " + o.getClass()); | |
22 | - test1.test(o); | |
23 | - test1.test(s); | |
24 | - | |
25 | - { | |
26 | - Dispatcher dispatcher = new Dispatcher(test1, "test", o); | |
27 | - if (dispatcher.dispatch()) { | |
28 | - System.out.println("Output = " + dispatcher.getResult()); | |
29 | - } else { | |
30 | - System.out.println("Invocation failure."); | |
31 | - } | |
32 | - } | |
33 | - | |
34 | - { | |
35 | - Dispatcher dispatcher = new Dispatcher(test1, "test", 123); | |
36 | - if (dispatcher.dispatch()) { | |
37 | - System.out.println("Output = " + dispatcher.getResult()); | |
38 | - } else { | |
39 | - System.out.println("Invocation failure."); | |
40 | - } | |
41 | - } | |
42 | - | |
43 | - } | |
44 | -} |
@@ -1,17 +1,33 @@ | ||
1 | 1 | /* |
2 | - * Copyright 2012 Take-Yuki NAGAO | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
3 | 4 | * |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | - * you may not use this file except in compliance with the License. | |
6 | - * You may obtain a copy of the License at | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
7 | 8 | * |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | - * | |
10 | - * Unless required by applicable law or agreed to in writing, software | |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | - * See the License for the specific language governing permissions and | |
14 | - * limitations under the License. | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
15 | 31 | */ |
16 | 32 | |
17 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.cmd; |
@@ -1,17 +1,33 @@ | ||
1 | 1 | /* |
2 | - * Copyright 2012 Take-Yuki NAGAO | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
3 | 4 | * |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | - * you may not use this file except in compliance with the License. | |
6 | - * You may obtain a copy of the License at | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
7 | 8 | * |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | - * | |
10 | - * Unless required by applicable law or agreed to in writing, software | |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | - * See the License for the specific language governing permissions and | |
14 | - * limitations under the License. | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
15 | 31 | */ |
16 | 32 | |
17 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.cmd; |
@@ -30,7 +46,7 @@ public abstract class AnnotatedCommand extends AbstractCommand { | ||
30 | 46 | parser = new AnnotatedCommandLineParser(this); |
31 | 47 | } |
32 | 48 | |
33 | - @BooleanValueOption(shortName = "h", longName = "help", description = "Show help") | |
49 | + @BooleanValueOption(shortName = "h", longName = "help", description = "Show this information") | |
34 | 50 | public void wantHelp(boolean want) { |
35 | 51 | this.wantHelp = want; |
36 | 52 | } |
@@ -1,3 +1,35 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
31 | + */ | |
32 | + | |
1 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.cmd; |
2 | 34 | |
3 | 35 | import java.io.PrintWriter; |
@@ -19,7 +51,7 @@ public class AnnotatedCommandLineParser implements CommandLineParser { | ||
19 | 51 | } |
20 | 52 | |
21 | 53 | protected void scanOptions() throws CommandException { |
22 | - OptionAdapter adapter = new OptionAdapter(mapper); | |
54 | + OptionParserAdapter adapter = new OptionParserAdapter(mapper); | |
23 | 55 | MemberWalker walker = new MemberWalker(adapter); |
24 | 56 | try { |
25 | 57 | walker.walk(command); |
@@ -1,17 +1,33 @@ | ||
1 | 1 | /* |
2 | - * Copyright 2012 Take-Yuki NAGAO | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
3 | 4 | * |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | - * you may not use this file except in compliance with the License. | |
6 | - * You may obtain a copy of the License at | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
7 | 8 | * |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | - * | |
10 | - * Unless required by applicable law or agreed to in writing, software | |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | - * See the License for the specific language governing permissions and | |
14 | - * limitations under the License. | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
15 | 31 | */ |
16 | 32 | |
17 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.cmd; |
@@ -1,17 +1,33 @@ | ||
1 | 1 | /* |
2 | - * Copyright 2012 Take-Yuki NAGAO | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
3 | 4 | * |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | - * you may not use this file except in compliance with the License. | |
6 | - * You may obtain a copy of the License at | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
7 | 8 | * |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | - * | |
10 | - * Unless required by applicable law or agreed to in writing, software | |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | - * See the License for the specific language governing permissions and | |
14 | - * limitations under the License. | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
15 | 31 | */ |
16 | 32 | |
17 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.cmd; |
@@ -1,3 +1,35 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
31 | + */ | |
32 | + | |
1 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.cmd; |
2 | 34 | |
3 | 35 | import java.io.PrintWriter; |
@@ -1,3 +1,35 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
31 | + */ | |
32 | + | |
1 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.cmd; |
2 | 34 | |
3 | 35 | import java.lang.reflect.InvocationTargetException; |
@@ -1,45 +0,0 @@ | ||
1 | -package jp.sourceforge.dvibrowser.dvi2epub.cmd; | |
2 | - | |
3 | -import java.io.PrintWriter; | |
4 | -import java.lang.reflect.Method; | |
5 | - | |
6 | -import jp.sourceforge.dvibrowser.dvi2epub.reflect.MemberWalkerAdapter; | |
7 | -import jp.sourceforge.dvibrowser.dvi2epub.reflect.MemberWalkerException; | |
8 | - | |
9 | -final class FormatAdapter extends MemberWalkerAdapter { | |
10 | - private final PrintWriter writer; | |
11 | - | |
12 | - FormatAdapter(PrintWriter writer) { | |
13 | - this.writer = writer; | |
14 | - } | |
15 | - | |
16 | - public void processMethod(Object o, Method method) | |
17 | - throws MemberWalkerException { | |
18 | -// try { | |
19 | -// Annotation a = mapper.getAnnotationForOption(method, state.getOptionName()); | |
20 | -// if (a != null) { | |
21 | -// Dispatcher<Object[]> d = new Dispatcher<Object[]>(mapper, "map", a); | |
22 | -// if (d.dispatch()) { | |
23 | -// Object[] args = d.getResult(); | |
24 | -// method.invoke(o, args); | |
25 | -// setDone(true); | |
26 | -// return; | |
27 | -// } | |
28 | -// } | |
29 | -// } catch (Exception ex) { | |
30 | -//// ex.printStackTrace(); | |
31 | -// state.stopWithError(ex); | |
32 | -// return; | |
33 | -// } | |
34 | - } | |
35 | - | |
36 | -// public OptionMapper getMapper() | |
37 | -// { | |
38 | -// return mapper; | |
39 | -// } | |
40 | -// | |
41 | - public PrintWriter getWriter() { | |
42 | - return writer; | |
43 | - } | |
44 | - | |
45 | -} | |
\ No newline at end of file |
@@ -1,3 +1,35 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
31 | + */ | |
32 | + | |
1 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.cmd; |
2 | 34 | |
3 | 35 | import java.lang.annotation.Annotation; |
@@ -1,38 +0,0 @@ | ||
1 | -package jp.sourceforge.dvibrowser.dvi2epub.cmd; | |
2 | - | |
3 | -import java.lang.reflect.Method; | |
4 | -import java.util.ArrayList; | |
5 | -import java.util.List; | |
6 | - | |
7 | -import jp.sourceforge.dvibrowser.dvi2epub.reflect.MemberWalkerAdapter; | |
8 | -import jp.sourceforge.dvibrowser.dvi2epub.reflect.MemberWalkerException; | |
9 | - | |
10 | -final class OptionAdapter extends MemberWalkerAdapter { | |
11 | - private final List<Option> options = new ArrayList<Option>(); | |
12 | - private final OptionMapper mapper; | |
13 | - | |
14 | - OptionAdapter(OptionMapper mapper) { | |
15 | - this.mapper = mapper; | |
16 | - } | |
17 | - | |
18 | - public void processMethod(Object o, Method method) | |
19 | - throws MemberWalkerException { | |
20 | - try { | |
21 | - Option option = mapper.getOption(method); | |
22 | - if (option != null) | |
23 | - options.add(option); | |
24 | - } catch (Exception ex) { | |
25 | - throw new MemberWalkerException(ex); | |
26 | - } | |
27 | - } | |
28 | - | |
29 | - public OptionMapper getMapper() | |
30 | - { | |
31 | - return mapper; | |
32 | - } | |
33 | - | |
34 | - public List<Option> getOptions() { | |
35 | - return options; | |
36 | - } | |
37 | - | |
38 | -} | |
\ No newline at end of file |
@@ -1,3 +1,35 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
31 | + */ | |
32 | + | |
1 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.cmd; |
2 | 34 | |
3 | 35 | import java.lang.reflect.Method; |
@@ -0,0 +1,70 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
31 | + */ | |
32 | + | |
33 | +package jp.sourceforge.dvibrowser.dvi2epub.cmd; | |
34 | + | |
35 | +import java.lang.reflect.Method; | |
36 | +import java.util.ArrayList; | |
37 | +import java.util.List; | |
38 | + | |
39 | +import jp.sourceforge.dvibrowser.dvi2epub.reflect.MemberWalkerAdapter; | |
40 | +import jp.sourceforge.dvibrowser.dvi2epub.reflect.MemberWalkerException; | |
41 | + | |
42 | +final class OptionParserAdapter extends MemberWalkerAdapter { | |
43 | + private final List<Option> options = new ArrayList<Option>(); | |
44 | + private final OptionMapper mapper; | |
45 | + | |
46 | + OptionParserAdapter(OptionMapper mapper) { | |
47 | + this.mapper = mapper; | |
48 | + } | |
49 | + | |
50 | + public void processMethod(Object o, Method method) | |
51 | + throws MemberWalkerException { | |
52 | + try { | |
53 | + Option option = mapper.getOption(method); | |
54 | + if (option != null) | |
55 | + options.add(option); | |
56 | + } catch (Exception ex) { | |
57 | + throw new MemberWalkerException(ex); | |
58 | + } | |
59 | + } | |
60 | + | |
61 | + public OptionMapper getMapper() | |
62 | + { | |
63 | + return mapper; | |
64 | + } | |
65 | + | |
66 | + public List<Option> getOptions() { | |
67 | + return options; | |
68 | + } | |
69 | + | |
70 | +} | |
\ No newline at end of file |
@@ -1,3 +1,35 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
31 | + */ | |
32 | + | |
1 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.cmd; |
2 | 34 | |
3 | 35 | import java.io.PrintWriter; |
@@ -1,3 +1,35 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
31 | + */ | |
32 | + | |
1 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.cmd; |
2 | 34 | |
3 | 35 | import java.util.ArrayList; |
@@ -0,0 +1,25 @@ | ||
1 | +package jp.sourceforge.dvibrowser.dvi2epub.epub; | |
2 | + | |
3 | +public class BookEntry { | |
4 | + private final String path; | |
5 | + private final String id; | |
6 | + private final String mimeType; | |
7 | + | |
8 | + public BookEntry(String path, String id, String mimeType) { | |
9 | + this.path = path; | |
10 | + this.id = id; | |
11 | + this.mimeType = mimeType; | |
12 | + } | |
13 | + | |
14 | + public String getPath() { | |
15 | + return path; | |
16 | + } | |
17 | + | |
18 | + public String getId() { | |
19 | + return id; | |
20 | + } | |
21 | + | |
22 | + public String getMimeType() { | |
23 | + return mimeType; | |
24 | + } | |
25 | +} |
@@ -0,0 +1,264 @@ | ||
1 | +package jp.sourceforge.dvibrowser.dvi2epub.epub; | |
2 | + | |
3 | +import java.io.ByteArrayOutputStream; | |
4 | +import java.io.IOException; | |
5 | +import java.io.OutputStream; | |
6 | +import java.io.UnsupportedEncodingException; | |
7 | +import java.util.ArrayList; | |
8 | +import java.util.List; | |
9 | +import java.util.UUID; | |
10 | +import java.util.zip.ZipEntry; | |
11 | +import java.util.zip.ZipOutputStream; | |
12 | + | |
13 | +import javax.xml.parsers.DocumentBuilder; | |
14 | +import javax.xml.parsers.DocumentBuilderFactory; | |
15 | +import javax.xml.parsers.ParserConfigurationException; | |
16 | +import javax.xml.transform.OutputKeys; | |
17 | +import javax.xml.transform.Transformer; | |
18 | +import javax.xml.transform.TransformerException; | |
19 | +import javax.xml.transform.TransformerFactory; | |
20 | +import javax.xml.transform.dom.DOMSource; | |
21 | +import javax.xml.transform.stream.StreamResult; | |
22 | + | |
23 | +import org.w3c.dom.DOMImplementation; | |
24 | +import org.w3c.dom.Document; | |
25 | +import org.w3c.dom.Element; | |
26 | + | |
27 | +public class EpubWriter | |
28 | +{ | |
29 | + private static final String NCX_VERSION = "2005-1"; | |
30 | + private static final String BOOK_OPF_PATH = "book.opf"; | |
31 | + private static final String BOOK_NCX_PATH = "book.ncx"; | |
32 | + public static final String DEFAULT_LANGUAGE = "en"; | |
33 | + public static final String CONTAINER_NS = "urn:oasis:names:tc:opendocument:xmlns:container"; | |
34 | + public static final String OPF_NS = "http://www.idpf.org/2007/opf"; | |
35 | + public static final String NCX_NS = "http://www.daisy.org/z3986/2005/ncx/"; | |
36 | + public static final String PURL_NS = "http://purl.org/dc/elements/1.1/"; | |
37 | + private final ZipOutputStream zipOutput; | |
38 | + private final UUID uuid; | |
39 | + private String title; | |
40 | + private String author; | |
41 | + private String language; | |
42 | + | |
43 | + private final List<BookEntry> entries = new ArrayList<BookEntry>(); | |
44 | + | |
45 | + public EpubWriter(OutputStream os) throws TransformerException, IOException, ParserConfigurationException | |
46 | + { | |
47 | + zipOutput = new ZipOutputStream(os); | |
48 | + writeXml("META-INF/container.xml", createContainerDOM()); | |
49 | + uuid = UUID.randomUUID(); | |
50 | + } | |
51 | + | |
52 | + public void close() throws IOException, ParserConfigurationException, TransformerException | |
53 | + { | |
54 | + writeXml(BOOK_NCX_PATH, createNCXDOM()); | |
55 | + writeXml(BOOK_OPF_PATH, createOPFDOM()); | |
56 | + writeRawFile("mimetype", "application/epub+zip"); | |
57 | + zipOutput.flush(); | |
58 | + zipOutput.close(); | |
59 | + } | |
60 | + | |
61 | + public void writeXml(String path, Document doc) throws TransformerException, IOException { | |
62 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
63 | + TransformerFactory tf = TransformerFactory.newInstance(); | |
64 | + Transformer t = tf.newTransformer(); | |
65 | + t.setOutputProperty(OutputKeys.INDENT, "yes"); | |
66 | + t.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); | |
67 | + DOMSource source = new DOMSource(doc); | |
68 | + StreamResult result = new StreamResult(baos); | |
69 | + t.transform(source, result); | |
70 | + baos.close(); | |
71 | + byte[] data = baos.toByteArray(); | |
72 | + | |
73 | + ZipEntry entry = new ZipEntry(path); | |
74 | + zipOutput.putNextEntry(entry); | |
75 | + zipOutput.write(data); | |
76 | + zipOutput.closeEntry(); | |
77 | + } | |
78 | + | |
79 | + public void writeFile(String path, String mimeType, String data) throws UnsupportedEncodingException, IOException { | |
80 | + writeRawFile(path, data); | |
81 | + BookEntry bookEntry = new BookEntry(path, "http://dummy.url/" + path, mimeType); | |
82 | + entries.add(bookEntry); | |
83 | + } | |
84 | + | |
85 | + public void writeRawFile(String path, String data) throws UnsupportedEncodingException, IOException { | |
86 | + ZipEntry entry = new ZipEntry(path); | |
87 | + zipOutput.putNextEntry(entry); | |
88 | + zipOutput.write(data.getBytes("UTF-8")); | |
89 | + zipOutput.closeEntry(); | |
90 | + } | |
91 | + | |
92 | + protected Document createContainerDOM() throws ParserConfigurationException { | |
93 | + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | |
94 | + factory.setNamespaceAware(true); | |
95 | + DocumentBuilder db = factory.newDocumentBuilder(); | |
96 | + DOMImplementation dom = db.getDOMImplementation(); | |
97 | + Document doc = dom.createDocument(CONTAINER_NS, "container", null); | |
98 | + Element container = doc.getDocumentElement(); | |
99 | + container.setAttribute("version", "1.0"); | |
100 | + Element rootfiles = doc.createElementNS(CONTAINER_NS, "rootfiles"); | |
101 | + container.appendChild(rootfiles); | |
102 | + Element rootfile = doc.createElementNS(CONTAINER_NS, "rootfile"); | |
103 | + rootfile.setAttribute("full-path", BOOK_OPF_PATH); | |
104 | + rootfile.setAttribute("media-type", "application/oebps-package+xml"); | |
105 | + rootfiles.appendChild(rootfile); | |
106 | + return doc; | |
107 | + } | |
108 | + | |
109 | + protected Document createNCXDOM() throws ParserConfigurationException { | |
110 | + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | |
111 | + factory.setNamespaceAware(true); | |
112 | + DocumentBuilder db = factory.newDocumentBuilder(); | |
113 | + DOMImplementation dom = db.getDOMImplementation(); | |
114 | + Document doc = dom.createDocument(NCX_NS, "ncx", null); | |
115 | + Element ncx = doc.getDocumentElement(); | |
116 | + ncx.setAttribute("version", NCX_VERSION); | |
117 | + ncx.setAttribute("lang", getLanguage()); | |
118 | + Element head = doc.createElementNS(NCX_NS, "head"); | |
119 | + ncx.appendChild(head); | |
120 | + | |
121 | + addMeta(doc, head, "dtb:uid", uuid.toString()); | |
122 | + addMeta(doc, head, "dtb:depth", "1"); | |
123 | + addMeta(doc, head, "dtb:totalPageCount", "0"); | |
124 | + addMeta(doc, head, "dtb:maxPageNumber", "0"); | |
125 | + | |
126 | + Element docTitle = doc.createElementNS(NCX_NS, "docTitle"); | |
127 | + Element titleElem2 = doc.createElement("text"); | |
128 | + titleElem2.setTextContent(title == null ? "NO TITLE" : title); | |
129 | + docTitle.appendChild(titleElem2); | |
130 | + ncx.appendChild(docTitle); | |
131 | + | |
132 | + Element docAuthor = doc.createElementNS(NCX_NS, "docAuthor"); | |
133 | + Element authorElem2 = doc.createElement("text"); | |
134 | + authorElem2.setTextContent(author == null ? "NO AUTHOR" : author); | |
135 | + docAuthor.appendChild(authorElem2); | |
136 | + ncx.appendChild(docAuthor); | |
137 | + | |
138 | + Element navMap = doc.createElementNS(NCX_NS, "navMap"); | |
139 | + buildNavMap(doc, navMap); | |
140 | + ncx.appendChild(navMap); | |
141 | + | |
142 | + return doc; | |
143 | + } | |
144 | + | |
145 | + protected void addMeta(Document doc, Element head, String name, String value) { | |
146 | + Element meta = doc.createElementNS(NCX_NS, "meta"); | |
147 | + meta.setAttribute("name", name); | |
148 | + meta.setAttribute("content", value); | |
149 | + head.appendChild(meta); | |
150 | + } | |
151 | + | |
152 | + public String getLanguage() { | |
153 | + return language == null ? DEFAULT_LANGUAGE : language; | |
154 | + } | |
155 | + | |
156 | + protected Document createOPFDOM() throws ParserConfigurationException { | |
157 | + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | |
158 | + factory.setNamespaceAware(true); | |
159 | + DocumentBuilder db = factory.newDocumentBuilder(); | |
160 | + DOMImplementation dom = db.getDOMImplementation(); | |
161 | + Document doc = dom.createDocument(OPF_NS, "package", null); | |
162 | + Element pkg = doc.getDocumentElement(); | |
163 | + pkg.setAttribute("unique-identifier", getUniqueIdentifierName()); | |
164 | + Element metadata = doc.createElementNS(OPF_NS, "metadata"); | |
165 | + pkg.appendChild(metadata); | |
166 | + | |
167 | + Element titleElem = doc.createElement("title"); | |
168 | + titleElem.setTextContent(title == null ? "NO TITLE" : title); | |
169 | + metadata.appendChild(titleElem); | |
170 | + | |
171 | + Element langElem = doc.createElement("language"); | |
172 | + langElem.setTextContent(getLanguage()); | |
173 | + metadata.appendChild(langElem); | |
174 | + | |
175 | + Element identifierElem = doc.createElement("identifier"); | |
176 | + identifierElem.setAttribute("scheme", "URI"); | |
177 | + identifierElem.setAttribute("id", getUniqueIdentifierName()); | |
178 | + identifierElem.setTextContent(uuid.toString()); | |
179 | + metadata.appendChild(identifierElem); | |
180 | + | |
181 | + Element manifestElem = doc.createElementNS(OPF_NS, "manifest"); | |
182 | + pkg.appendChild(manifestElem); | |
183 | + | |
184 | + buildManifest(doc, manifestElem); | |
185 | + | |
186 | + Element spineElem = doc.createElementNS(OPF_NS, "spine"); | |
187 | + spineElem.setAttribute("toc", "ncx"); | |
188 | + pkg.appendChild(spineElem); | |
189 | + buildSpine(doc, spineElem); | |
190 | + | |
191 | + return doc; | |
192 | + } | |
193 | + | |
194 | + protected void buildSpine(Document doc, Element spine) { | |
195 | + Element itemref = doc.createElement("itemref"); | |
196 | + itemref.setAttribute("idref", "http://dummy.url/index.html"); | |
197 | + spine.appendChild(itemref); | |
198 | + } | |
199 | + | |
200 | + protected void buildManifest(Document doc, Element manifest) { | |
201 | + for (BookEntry entry : entries) { | |
202 | + Element item = doc.createElementNS(OPF_NS, "item"); | |
203 | + item.setAttribute("id", entry.getId()); | |
204 | + item.setAttribute("href", entry.getPath()); | |
205 | + item.setAttribute("media-type", "application/x-html"); | |
206 | + manifest.appendChild(item); | |
207 | + } | |
208 | + | |
209 | + Element item = doc.createElementNS(OPF_NS, "item"); | |
210 | + item.setAttribute("id", "ncx"); | |
211 | + item.setAttribute("href", BOOK_NCX_PATH); | |
212 | + item.setAttribute("media-type", "application/x-dtbncx+xml"); | |
213 | + manifest.appendChild(item); | |
214 | + } | |
215 | + | |
216 | + protected void buildNavMap(Document doc, Element navMap) { | |
217 | + for (BookEntry entry : entries) { | |
218 | + Element navPoint = doc.createElementNS(NCX_NS, "navPoint"); | |
219 | + navPoint.setAttribute("class", "chapter"); | |
220 | + navPoint.setAttribute("id", "dummy"); | |
221 | + navPoint.setAttribute("playOrder", "1"); | |
222 | + | |
223 | + Element navLabel = doc.createElementNS(NCX_NS, "navLabel"); | |
224 | + Element text = doc.createElementNS(NCX_NS, "text"); | |
225 | + text.setTextContent(entry.getPath()); | |
226 | + navLabel.appendChild(text); | |
227 | + navPoint.appendChild(navLabel); | |
228 | + | |
229 | + Element content = doc.createElementNS(NCX_NS, "content"); | |
230 | + content.setAttribute("src", entry.getPath()); | |
231 | + | |
232 | + navPoint.appendChild(content); | |
233 | + navMap.appendChild(navPoint); | |
234 | + } | |
235 | + } | |
236 | + | |
237 | + public String getUniqueIdentifierName() { | |
238 | + return "BookId"; | |
239 | + } | |
240 | + | |
241 | + public ZipOutputStream getZipOutput() { | |
242 | + return zipOutput; | |
243 | + } | |
244 | + | |
245 | + public String getTitle() { | |
246 | + return title; | |
247 | + } | |
248 | + | |
249 | + public void setTitle(String title) { | |
250 | + this.title = title; | |
251 | + } | |
252 | + | |
253 | + public String getAuthor() { | |
254 | + return author; | |
255 | + } | |
256 | + | |
257 | + public void setAuthor(String author) { | |
258 | + this.author = author; | |
259 | + } | |
260 | + | |
261 | + public UUID getUuid() { | |
262 | + return uuid; | |
263 | + } | |
264 | +} |
@@ -1,3 +1,35 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
31 | + */ | |
32 | + | |
1 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.opt; |
2 | 34 | |
3 | 35 | import java.lang.annotation.Retention; |
@@ -1,3 +1,35 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
31 | + */ | |
32 | + | |
1 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.opt; |
2 | 34 | |
3 | 35 | import java.lang.annotation.Annotation; |
@@ -1,3 +1,35 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
31 | + */ | |
32 | + | |
1 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.opt; |
2 | 34 | |
3 | 35 | import java.lang.annotation.Retention; |
@@ -1,17 +1,33 @@ | ||
1 | 1 | /* |
2 | - * Copyright 2012 Take-Yuki NAGAO | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
3 | 4 | * |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | - * you may not use this file except in compliance with the License. | |
6 | - * You may obtain a copy of the License at | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
7 | 8 | * |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | - * | |
10 | - * Unless required by applicable law or agreed to in writing, software | |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | - * See the License for the specific language governing permissions and | |
14 | - * limitations under the License. | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
15 | 31 | */ |
16 | 32 | |
17 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.opt; |
@@ -1,3 +1,35 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
31 | + */ | |
32 | + | |
1 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.reflect; |
2 | 34 | |
3 | 35 | import java.lang.reflect.InvocationTargetException; |
@@ -22,6 +54,7 @@ extends MemberWalkerAdapter | ||
22 | 54 | throw new IllegalArgumentException("Too few arguments to invoke()."); |
23 | 55 | } |
24 | 56 | |
57 | + @SuppressWarnings("unchecked") | |
25 | 58 | public void processMethod(Object target, Method method) throws MemberWalkerException { |
26 | 59 | try { |
27 | 60 | if (method.getName().equals(getMethodName())) { |
@@ -1,25 +1,33 @@ | ||
1 | 1 | /* |
2 | -The MIT License | |
3 | - | |
4 | -Copyright (c) 2010 Takeyuki Nagao | |
5 | - | |
6 | -Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | -of this software and associated documentation files (the "Software"), to deal | |
8 | -in the Software without restriction, including without limitation the rights | |
9 | -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | -copies of the Software, and to permit persons to whom the Software is | |
11 | -furnished to do so, subject to the following conditions: | |
12 | - | |
13 | -The above copyright notice and this permission notice shall be included in | |
14 | -all copies or substantial portions of the Software. | |
15 | - | |
16 | -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
19 | -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | -THE SOFTWARE. | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
23 | 31 | */ |
24 | 32 | |
25 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.reflect; |
@@ -28,41 +36,9 @@ import java.lang.reflect.Field; | ||
28 | 36 | import java.lang.reflect.Member; |
29 | 37 | import java.lang.reflect.Method; |
30 | 38 | |
31 | -/** | |
32 | - * <p> | |
33 | - * 指定オブジェクトのすべてのメンバ(フィールド及びメソッド)を巡回して, 個々のメンバに対して特定の処理を行うためのクラス. 具体的な処理の内容は | |
34 | - * {@link MemberWalkerHandler} インターフェイスの実装クラスに記述して,コンストラクタ引数でそのインスタンスを指定する. | |
35 | - * </p> | |
36 | - * <p> | |
37 | - * 利用例を挙げる. <code><pre> | |
38 | - MyBean bean = new MyBean(); // ユーザ定義クラス | |
39 | - bean.setField1("hogehoge"); | |
40 | - bean.setField2(314); | |
41 | - | |
42 | - MemberWalker walker = new MemberWalker(new MemberWalkerAdapter() { | |
43 | - public void processField(Object o, Field field) | |
44 | - { | |
45 | - System.out.println("フィールド: " + field.getName()); | |
46 | - } | |
47 | - }); | |
48 | - walker.walk(bean); | |
49 | - * </pre></code> | |
50 | - * </p> | |
51 | - * | |
52 | - * @author nagaotakeyuki@gmail.com | |
53 | - */ | |
54 | - | |
55 | 39 | public class MemberWalker { |
56 | 40 | private final MemberWalkerHandler handler; |
57 | 41 | |
58 | - /** | |
59 | - * <p> | |
60 | - * 指定されたハンドラを持ったインスタンスを生成する. | |
61 | - * </p> | |
62 | - * | |
63 | - * @param handler | |
64 | - * メンバを見つけたときに呼び出されるハンドラ | |
65 | - */ | |
66 | 42 | public MemberWalker(MemberWalkerHandler handler) { |
67 | 43 | this.handler = handler; |
68 | 44 | if (handler == null) { |
@@ -75,14 +51,6 @@ public class MemberWalker { | ||
75 | 51 | return handler.wantMember(t, member); |
76 | 52 | } |
77 | 53 | |
78 | - /** | |
79 | - * 指定されたオブジェクトのすべてのメンバ(フィールドとメソッド)に対してハンドラを呼び出す. <code>public</code> | |
80 | - * でないメンバも処理の対象となる. | |
81 | - * | |
82 | - * @param t | |
83 | - * 対象となるオブジェクト | |
84 | - * @throws MemberWalkerException | |
85 | - */ | |
86 | 54 | public void walk(Object t) throws MemberWalkerException { |
87 | 55 | if (t == null) |
88 | 56 | throw new NullPointerException("Cannot walk about null object."); |
@@ -90,19 +58,17 @@ public class MemberWalker { | ||
90 | 58 | if (t.getClass().isPrimitive()) |
91 | 59 | return; |
92 | 60 | |
93 | - // Class#getFields() では public フィールドしか参照できないので | |
94 | - // クラスの階層を Object クラスまでたどってフィールドのエンコード処理を行う. | |
95 | 61 | for (Class<?> cls = t.getClass();; cls = cls.getSuperclass()) { |
96 | 62 | for (Method method : cls.getDeclaredMethods()) { |
97 | 63 | if (!wantMember(t, method)) |
98 | 64 | continue; |
99 | - method.setAccessible(true); // public 以外のメソッドにもアクセス出来るようにする. | |
65 | + method.setAccessible(true); | |
100 | 66 | handler.processMethod(t, method); |
101 | 67 | } |
102 | 68 | for (Field field : cls.getDeclaredFields()) { |
103 | 69 | if (!wantMember(t, field)) |
104 | 70 | continue; |
105 | - field.setAccessible(true); // public 以外のフィールドにもアクセス出来るようにする. | |
71 | + field.setAccessible(true); | |
106 | 72 | handler.processField(t, field); |
107 | 73 | } |
108 | 74 | if (cls == Object.class) |
@@ -1,26 +1,34 @@ | ||
1 | 1 | /* |
2 | -The MIT License | |
3 | - | |
4 | -Copyright (c) 2010 Takeyuki Nagao | |
5 | - | |
6 | -Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | -of this software and associated documentation files (the "Software"), to deal | |
8 | -in the Software without restriction, including without limitation the rights | |
9 | -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | -copies of the Software, and to permit persons to whom the Software is | |
11 | -furnished to do so, subject to the following conditions: | |
12 | - | |
13 | -The above copyright notice and this permission notice shall be included in | |
14 | -all copies or substantial portions of the Software. | |
15 | - | |
16 | -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
19 | -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | -THE SOFTWARE. | |
23 | -*/ | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
31 | + */ | |
24 | 32 | |
25 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.reflect; |
26 | 34 |
@@ -29,12 +37,6 @@ import java.lang.reflect.Member; | ||
29 | 37 | import java.lang.reflect.Method; |
30 | 38 | import java.lang.reflect.Modifier; |
31 | 39 | |
32 | -/** | |
33 | - * {@link MemberWalkerHandler} のためのアダプタクラス. | |
34 | - * @author nagaotakeyuki@gmail.com | |
35 | - * | |
36 | - */ | |
37 | - | |
38 | 40 | public class MemberWalkerAdapter implements MemberWalkerHandler |
39 | 41 | { |
40 | 42 | private boolean done; |
@@ -1,34 +1,37 @@ | ||
1 | 1 | /* |
2 | -The MIT License | |
3 | - | |
4 | -Copyright (c) 2010 Takeyuki Nagao | |
5 | - | |
6 | -Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | -of this software and associated documentation files (the "Software"), to deal | |
8 | -in the Software without restriction, including without limitation the rights | |
9 | -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | -copies of the Software, and to permit persons to whom the Software is | |
11 | -furnished to do so, subject to the following conditions: | |
12 | - | |
13 | -The above copyright notice and this permission notice shall be included in | |
14 | -all copies or substantial portions of the Software. | |
15 | - | |
16 | -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
19 | -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | -THE SOFTWARE. | |
23 | -*/ | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
31 | + */ | |
24 | 32 | |
25 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.reflect; |
26 | 34 | |
27 | -/** | |
28 | - * {@link MemberWalkerHandler} インターフェイスで例外をラップするための例外クラス. | |
29 | - * @author nagaotakeyuki@gmail.com | |
30 | - * | |
31 | - */ | |
32 | 35 | public class MemberWalkerException |
33 | 36 | extends Exception |
34 | 37 | { |
@@ -1,26 +1,34 @@ | ||
1 | 1 | /* |
2 | -The MIT License | |
3 | - | |
4 | -Copyright (c) 2010 Takeyuki Nagao | |
5 | - | |
6 | -Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | -of this software and associated documentation files (the "Software"), to deal | |
8 | -in the Software without restriction, including without limitation the rights | |
9 | -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | -copies of the Software, and to permit persons to whom the Software is | |
11 | -furnished to do so, subject to the following conditions: | |
12 | - | |
13 | -The above copyright notice and this permission notice shall be included in | |
14 | -all copies or substantial portions of the Software. | |
15 | - | |
16 | -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
19 | -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | -THE SOFTWARE. | |
23 | -*/ | |
2 | + * Copyright (c) 2012, Takeyuki Nagao | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or | |
6 | + * without modification, are permitted provided that the | |
7 | + * following conditions are met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above | |
10 | + * copyright notice, this list of conditions and the | |
11 | + * following disclaimer. | |
12 | + * * Redistributions in binary form must reproduce the above | |
13 | + * copyright notice, this list of conditions and the | |
14 | + * following disclaimer in the documentation and/or other | |
15 | + * materials provided with the distribution. | |
16 | + * | |
17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
18 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
19 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
22 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
29 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | + * OF SUCH DAMAGE. | |
31 | + */ | |
24 | 32 | |
25 | 33 | package jp.sourceforge.dvibrowser.dvi2epub.reflect; |
26 | 34 |
@@ -28,38 +36,8 @@ import java.lang.reflect.Field; | ||
28 | 36 | import java.lang.reflect.Member; |
29 | 37 | import java.lang.reflect.Method; |
30 | 38 | |
31 | -/** | |
32 | - * {@link MemberWalker} クラスが個々のメンバに対して行う | |
33 | - * 処理内容を記述するためのインターフェイス. | |
34 | - * | |
35 | - * @author nagaotakeyuki@gmail.com | |
36 | - * | |
37 | - */ | |
38 | 39 | public interface MemberWalkerHandler { |
39 | - /** | |
40 | - * 特定のメンバを {@link #processField(Object, Field)} 及び {@link #processMethod(Object, Method)} | |
41 | - * の呼び出し対象とするかどうかを決定するメソッド | |
42 | - * @param t 対象オブジェクト | |
43 | - * @param member 対象オブジェクトのメンバ(フィールドもしくはメソッド) | |
44 | - * @return <code>member</code> で指定されたメンバを呼び出し対象とする場合に <code>true</code>. | |
45 | - * それ以外は <code>false</code> | |
46 | - * @throws MemberWalkerException | |
47 | - */ | |
48 | 40 | boolean wantMember(Object t, Member member) throws MemberWalkerException; |
49 | - | |
50 | - /** | |
51 | - * フィールドが見つかった場合に呼び出されるメソッド. | |
52 | - * @param t 対象オブジェクト | |
53 | - * @param field 見つかったフィールド | |
54 | - * @throws MemberWalkerException | |
55 | - */ | |
56 | 41 | void processField(Object t, Field field) throws MemberWalkerException; |
57 | - | |
58 | - /** | |
59 | - * メソッドが見つかった場合に呼び出されるメソッド. | |
60 | - * @param t 対象オブジェクト | |
61 | - * @param method 見つかったメソッド | |
62 | - * @throws MemberWalkerException | |
63 | - */ | |
64 | 42 | void processMethod(Object t, Method method) throws MemberWalkerException; |
65 | 43 | } |