ff7d0f1594132933d9deb3a614eb8d283e55d6f1
[mir.git] / source / mircoders / producer / reader / SupplementalProducerNodeBuilders.java
1 /*
2  * Copyright (C) 2001, 2002  The Mir-coders group
3  *
4  * This file is part of Mir.
5  *
6  * Mir is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Mir is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Mir; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * In addition, as a special exception, The Mir-coders gives permission to link
21  * the code of this program with the com.oreilly.servlet library, any library
22  * licensed under the Apache Software License, The Sun (tm) Java Advanced
23  * Imaging library (JAI), The Sun JIMI library (or with modified versions of
24  * the above that use the same license as the above), and distribute linked
25  * combinations including the two.  You must obey the GNU General Public
26  * License in all respects for all of the code used other than the above
27  * mentioned libraries.  If you modify this file, you may extend this exception
28  * to your version of the file, but you are not obligated to do so.  If you do
29  * not wish to do so, delete this exception statement from your version.
30  */
31
32 package mircoders.producer.reader;
33
34 import java.util.*;
35 import mir.producer.*;
36 import mir.producer.reader.*;
37 import mir.util.*;
38 import mir.entity.adapter.*;
39 import mir.generator.*;
40 import mircoders.producer.*;
41
42 public class SupplementalProducerNodeBuilders {
43
44   public static void registerBuilders(ProducerNodeBuilderLibrary aBuilderLibrary, EntityAdapterModel aModel) throws ProducerConfigExc {
45     aBuilderLibrary.registerBuilder("ModifyContent", ContentModifyingProducerNodeBuilder.class);
46     aBuilderLibrary.registerBuilder("MarkContent", ContentMarkingProducerNodeBuilder.class);
47     aBuilderLibrary.registerBuilder("GenerateMedia", MediaGeneratingProducerNodeBuilder.class);
48
49
50     aBuilderLibrary.registerBuilder("PDFPreFormat", PDFPreFormattingProducerNodeBuilder.class);
51     aBuilderLibrary.registerBuilder("PDFGenerate", PDFGeneratingProducerNodeBuilder.class);
52   }
53
54   private final static String   MARKER_KEY_ATTRIBUTE = DefaultProducerNodeBuilders.KEY_ATTRIBUTE;
55   private final static String[] MARKER_REQUIRED_ATTRIBUTES = { MARKER_KEY_ATTRIBUTE };
56   private final static String[] MARKER_OPTIONAL_ATTRIBUTES = {};
57   private final static String[] MARKER_SUBNODES = {};
58
59   public static class ContentMarkingProducerNodeBuilder extends DefaultProducerNodeBuilders.AbstractProducerNodeBuilder {
60
61     private String key;
62
63     public ContentMarkingProducerNodeBuilder() {
64       super(MARKER_SUBNODES);
65     }
66
67     public void setAttributes(Map anAttributes) throws ProducerConfigExc {
68       ReaderTool.checkAttributes(anAttributes, MARKER_REQUIRED_ATTRIBUTES, MARKER_OPTIONAL_ATTRIBUTES);
69
70       key = (String) anAttributes.get(MARKER_KEY_ATTRIBUTE);
71     };
72
73     public ProducerNode constructNode() {
74       return new ContentMarkingProducerNode(key);
75     };
76   }
77
78
79   private final static String   CONTENT_MODIFIER_KEY_ATTRIBUTE = DefaultProducerNodeBuilders.KEY_ATTRIBUTE;
80   private final static String   CONTENT_MODIFIER_FIELD_ATTRIBUTE = "field";
81   private final static String   CONTENT_MODIFIER_VALUE_ATTRIBUTE = "value";
82   private final static String[] CONTENT_MODIFIER_REQUIRED_ATTRIBUTES = { CONTENT_MODIFIER_KEY_ATTRIBUTE, CONTENT_MODIFIER_FIELD_ATTRIBUTE, CONTENT_MODIFIER_VALUE_ATTRIBUTE };
83   private final static String[] CONTENT_MODIFIER_OPTIONAL_ATTRIBUTES = {};
84   private final static String[] CONTENT_MODIFIER_SUBNODES = {};
85
86   public static class ContentModifyingProducerNodeBuilder extends DefaultProducerNodeBuilders.AbstractProducerNodeBuilder {
87
88     private String key;
89     private String field;
90     private String value;
91
92     public ContentModifyingProducerNodeBuilder() {
93       super(CONTENT_MODIFIER_SUBNODES);
94     }
95
96     public void setAttributes(Map anAttributes) throws ProducerConfigExc {
97       ReaderTool.checkAttributes(anAttributes, CONTENT_MODIFIER_REQUIRED_ATTRIBUTES, CONTENT_MODIFIER_OPTIONAL_ATTRIBUTES);
98
99       key = (String) anAttributes.get(CONTENT_MODIFIER_KEY_ATTRIBUTE);
100       field = (String) anAttributes.get(CONTENT_MODIFIER_FIELD_ATTRIBUTE);
101       value = (String) anAttributes.get(CONTENT_MODIFIER_VALUE_ATTRIBUTE);
102     };
103
104     public ProducerNode constructNode() {
105       return new ContentModifyingProducerNode(key, field, value);
106     };
107   }
108
109   private final static String   MEDIA_KEY_ATTRIBUTE = DefaultProducerNodeBuilders.KEY_ATTRIBUTE;
110   private final static String[] MEDIA_REQUIRED_ATTRIBUTES = { MEDIA_KEY_ATTRIBUTE };
111   private final static String[] MEDIA_OPTIONAL_ATTRIBUTES = {};
112   private final static String[] MEDIA_SUBNODES = {};
113
114   public static class MediaGeneratingProducerNodeBuilder extends DefaultProducerNodeBuilders.AbstractProducerNodeBuilder {
115
116     private String key;
117
118     public MediaGeneratingProducerNodeBuilder() {
119       super(MEDIA_SUBNODES);
120     }
121
122     public void setAttributes(Map anAttributes) throws ProducerConfigExc {
123       ReaderTool.checkAttributes(anAttributes, MEDIA_REQUIRED_ATTRIBUTES, MEDIA_OPTIONAL_ATTRIBUTES);
124
125       key = (String) anAttributes.get(MEDIA_KEY_ATTRIBUTE);
126     };
127
128     public ProducerNode constructNode() {
129       return new MediaGeneratingProducerNode(key);
130     };
131   }
132
133   public static class PDFPreFormattingProducerNodeBuilder extends DefaultProducerNodeBuilders.AbstractProducerNodeBuilder {
134     private final static String   MARKER_KEY_ATTRIBUTE = DefaultProducerNodeBuilders.KEY_ATTRIBUTE;
135     private final static String   PDF_NUM_LINES_ATTRIBUTE = "numLinesBetweenImages";
136     private final static String   PDF_CONTENT_WIDTH_ATTRIBUTE = "contentAreaWidthCM";
137     private final static String   PDF_CHAR_WIDTH_ATTRIBUTE = "charWidthCM";
138     private final static String   PDF_PIXEL_WIDTH_ATTRIBUTE = "pixelWidthCM";
139     private final static String   PDF_LINE_HEIGHT_ATTRIBUTE = "lineHeightCM";
140     private final static String[] MARKER_REQUIRED_ATTRIBUTES = { MARKER_KEY_ATTRIBUTE, PDF_NUM_LINES_ATTRIBUTE, PDF_CONTENT_WIDTH_ATTRIBUTE,PDF_CHAR_WIDTH_ATTRIBUTE,PDF_PIXEL_WIDTH_ATTRIBUTE,PDF_LINE_HEIGHT_ATTRIBUTE };
141     private final static String[] MARKER_OPTIONAL_ATTRIBUTES = {};
142     private final static String[] MARKER_SUBNODES = {};
143
144     private String key;
145     private String numLinesBetweenImages;
146     private String contentAreaWidthCM;
147     private String characterWidthCM;
148     private String pixelWidthCM;
149     private String lineHeightCM;
150
151     public PDFPreFormattingProducerNodeBuilder() {
152       super(MARKER_SUBNODES);
153     }
154
155     public void setAttributes(Map anAttributes) throws ProducerConfigExc {
156       ReaderTool.checkAttributes(anAttributes, MARKER_REQUIRED_ATTRIBUTES, MARKER_OPTIONAL_ATTRIBUTES);
157
158       key = (String) anAttributes.get(MARKER_KEY_ATTRIBUTE);
159       numLinesBetweenImages = (String) anAttributes.get(PDF_NUM_LINES_ATTRIBUTE);
160       contentAreaWidthCM = (String) anAttributes.get(PDF_CONTENT_WIDTH_ATTRIBUTE);
161       characterWidthCM = (String) anAttributes.get(PDF_CHAR_WIDTH_ATTRIBUTE);
162       pixelWidthCM   = (String) anAttributes.get(PDF_PIXEL_WIDTH_ATTRIBUTE);
163       lineHeightCM = (String) anAttributes.get(PDF_LINE_HEIGHT_ATTRIBUTE);
164
165
166     };
167
168     public ProducerNode constructNode() {
169       return new PDFPreFormattingProducerNode(key,numLinesBetweenImages,contentAreaWidthCM,characterWidthCM,pixelWidthCM,lineHeightCM);
170     };
171   }
172
173   public static class PDFGeneratingProducerNodeBuilder extends DefaultProducerNodeBuilders.AbstractProducerNodeBuilder {
174     private final static String   MARKER_KEY_ATTRIBUTE = DefaultProducerNodeBuilders.KEY_ATTRIBUTE;
175     private final static String   PDF_GENERATOR_ATTRIBUTE = "generator";
176     private final static String   PDF_DESTINATION_ATTRIBUTE = "destination";
177     private final static String   PDF_STYLESHEET_ATTRIBUTE = "stylesheet";
178     private final static String[] MARKER_REQUIRED_ATTRIBUTES = {PDF_GENERATOR_ATTRIBUTE,PDF_DESTINATION_ATTRIBUTE,PDF_STYLESHEET_ATTRIBUTE  };
179     private final static String[] MARKER_OPTIONAL_ATTRIBUTES = {};
180     private final static String[] MARKER_SUBNODES = {};
181
182     private String generator;
183     private String destination;
184     private String stylesheet;
185
186
187     public PDFGeneratingProducerNodeBuilder() {
188       super(MARKER_SUBNODES);
189     }
190
191     public void setAttributes(Map anAttributes) throws ProducerConfigExc {
192       ReaderTool.checkAttributes(anAttributes, MARKER_REQUIRED_ATTRIBUTES, MARKER_OPTIONAL_ATTRIBUTES);
193
194       generator = (String) anAttributes.get(PDF_GENERATOR_ATTRIBUTE);
195       destination = (String) anAttributes.get(PDF_DESTINATION_ATTRIBUTE);
196       stylesheet = (String) anAttributes.get(PDF_STYLESHEET_ATTRIBUTE);
197     };
198
199     public ProducerNode constructNode() {
200       return new PDFGeneratingProducerNode(generator,destination,stylesheet);
201     };
202   }
203 }
204
205