/** * Write key definition XML configuration file * * @param keydefFile key definition file * @param keydefs list of key definitions * @throws DITAOTException if writing configuration file failed */ public static void writeKeydef(final File keydefFile, final Collection<KeyDef> keydefs) throws DITAOTException { XMLSerializer keydef = null; try { keydef = XMLSerializer.newInstance(new FileOutputStream(keydefFile)); keydef.writeStartDocument(); keydef.writeStartElement(ELEMENT_STUB); for (final KeyDef k : keydefs) { keydef.writeStartElement(ELEMENT_KEYDEF); keydef.writeAttribute(ATTRIBUTE_KEYS, k.keys); if (k.href != null) { keydef.writeAttribute(ATTRIBUTE_HREF, k.href); } if (k.source != null) { keydef.writeAttribute(ATTRIUBTE_SOURCE, k.source); } keydef.writeEndElement(); } keydef.writeEndDocument(); } catch (final Exception e) { throw new DITAOTException( "Failed to write key definition file " + keydefFile + ": " + e.getMessage(), e); } finally { if (keydef != null) { try { keydef.close(); } catch (final IOException e) { } } } }
private void parseInputParameters(final AbstractPipelineInput input) { final String basedir = input.getAttribute(ANT_INVOKER_PARAM_BASEDIR); final String ditaInput = input.getAttribute(ANT_INVOKER_PARAM_INPUTMAP); tempDir = input.getAttribute(ANT_INVOKER_PARAM_TEMPDIR); ditaDir = input.getAttribute(ANT_INVOKER_EXT_PARAM_DITADIR); ditavalFile = input.getAttribute(ANT_INVOKER_PARAM_DITAVAL); xmlValidate = Boolean.valueOf(input.getAttribute(ANT_INVOKER_EXT_PARAM_VALIDATE)); // Added by William on 2009-07-18 for req #12014 start // get transtype transtype = input.getAttribute(ANT_INVOKER_EXT_PARAM_TRANSTYPE); // Added by William on 2009-07-18 for req #12014 start gramcache = "yes".equalsIgnoreCase(input.getAttribute(ANT_INVOKER_EXT_PARAM_GRAMCACHE)); setSystemid = "yes".equalsIgnoreCase(input.getAttribute(ANT_INVOKER_EXT_PARAN_SETSYSTEMID)); // For the output control outputUtils = new OutputUtils(); outputUtils.setGeneratecopyouter(input.getAttribute(ANT_INVOKER_EXT_PARAM_GENERATECOPYOUTTER)); outputUtils.setOutterControl(input.getAttribute(ANT_INVOKER_EXT_PARAM_OUTTERCONTROL)); outputUtils.setOnlyTopicInMap(input.getAttribute(ANT_INVOKER_EXT_PARAM_ONLYTOPICINMAP)); // Set the OutputDir final File path = new File(input.getAttribute(ANT_INVOKER_EXT_PARAM_OUTPUTDIR)); if (path.isAbsolute()) { outputUtils.setOutputDir(path.getAbsolutePath()); } else { throw new IllegalArgumentException("Output directory " + tempDir + " must be absolute"); } // Resolve relative paths base on the basedir. File inFile = new File(ditaInput); if (!inFile.isAbsolute()) { // XXX Shouldn't this be resolved to current directory, not Ant script base directory? inFile = new File(basedir, ditaInput); } try { inFile = inFile.getCanonicalFile(); } catch (final IOException e1) { logger.logException(e1); } if (!new File(tempDir).isAbsolute()) { throw new IllegalArgumentException("Temporary directory " + tempDir + " must be absolute"); } else { tempDir = FileUtils.normalize(tempDir); } if (!new File(ditaDir).isAbsolute()) { throw new IllegalArgumentException( "DITA-OT installation directory " + tempDir + " must be absolute"); } else { ditaDir = FileUtils.normalize(ditaDir); } if (ditavalFile != null && !new File(ditavalFile).isAbsolute()) { // XXX Shouldn't this be resolved to current directory, not Ant script base directory? ditavalFile = new File(basedir, ditavalFile).getAbsolutePath(); } baseInputDir = new File(inFile.getAbsolutePath()).getParent(); baseInputDir = FileUtils.normalize(baseInputDir); rootFile = inFile.getAbsolutePath(); rootFile = FileUtils.normalize(rootFile); inputFile = inFile.getName(); try { // Added by William on 2009-06-09 for scheme key bug // create the keydef file for scheme files schemekeydef = XMLSerializer.newInstance(new FileOutputStream(new File(tempDir, "schemekeydef.xml"))); schemekeydef.writeStartDocument(); schemekeydef.writeStartElement(ELEMENT_STUB); // Added by William on 2009-06-25 for req #12014 start // create the export file for exportanchors // write the head export = new OutputStreamWriter(new FileOutputStream(new File(tempDir, FILE_NAME_EXPORT_XML))); export.write(XML_HEAD); export.write("<stub>"); // Added by William on 2009-06-25 for req #12014 end } catch (final FileNotFoundException e) { logger.logException(e); } catch (final IOException e) { logger.logException(e); } catch (final SAXException e) { logger.logException(e); } // Set the mapDir outputUtils.setInputMapPathName(inFile.getAbsolutePath()); }