/**
   * add FlagImangesSet to Properties, which needn't to change the dir level, just ouput to the
   * ouput dir.
   *
   * @param prop job configuration
   * @param key list name
   * @param set relative flag image files
   */
  private void addFlagImagesSetToProperties(
      final Job prop, final String key, final Set<String> set) {
    String value = null;
    final Set<String> newSet = new LinkedHashSet<String>(INT_128);
    for (final String file : set) {
      if (new File(file).isAbsolute()) {
        // no need to append relative path before absolute paths
        newSet.add(FileUtils.normalize(file));
      } else {
        // In ant, all the file separator should be slash, so we need to
        // replace all the back slash with slash.
        newSet.add(
            FileUtils.separatorsToUnix(
                FileUtils.normalize(new StringBuffer().append(file).toString())));
      }
    }

    // write list attribute to file
    final String fileKey = key.substring(0, key.lastIndexOf("list")) + "file";
    prop.setProperty(fileKey, key.substring(0, key.lastIndexOf("list")) + ".list");
    final File list = new File(tempDir, prop.getProperty(fileKey));
    Writer bufferedWriter = null;
    try {
      bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(list)));
      final Iterator<String> it = newSet.iterator();
      while (it.hasNext()) {
        bufferedWriter.write(it.next());
        if (it.hasNext()) {
          bufferedWriter.write("\n");
        }
      }
      bufferedWriter.flush();
      bufferedWriter.close();
    } catch (final FileNotFoundException e) {
      logger.logException(e);
    } catch (final IOException e) {
      logger.logException(e);
    } finally {
      if (bufferedWriter != null) {
        try {
          bufferedWriter.close();
        } catch (final IOException e) {
          logger.logException(e);
        }
      }
    }

    value = StringUtils.assembleString(newSet, COMMA);

    prop.setProperty(key, value);

    // clear set
    set.clear();
    newSet.clear();
  }
  /**
   * Categorize file.
   *
   * <p>If {@code file} parameter contains a pipe character, the pipe character is followed by the
   * format of the file.
   *
   * <p>TODO: Pass format as separate DITA class parameter.
   *
   * @param file file path with optional format
   */
  private void categorizeResultFile(String file) {
    // edited by william on 2009-08-06 for bug:2832696 start
    String lcasefn = null;
    String format = null;
    // has format attribute set
    if (file.contains(STICK)) {
      // get lower case file name
      lcasefn = file.substring(0, file.indexOf(STICK)).toLowerCase();
      // get format attribute
      format = file.substring(file.indexOf(STICK) + 1);
      file = file.substring(0, file.indexOf(STICK));
    } else {
      lcasefn = file.toLowerCase();
    }

    // Added by William on 2010-03-04 for bug:2957938 start
    // avoid files referred by coderef being added into wait list
    if (subsidiarySet.contains(lcasefn)) {
      return;
    }
    // Added by William on 2010-03-04 for bug:2957938 end

    if (FileUtils.isDITAFile(lcasefn)
        && (format == null
            || ATTR_FORMAT_VALUE_DITA.equalsIgnoreCase(format)
            || ATTR_FORMAT_VALUE_DITAMAP.equalsIgnoreCase(format))) {

      addToWaitList(file);
    } else if (!FileUtils.isSupportedImageFile(lcasefn)) {
      // FIXME: Treating all non-image extensions as HTML/resource files is not correct if
      // HTML/resource files
      //        are defined by the file extension. Correct behaviour would be to remove this else
      // block.
      htmlSet.add(file);
    }
    // edited by william on 2009-08-06 for bug:2832696 end
    if (FileUtils.isSupportedImageFile(lcasefn)) {
      imageSet.add(file);
      try {
        final File image = new File(baseInputDir + File.separator + file).getCanonicalFile();
        if (!image.exists()) {
          final Properties prop = new Properties();
          prop.put("%1", image.getAbsolutePath());
          logger.logWarn(MessageUtils.getMessage("DOTX008W", prop).toString());
        }
      } catch (final IOException e) {
        logger.logError(e.getMessage());
      }
    }

    if (FileUtils.isHTMLFile(lcasefn) || FileUtils.isResourceFile(lcasefn)) {
      htmlSet.add(file);
    }
  }
Beispiel #3
0
  /**
   * Write map into xml file.
   *
   * @param m map
   * @param outputFile output xml file
   */
  public void writeMapToXML(final Map<String, Set<String>> m, final File outputFile) {
    if (m == null) {
      return;
    }
    final Properties prop = new Properties();
    for (Map.Entry<String, Set<String>> entry : m.entrySet()) {
      final String key = entry.getKey();
      final String value = StringUtils.join(entry.getValue(), COMMA);
      prop.setProperty(key, value);
    }
    // File outputFile = new File(tempDir, filename);

    final DocumentBuilder db = XMLUtils.getDocumentBuilder();
    final Document doc = db.newDocument();
    final Element properties = (Element) doc.appendChild(doc.createElement("properties"));

    final Set<Object> keys = prop.keySet();
    for (Object key1 : keys) {
      final String key = (String) key1;
      final Element entry = (Element) properties.appendChild(doc.createElement("entry"));
      entry.setAttribute("key", key);
      entry.appendChild(doc.createTextNode(prop.getProperty(key)));
    }
    final TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = null;
    try {
      t = tf.newTransformer();
      t.setOutputProperty(OutputKeys.INDENT, "yes");
      t.setOutputProperty(OutputKeys.METHOD, "xml");
      t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    } catch (final TransformerConfigurationException tce) {
      throw new RuntimeException(tce);
    }
    final DOMSource doms = new DOMSource(doc);
    OutputStream out = null;
    try {
      out = new FileOutputStream(outputFile);
      final StreamResult sr = new StreamResult(out);
      t.transform(doms, sr);
    } catch (final Exception e) {
      logger.error("Failed to process map: " + e.getMessage(), e);
    } finally {
      if (out != null) {
        try {
          out.close();
        } catch (final IOException e) {
          logger.error("Failed to close output stream: " + e.getMessage());
        }
      }
    }
  }
  public AbstractPipelineOutput execute(final AbstractPipelineInput input) throws DITAOTException {
    if (logger == null) {
      throw new IllegalStateException("Logger not set");
    }
    final Date startTime = TimingUtils.getNowTime();

    try {
      logger.logInfo(moduleStartMsg);
      parseInputParameters(input);

      // set grammar pool flag
      GrammarPoolManager.setGramCache(gramcache);

      reader = new GenListModuleReader();
      reader.setLogger(logger);
      reader.initXMLReader(ditaDir, xmlValidate, rootFile, setSystemid);
      final FilterUtils filterUtils = parseFilterFile();
      reader.setFilterUtils(filterUtils);
      reader.setOutputUtils(outputUtils);

      addToWaitList(inputFile);
      processWaitList();
      // Depreciated function
      // The base directory does not change according to the referenceing
      // topic files in the new resolution
      updateBaseDirectory();
      refactoringResult();
      outputResult();
      schemekeydef.writeEndDocument();
      schemekeydef.close();
      // Added by William on 2009-06-25 for req #12014 start
      // write the end tag
      export.write("</stub>");
      // close the steam
      export.close();
      // Added by William on 2009-06-25 for req #12014 end
    } catch (final DITAOTException e) {
      throw e;
    } catch (final SAXException e) {
      throw new DITAOTException(e.getMessage(), e);
    } catch (final Exception e) {
      throw new DITAOTException(e.getMessage(), e);
    } finally {

      logger.logInfo(moduleEndMsg + TimingUtils.reportElapsedTime(startTime));
    }

    return null;
  }
 /**
  * Write map of sets to a file.
  *
  * <p>The serialization format is XML properties format where values are comma separated lists.
  *
  * @param m map to serialize
  * @param filename output filename
  */
 private void writeMapToXML(final Map<String, Set<String>> m, final String filename) {
   if (m == null) {
     return;
   }
   final Properties prop = new Properties();
   for (final Map.Entry<String, Set<String>> entry : m.entrySet()) {
     final String key = entry.getKey();
     final String value = StringUtils.assembleString(entry.getValue(), COMMA);
     prop.setProperty(key, value);
   }
   final File outputFile = new File(tempDir, filename);
   OutputStream os = null;
   try {
     os = new FileOutputStream(outputFile);
     prop.storeToXML(os, null);
     os.close();
   } catch (final IOException e) {
     this.logger.logException(e);
   } finally {
     if (os != null) {
       try {
         os.close();
       } catch (final Exception e) {
         logger.logException(e);
       }
     }
   }
 }
 /**
  * Add key definition to job configuration
  *
  * @param prop job configuration
  * @param key list name
  * @param set key defintions to add
  */
 private void addKeyDefSetToProperties(
     final Job prop, final String key, final Collection<KeyDef> set) {
   // update value
   final Collection<KeyDef> updated = new ArrayList<KeyDef>(set.size());
   for (final KeyDef file : set) {
     String keys = FileUtils.separatorsToUnix(FileUtils.normalize(prefix + file.keys));
     String href = file.href;
     String source = file.source;
     if (prefix.length() != 0) {
       // cases where keymap is in map ancestor folder
       keys = keys.substring(prefix.length());
       if (href == null) {
         // href = FileUtils.separatorsToUnix(FileUtils.normalize(prefix));
         source = FileUtils.separatorsToUnix(FileUtils.normalize(prefix + source));
       } else {
         if (!exKeyDefMap.containsKey(file.keys)) {
           href = FileUtils.separatorsToUnix(FileUtils.normalize(prefix + href));
         }
         source = FileUtils.separatorsToUnix(FileUtils.normalize(prefix + source));
       }
     }
     final KeyDef keyDef = new KeyDef(keys, href, source);
     updated.add(keyDef);
   }
   // write key definition
   try {
     writeKeydef(new File(tempDir, "keydef.xml"), updated);
   } catch (final DITAOTException e) {
     logger.logError("Failed to write key definition file: " + e.getMessage(), e);
   }
   // write list file
   final Set<String> newSet = new LinkedHashSet<String>(set.size());
   for (final KeyDef keydef : updated) {
     newSet.add(keydef.toString());
   }
   prop.setSet(key, newSet);
   final String fileKey = key.substring(0, key.lastIndexOf("list")) + "file";
   prop.setProperty(fileKey, key.substring(0, key.lastIndexOf("list")) + ".list");
   try {
     prop.writeList(key);
   } catch (final IOException e) {
     logger.logError("Failed to write key list file: " + e.getMessage(), e);
   }
 }
Beispiel #7
0
 /**
  * Get the first topic id.
  *
  * @param path file path
  * @param dir file dir
  * @param useCatalog whether use catalog file for validation
  * @return topic id
  */
 public static String getFirstTopicId(final URI path, final File dir, final boolean useCatalog) {
   if (path == null && dir == null) {
     return null;
   }
   final DITAOTLogger logger = new DITAOTJavaLogger();
   final StringBuilder firstTopicId = new StringBuilder();
   final TopicIdParser parser = new TopicIdParser(firstTopicId);
   try {
     final XMLReader reader = XMLUtils.getXMLReader();
     reader.setContentHandler(parser);
     if (useCatalog) {
       reader.setEntityResolver(CatalogUtils.getCatalogResolver());
     }
     reader.parse(dir.toURI().resolve(path).toString());
   } catch (final Exception e) {
     logger.error(e.getMessage(), e);
   }
   return firstTopicId.toString();
 }
Beispiel #8
0
  /**
   * Find whether an id is refer to a topic in a dita file.
   *
   * @param absolutePathToFile the absolute path of dita file
   * @param id topic id
   * @return true if id find and false otherwise
   */
  public boolean findTopicId(final File absolutePathToFile, final String id) {

    if (!absolutePathToFile.exists()) {
      return false;
    }
    try {
      // load the file
      final DocumentBuilder builder = XMLUtils.getDocumentBuilder();
      builder.setEntityResolver(CatalogUtils.getCatalogResolver());
      final Document root = builder.parse(new InputSource(new FileInputStream(absolutePathToFile)));

      // get root element
      final Element doc = root.getDocumentElement();
      // do BFS
      final Queue<Element> queue = new LinkedList<>();
      queue.offer(doc);
      while (!queue.isEmpty()) {
        final Element pe = queue.poll();
        final NodeList pchildrenList = pe.getChildNodes();
        for (int i = 0; i < pchildrenList.getLength(); i++) {
          final Node node = pchildrenList.item(i);
          if (node.getNodeType() == Node.ELEMENT_NODE) {
            queue.offer((Element) node);
          }
        }
        final String classValue = pe.getAttribute(ATTRIBUTE_NAME_CLASS);
        if (classValue != null && TOPIC_TOPIC.matches(classValue)) {
          // topic id found
          if (pe.getAttribute(ATTRIBUTE_NAME_ID).equals(id)) {
            return true;
          }
        }
      }
      return false;

    } catch (final Exception e) {
      logger.error("Failed to read document: " + e.getMessage(), e);
    }
    return false;
  }
  /**
   * Add set of values of job configuration
   *
   * @param prop job configuration
   * @param key list name
   * @param set values to add
   */
  private void addSetToProperties(final Job prop, final String key, final Set<String> set) {
    // update value
    final Set<String> newSet = new LinkedHashSet<String>(INT_128);
    for (final String file : set) {
      if (new File(file).isAbsolute()) {
        // no need to append relative path before absolute paths
        newSet.add(FileUtils.normalize(file));
      } else {
        // In ant, all the file separator should be slash, so we need to
        // replace all the back slash with slash.
        final int index = file.indexOf(EQUAL);
        if (index != -1) {
          // keyname
          final String to = file.substring(0, index);
          final String source = file.substring(index + 1);

          newSet.add(
              FileUtils.separatorsToUnix(
                      FileUtils.normalize(new StringBuffer(prefix).append(to).toString()))
                  + EQUAL
                  + FileUtils.separatorsToUnix(
                      FileUtils.normalize(new StringBuffer(prefix).append(source).toString())));
        } else {
          newSet.add(
              FileUtils.separatorsToUnix(
                  FileUtils.normalize(new StringBuffer(prefix).append(file).toString())));
        }
      }
    }
    prop.setSet(key, newSet);
    // write list file
    final String fileKey = key.substring(0, key.lastIndexOf("list")) + "file";
    prop.setProperty(fileKey, key.substring(0, key.lastIndexOf("list")) + ".list");
    try {
      prop.writeList(key);
    } catch (final IOException e) {
      logger.logError("Failed to write list file: " + e.getMessage(), e);
    }
  }
  /**
   * Write result files.
   *
   * @throws DITAOTException if writing result files failed
   */
  private void outputResult() throws DITAOTException {
    final File dir = new File(tempDir);
    if (!dir.exists()) {
      dir.mkdirs();
    }

    Job prop = null;
    try {
      prop = new Job(dir);
    } catch (final IOException e) {
      throw new DITAOTException("Failed to create empty job: " + e.getMessage(), e);
    }

    prop.setProperty(INPUT_DIR, baseInputDir);
    prop.setProperty(INPUT_DITAMAP, prefix + inputFile);

    prop.setProperty(INPUT_DITAMAP_LIST_FILE_LIST, USER_INPUT_FILE_LIST_FILE);
    final File inputfile = new File(tempDir, USER_INPUT_FILE_LIST_FILE);
    Writer bufferedWriter = null;
    try {
      bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(inputfile)));
      bufferedWriter.write(prefix + inputFile);
      bufferedWriter.flush();
    } catch (final FileNotFoundException e) {
      logger.logException(e);
    } catch (final IOException e) {
      logger.logException(e);
    } finally {
      if (bufferedWriter != null) {
        try {
          bufferedWriter.close();
        } catch (final IOException e) {
          logger.logException(e);
        }
      }
    }

    // add out.dita.files,tempdirToinputmapdir.relative.value to solve the
    // output problem
    relativeValue = prefix;
    formatRelativeValue = formatRelativeValue(relativeValue);
    prop.setProperty("tempdirToinputmapdir.relative.value", formatRelativeValue);

    prop.setProperty("uplevels", getUpdateLevels());
    addSetToProperties(prop, OUT_DITA_FILES_LIST, outDitaFilesSet);

    addSetToProperties(prop, FULL_DITAMAP_TOPIC_LIST, ditaSet);
    addSetToProperties(prop, FULL_DITA_TOPIC_LIST, fullTopicSet);
    addSetToProperties(prop, FULL_DITAMAP_LIST, fullMapSet);
    addSetToProperties(prop, HREF_DITA_TOPIC_LIST, hrefTopicSet);
    addSetToProperties(prop, CONREF_LIST, conrefSet);
    addSetToProperties(prop, IMAGE_LIST, imageSet);
    addSetToProperties(prop, FLAG_IMAGE_LIST, flagImageSet);
    addSetToProperties(prop, HTML_LIST, htmlSet);
    addSetToProperties(prop, HREF_TARGET_LIST, hrefTargetSet);
    addSetToProperties(prop, HREF_TOPIC_LIST, hrefWithIDSet);
    addSetToProperties(prop, CHUNK_TOPIC_LIST, chunkTopicSet);
    addSetToProperties(prop, SUBJEC_SCHEME_LIST, schemeSet);
    addSetToProperties(prop, CONREF_TARGET_LIST, conrefTargetSet);
    addSetToProperties(prop, COPYTO_SOURCE_LIST, copytoSourceSet);
    addSetToProperties(prop, SUBSIDIARY_TARGET_LIST, subsidiarySet);
    addSetToProperties(prop, CONREF_PUSH_LIST, conrefpushSet);
    addSetToProperties(prop, KEYREF_LIST, keyrefSet);
    addSetToProperties(prop, CODEREF_LIST, coderefSet);

    // @processing-role
    addSetToProperties(prop, RESOURCE_ONLY_LIST, resourceOnlySet);

    addFlagImagesSetToProperties(prop, REL_FLAGIMAGE_LIST, relFlagImagesSet);

    // Convert copyto map into set and output
    final Set<String> copytoSet = new HashSet<String>(INT_128);
    for (final Map.Entry<String, String> entry : copytoMap.entrySet()) {
      copytoSet.add(entry.toString());
    }
    addSetToProperties(prop, COPYTO_TARGET_TO_SOURCE_MAP_LIST, copytoSet);
    addKeyDefSetToProperties(prop, KEY_LIST, keysDefMap.values());

    try {
      logger.logInfo("Serializing job specification");
      prop.write();
    } catch (final IOException e) {
      throw new DITAOTException(
          "Failed to serialize job configuration files: " + e.getMessage(), e);
    }

    // Output relation-graph
    writeMapToXML(reader.getRelationshipGrap(), FILE_NAME_SUBJECT_RELATION);
    // Output topic-scheme dictionary
    writeMapToXML(this.schemeDictionary, FILE_NAME_SUBJECT_DICTIONARY);

    // added by Willam on 2009-07-17 for req #12014 start
    if (INDEX_TYPE_ECLIPSEHELP.equals(transtype)) {
      // Output plugin id
      final File pluginIdFile = new File(tempDir, FILE_NAME_PLUGIN_XML);
      final DelayConrefUtils delayConrefUtils = new DelayConrefUtils();
      delayConrefUtils.writeMapToXML(reader.getPluginMap(), pluginIdFile);
      // write the result into the file
      final StringBuffer result = reader.getResult();
      try {
        export.write(result.toString());
      } catch (final IOException e) {
        logger.logException(e);
      }
    }
    // added by Willam on 2009-07-17 for req #12014 end

  }
  private void processParseResult(String currentFile) {
    final Map<String, String> cpMap = reader.getCopytoMap();
    final Map<String, KeyDef> kdMap = reader.getKeysDMap();
    // Added by William on 2010-06-09 for bug:3013079 start
    // the reader's reset method will clear the map.
    final Map<String, String> exKdMap = reader.getExKeysDefMap();
    exKeyDefMap.putAll(exKdMap);
    // Added by William on 2010-06-09 for bug:3013079 end

    // Category non-copyto result and update uplevels accordingly
    for (final String file : reader.getNonCopytoResult()) {
      categorizeResultFile(file);
      updateUplevels(file);
    }

    // Update uplevels for copy-to targets, and store copy-to map.
    // Note: same key(target) copy-to will be ignored.
    for (final String key : cpMap.keySet()) {
      final String value = cpMap.get(key);

      if (copytoMap.containsKey(key)) {
        // edited by Alan on Date:2009-11-02 for Work Item:#1590 start
        /*
         * StringBuffer buff = new StringBuffer();
         * buff.append("Copy-to task [href=\""); buff.append(value);
         * buff.append("\" copy-to=\""); buff.append(key);
         * buff.append("\"] which points to another copy-to target");
         * buff.append(" was ignored.");
         * logger.logWarn(buff.toString());
         */
        final Properties prop = new Properties();
        prop.setProperty("%1", value);
        prop.setProperty("%2", key);
        logger.logWarn(MessageUtils.getMessage("DOTX065W", prop).toString());
        // edited by Alan on Date:2009-11-02 for Work Item:#1590 end
        ignoredCopytoSourceSet.add(value);
      } else {
        updateUplevels(key);
        copytoMap.put(key, value);
      }
    }
    // TODO Added by William on 2009-06-09 for scheme key bug(497)
    schemeSet.addAll(reader.getSchemeRefSet());

    // collect key definitions
    for (final String key : kdMap.keySet()) {
      // key and value.keys will differ when keydef is a redirect to another keydef
      final KeyDef value = kdMap.get(key);
      if (keysDefMap.containsKey(key)) {
        // if there already exists duplicated key definition in
        // different map files.
        // Should only emit this if in a debug mode; comment out for now
        /*
         * Properties prop = new Properties(); prop.put("%1", key);
         * prop.put("%2", value); prop.put("%3", currentFile); logger
         * .logInfo(MessageUtils.getMessage("DOTJ048I",
         * prop).toString());
         */
      } else {
        updateUplevels(key);
        // add the ditamap where it is defined.
        /*
         * try { keydef.write("<keydef ");
         * keydef.write("keys=\""+key+"\" ");
         * keydef.write("href=\""+value+"\" ");
         * keydef.write("source=\""+currentFile+"\"/>");
         * keydef.write("\n"); keydef.flush(); } catch (IOException e) {
         *
         * logger.logException(e); }
         */
        keysDefMap.put(key, new KeyDef(key, value.href, currentFile));
      }
      // TODO Added by William on 2009-06-09 for scheme key bug(532-547)
      // if the current file is also a schema file
      if (schemeSet.contains(currentFile)) {
        // write the keydef into the scheme keydef file
        try {
          schemekeydef.writeStartElement(ELEMENT_KEYDEF);
          schemekeydef.writeAttribute(ATTRIBUTE_KEYS, key);
          if (value.href != null) {
            schemekeydef.writeAttribute(ATTRIBUTE_HREF, value.href);
          }
          schemekeydef.writeAttribute(ATTRIUBTE_SOURCE, currentFile);
          schemekeydef.writeEndElement();
        } catch (final SAXException e) {
          logger.logException(e);
        }
      }
    }

    hrefTargetSet.addAll(reader.getHrefTargets());
    hrefWithIDSet.addAll(reader.getHrefTopicSet());
    chunkTopicSet.addAll(reader.getChunkTopicSet());
    // schemeSet.addAll(reader.getSchemeRefSet());
    conrefTargetSet.addAll(reader.getConrefTargets());
    nonConrefCopytoTargetSet.addAll(reader.getNonConrefCopytoTargets());
    ignoredCopytoSourceSet.addAll(reader.getIgnoredCopytoSourceSet());
    subsidiarySet.addAll(reader.getSubsidiaryTargets());
    outDitaFilesSet.addAll(reader.getOutFilesSet());
    resourceOnlySet.addAll(reader.getResourceOnlySet());

    // Generate topic-scheme dictionary
    if (reader.getSchemeSet() != null && reader.getSchemeSet().size() > 0) {
      Set<String> children = null;
      children = this.schemeDictionary.get(currentFile);
      if (children == null) {
        children = new HashSet<String>();
      }
      children.addAll(reader.getSchemeSet());
      // for Linux support
      currentFile = FileUtils.separatorsToUnix(currentFile);

      this.schemeDictionary.put(currentFile, children);
      final Set<String> hrfSet = reader.getHrefTargets();
      for (final String f : hrfSet) {
        // for Linux support
        final String filename = FileUtils.separatorsToUnix(f);

        children = this.schemeDictionary.get(filename);
        if (children == null) {
          children = new HashSet<String>();
        }
        children.addAll(reader.getSchemeSet());
        this.schemeDictionary.put(filename, children);
      }
    }
  }
  private void processFile(String currentFile) throws DITAOTException {
    File fileToParse;
    final File file = new File(currentFile);
    if (file.isAbsolute()) {
      fileToParse = file;
      currentFile = FileUtils.getRelativePath(rootFile, currentFile);
    } else {
      fileToParse = new File(baseInputDir, currentFile);
    }
    try {
      fileToParse = fileToParse.getCanonicalFile();
    } catch (final IOException e1) {
      logger.logError(e1.toString());
    }
    logger.logInfo("Processing " + fileToParse.getAbsolutePath());
    String msg = null;
    final Properties params = new Properties();
    params.put("%1", currentFile);

    if (!fileToParse.exists()) {
      logger.logError(MessageUtils.getMessage("DOTX008E", params).toString());
      return;
    }
    try {
      if (FileUtils.isValidTarget(currentFile.toLowerCase())) {
        reader.setTranstype(transtype);
        reader.setCurrentDir(new File(currentFile).getParent());
        reader.parse(fileToParse);

      } else {
        // edited by Alan on Date:2009-11-02 for Work Item:#1590 start
        // logger.logWarn("Input file name is not valid DITA file name.");
        final Properties prop = new Properties();
        prop.put("%1", fileToParse);
        logger.logWarn(MessageUtils.getMessage("DOTJ053W", params).toString());
        // edited by Alan on Date:2009-11-02 for Work Item:#1590 end
      }

      // don't put it into dita.list if it is invalid
      if (reader.isValidInput()) {
        processParseResult(currentFile);
        categorizeCurrentFile(currentFile);
      } else if (!currentFile.equals(inputFile)) {
        logger.logWarn(MessageUtils.getMessage("DOTJ021W", params).toString());
      }
    } catch (final SAXParseException sax) {

      // To check whether the inner third level is DITAOTBuildException
      // :FATALERROR
      final Exception inner = sax.getException();
      if (inner != null && inner instanceof DITAOTException) { // second
        // level
        logger.logInfo(inner.getMessage());
        throw (DITAOTException) inner;
      }
      if (currentFile.equals(inputFile)) {
        // stop the build if exception thrown when parsing input file.
        final MessageBean msgBean = MessageUtils.getMessage("DOTJ012F", params);
        msg = MessageUtils.getMessage("DOTJ012F", params).toString();
        msg = new StringBuffer(msg).append(":").append(sax.getMessage()).toString();
        throw new DITAOTException(msgBean, sax, msg);
      }
      final StringBuffer buff = new StringBuffer();
      msg = MessageUtils.getMessage("DOTJ013E", params).toString();
      buff.append(msg).append(LINE_SEPARATOR).append(sax.getMessage());
      logger.logError(buff.toString());
    } catch (final Exception e) {

      if (currentFile.equals(inputFile)) {
        // stop the build if exception thrown when parsing input file.
        final MessageBean msgBean = MessageUtils.getMessage("DOTJ012F", params);
        msg = MessageUtils.getMessage("DOTJ012F", params).toString();
        msg = new StringBuffer(msg).append(":").append(e.getMessage()).toString();
        throw new DITAOTException(msgBean, e, msg);
      }
      final StringBuffer buff = new StringBuffer();
      msg = MessageUtils.getMessage("DOTJ013E", params).toString();
      buff.append(msg).append(LINE_SEPARATOR).append(e.getMessage());
      logger.logError(buff.toString());
    }

    if (!reader.isValidInput() && currentFile.equals(inputFile)) {

      if (xmlValidate == true) {
        // stop the build if all content in the input file was filtered
        // out.
        msg = MessageUtils.getMessage("DOTJ022F", params).toString();
        throw new DITAOTException(msg);
      } else {
        // stop the build if the content of the file is not valid.
        msg = MessageUtils.getMessage("DOTJ034F", params).toString();
        throw new DITAOTException(msg);
      }
    }

    doneList.add(currentFile);
    reader.reset();
  }
  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());
  }