/**
  * Add a row for the class that uses the given package.
  *
  * @param usedClass the class that uses the given package
  * @param packageName the name of the package to which the class belongs
  * @param contentTree the content tree to which the row will be added
  */
 protected void addClassRow(ClassDoc usedClass, String packageName, Content contentTree) {
   DocPath dp = pathString(usedClass, DocPaths.CLASS_USE.resolve(DocPath.forName(usedClass)));
   Content td =
       HtmlTree.TD(
           HtmlStyle.colOne,
           getHyperLink(dp.fragment(packageName), new StringContent(usedClass.name())));
   addIndexComment(usedClass, td);
   contentTree.addContent(td);
 }
 /**
  * Returns a link to the stylesheet file.
  *
  * @return an HtmlTree for the lINK tag which provides the stylesheet location
  */
 public HtmlTree getStyleSheetProperties() {
   String filename = configuration.stylesheetfile;
   DocPath stylesheet;
   if (filename.length() > 0) {
     DocFile file = DocFile.createFileForInput(configuration, filename);
     stylesheet = DocPath.create(file.getName());
   } else {
     stylesheet = DocPaths.STYLESHEET;
   }
   DocPath p = relativePath.resolve(stylesheet);
   HtmlTree link = HtmlTree.LINK("stylesheet", "text/css", p.getPath(), "Style");
   return link;
 }
  /**
   * Constructor.
   *
   * @param filename the file to be generated.
   * @throws IOException
   * @throws DocletAbortException
   */
  public PackageUseWriter(
      ConfigurationImpl configuration, ClassUseMapper mapper, DocPath filename, PackageDoc pkgdoc)
      throws IOException {
    super(configuration, DocPath.forPackage(pkgdoc).resolve(filename));
    this.pkgdoc = pkgdoc;

    // by examining all classes in this package, find what packages
    // use these classes - produce a map between using package and
    // used classes.
    ClassDoc[] content = pkgdoc.allClasses();
    for (int i = 0; i < content.length; ++i) {
      ClassDoc usedClass = content[i];
      Set<ClassDoc> usingClasses = mapper.classToClass.get(usedClass.qualifiedName());
      if (usingClasses != null) {
        for (Iterator<ClassDoc> it = usingClasses.iterator(); it.hasNext(); ) {
          ClassDoc usingClass = it.next();
          PackageDoc usingPackage = usingClass.containingPackage();
          Set<ClassDoc> usedClasses = usingPackageToUsedClasses.get(usingPackage.name());
          if (usedClasses == null) {
            usedClasses = new TreeSet<ClassDoc>();
            usingPackageToUsedClasses.put(Util.getPackageName(usingPackage), usedClasses);
          }
          usedClasses.add(usedClass);
        }
      }
    }
  }
 /**
  * Convert the given Class to an HTML.
  *
  * @param cd the class to convert.
  * @param outputdir the name of the directory to output to.
  */
 public void convertClass(ClassDoc cd, DocPath outputdir) {
   if (cd == null) {
     return;
   }
   try {
     SourcePosition sp = cd.position();
     if (sp == null) return;
     Reader r;
     // temp hack until we can update SourcePosition API.
     if (sp instanceof SourcePositionImpl) {
       FileObject fo = ((SourcePositionImpl) sp).fileObject();
       if (fo == null) return;
       r = fo.openReader(true);
     } else {
       File file = sp.file();
       if (file == null) return;
       r = new FileReader(file);
     }
     int lineno = 1;
     String line;
     relativePath = DocPaths.SOURCE_OUTPUT.resolve(DocPath.forPackage(cd)).invert();
     Content body = getHeader();
     Content pre = new HtmlTree(HtmlTag.PRE);
     try (LineNumberReader reader = new LineNumberReader(r)) {
       while ((line = reader.readLine()) != null) {
         addLineNo(pre, lineno);
         addLine(pre, line, lineno);
         lineno++;
       }
     }
     addBlankLines(pre);
     Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre);
     body.addContent((configuration.allowTag(HtmlTag.MAIN)) ? HtmlTree.MAIN(div) : div);
     writeToFile(body, outputdir.resolve(DocPath.forClass(cd)));
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
 /**
  * Write the output to the file.
  *
  * @param body the documentation content to be written to the file.
  * @param path the path for the file.
  */
 private void writeToFile(Content body, DocPath path) throws IOException {
   Content htmlDocType = configuration.isOutputHtml5() ? DocType.HTML5 : DocType.TRANSITIONAL;
   Content head = new HtmlTree(HtmlTag.HEAD);
   head.addContent(
       HtmlTree.TITLE(new StringContent(configuration.getText("doclet.Window_Source_title"))));
   head.addContent(getStyleSheetProperties());
   Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(), head, body);
   Content htmlDocument = new HtmlDocument(htmlDocType, htmlTree);
   configuration.message.notice("doclet.Generating_0", path.getPath());
   DocFile df = DocFile.createFileForOutput(configuration, path);
   try (Writer w = df.openWriter()) {
     htmlDocument.write(w, true);
   }
 }