~ubuntu-branches/ubuntu/vivid/herold/vivid

« back to all changes in this revision

Viewing changes to java/org/dbdoclet/herold/Herold.java

  • Committer: Package Import Robot
  • Author(s): Mathieu Malaterre
  • Date: 2012-11-29 13:00:52 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20121129130052-x60zqbks3mwb8nmx
Tags: 6.0.3-1
* New upstream. Closes: #692544
* option --logging-level was removed. Closes: #691170
* preserve lang attribute. Closes: #692543
* Fix herold help output. Closes: #692545
* pdftohtml support (detect-trapped-br=false to revert). Closes: #692741
* Fix invalid XML element. Closes: #693214
* Remove d/p/antencoding.patch, applied upstream
* man page is provided. Closes: #689309
* Fix herold.home location. Closes: #692547
* Support section element. Closes: #692756

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
 
104
104
                        if (options.getFlag("license", false)) {
105
105
                                printLicense();
106
 
                                return;
 
106
                                exit(0);
107
107
                        }
108
108
 
109
109
                        options = createOptionList(args);
114
114
 
115
115
                        Herold converter = new Herold();
116
116
 
117
 
                        FileOption optProfile = (FileOption) options.getOption("profile");
 
117
                        StringOption optProfile = (StringOption) options
 
118
                                        .getOption("profile");
 
119
                        File profileFile = findProfile(optProfile);
118
120
                        Script script;
119
121
 
120
122
                        TrafoScriptManager mgr = new TrafoScriptManager();
121
 
                        if (optProfile.isUnset() == false) {
122
 
                                File profileFile = optProfile.getValue();
123
 
                                script = mgr.parseScript(profileFile);
124
 
                                logger.info(String.format("Using profile file %s.",
125
 
                                                profileFile.getAbsolutePath()));
126
 
                        } else {
127
 
                                script = new Script();
128
 
                                logger.warn("No profile file was found!");
129
 
                        }
 
123
                        script = mgr.parseScript(profileFile);
 
124
                        logger.info(String.format("Using profile file %s.",
 
125
                                        profileFile.getAbsolutePath()));
130
126
 
131
127
                        if (logger.isTraceEnabled()) {
132
128
                                StringWriter buffer = new StringWriter();
135
131
                        }
136
132
 
137
133
                        File outFile = converter.processCommandLineOptions(options, script);
 
134
                        logger.info(String.format("Output file is %s.", outFile.getPath()));
138
135
                        script.setOutputFile(outFile);
139
136
                        script.setInputFile(optIn.getValue());
140
137
 
181
178
                        exitCode = 5;
182
179
                }
183
180
 
 
181
                exit(exitCode);
 
182
        }
 
183
 
 
184
        private static File findProfile(StringOption optProfile)
 
185
                        throws FileNotFoundException {
 
186
 
 
187
                String profileName = "default.her";
 
188
 
 
189
                if (optProfile.isUnset() == false) {
 
190
                        profileName = optProfile.getValue();
 
191
                }
 
192
 
 
193
                if (profileName == null || profileName.trim().length() == 0) {
 
194
                        profileName = "default.her";
 
195
                }
 
196
 
 
197
                File profile = new File(profileName);
 
198
 
 
199
                if (profile.exists() == true) {
 
200
                        return profile;
 
201
                }
 
202
 
 
203
                String homePath = System.getProperty("herold.home");
 
204
 
 
205
                if (homePath != null) {
 
206
 
 
207
                        File homeDir = new File(homePath);
 
208
 
 
209
                        if (homeDir.exists() == false) {
 
210
                                throw new FileNotFoundException(String.format(
 
211
                                                "Home directory %s does not exist!", homePath));
 
212
                        }
 
213
 
 
214
                        File profilesDir = new File(homeDir, "profiles");
 
215
 
 
216
                        if (profilesDir.exists() == false) {
 
217
                                throw new FileNotFoundException(String.format(
 
218
                                                "Profiles directory %s does not exist!",
 
219
                                                profilesDir.getAbsolutePath()));
 
220
                        }
 
221
 
 
222
                        File file = new File(profilesDir, profileName);
 
223
 
 
224
                        if (file.exists() == true) {
 
225
                                return file;
 
226
                        }
 
227
 
 
228
                        file = new File(profilesDir, profileName + ".her");
 
229
 
 
230
                        if (file.exists() == true) {
 
231
                                return file;
 
232
                        }
 
233
                }
 
234
 
 
235
                throw new FileNotFoundException(String.format(
 
236
                                "Profile %s does not exist!", profileName));
 
237
        }
 
238
 
 
239
        private static void exit(int exitCode) {
 
240
 
 
241
                Herold.exitCode = exitCode;
 
242
 
184
243
                if (systemExitEnabled == true) {
185
244
                        System.exit(exitCode);
186
245
                }
195
254
 
196
255
                OptionList options = new OptionList(args);
197
256
 
198
 
                // add-index
 
257
                // docbook-add-index
199
258
                bopt = new BooleanOption(DbtConstants.SECTION_DOCBOOK.toLowerCase()
200
259
                                + "-" + DbtConstants.PARAM_DOCBOOK_ADD_INDEX, "x");
201
260
                bopt.setValue(false);
202
261
                options.add(bopt);
203
262
 
204
 
                // destination-encoding
 
263
                // docbook-encoding
205
264
                sopt = new StringOption(DbtConstants.SECTION_DOCBOOK.toLowerCase()
206
 
                                + "-" + DbtConstants.PARAM_DOCBOOK_DESTINATION_ENCODING, "d");
 
265
                                + "-" + DbtConstants.PARAM_DOCBOOK_ENCODING, "d");
207
266
                sopt.setDefault("UTF-8");
208
267
                options.add(sopt);
209
268
 
217
276
                selopt = new SelectOption(DbtConstants.SECTION_DOCBOOK.toLowerCase()
218
277
                                + "-" + DbtConstants.PARAM_DOCBOOK_DOCUMENT_ELEMENT, "r");
219
278
 
220
 
                String[] optv2 = { "article", "book", "reference" };
 
279
                String[] optv2 = { "article", "book", "reference", "section" };
221
280
                selopt.setList(optv2);
222
281
                selopt.setDefault("article");
223
282
                options.add(selopt);
251
310
                optOut = new FileOption("out", "o");
252
311
                options.add(optOut);
253
312
 
254
 
                FileOption optProfile = new FileOption("profile", "p");
255
 
                optProfile.isExisting(true);
 
313
                StringOption optProfile = new StringOption("profile", "p");
256
314
                options.add(optProfile);
257
315
 
258
316
                // verbose
273
331
                URL url = ResourceServices
274
332
                                .getResourceAsUrl("/org/dbdoclet/herold/COPYING");
275
333
 
276
 
                BufferedReader reader = new BufferedReader(new InputStreamReader(
277
 
                                url.openStream()));
278
 
                String line = reader.readLine();
279
 
 
280
 
                while (line != null) {
281
 
                        println(line);
282
 
                        line = reader.readLine();
 
334
                if (url != null) {
 
335
                        BufferedReader reader = new BufferedReader(new InputStreamReader(
 
336
                                        url.openStream()));
 
337
                        String line = reader.readLine();
 
338
 
 
339
                        while (line != null) {
 
340
                                println(line);
 
341
                                line = reader.readLine();
 
342
                        }
 
343
 
 
344
                        reader.close();
 
345
                } else {
 
346
                        logger.fatal("Can't find resource for license!");
283
347
                }
284
 
 
285
 
                reader.close();
286
348
        }
287
349
 
288
350
        private static void println(String str) {
340
402
                                script.selectSection(DbtConstants.SECTION_DOCBOOK);
341
403
                                name = StringServices.cutPrefix(name,
342
404
                                                DbtConstants.SECTION_DOCBOOK.toLowerCase());
 
405
 
343
406
                        } else if (name.startsWith(DbtConstants.SECTION_HTML.toLowerCase())) {
344
407
                                script.selectSection(DbtConstants.SECTION_HTML);
345
408
                                name = StringServices.cutPrefix(name,
352
415
                                switch (option.getType()) {
353
416
 
354
417
                                case BOOLEAN:
355
 
                                        script.addBoolParam(name, (Boolean) option.getValue());
 
418
                                        script.setBoolParam(name, (Boolean) option.getValue());
356
419
                                        break;
357
420
 
358
421
                                default:
359
 
                                        script.addTextParam(name, option.getValue().toString());
 
422
                                        script.setTextParam(name, option.getValue().toString());
360
423
                                        break;
361
424
                                }
362
425
                        }