< prev index next >

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DocFilesHandlerImpl.java

Print this page




  47 import jdk.javadoc.internal.doclets.toolkit.util.Utils;
  48 
  49 import javax.lang.model.element.Element;
  50 import javax.lang.model.element.ModuleElement;
  51 import javax.lang.model.element.PackageElement;
  52 import javax.tools.FileObject;
  53 import javax.tools.JavaFileManager.Location;
  54 
  55 import java.util.ArrayList;
  56 import java.util.Collections;
  57 import java.util.List;
  58 
  59 import jdk.javadoc.internal.doclets.formats.html.markup.Navigation.PageMode;
  60 
  61 public class DocFilesHandlerImpl implements DocFilesHandler {
  62 
  63     public final Element element;
  64     public final Location location;
  65     public final DocPath  source;
  66     public final HtmlConfiguration configuration;

  67     private Navigation navBar;
  68 
  69     /**
  70      * Constructor to construct the DocFilesWriter object.
  71      *
  72      * @param configuration the configuration of this doclet.
  73      * @param element the containing element of the doc-files.
  74      *
  75      */
  76     public DocFilesHandlerImpl(HtmlConfiguration configuration, Element element) {
  77         this.configuration = configuration;

  78         this.element = element;
  79 
  80         switch (element.getKind()) {
  81             case MODULE:
  82                 ModuleElement mdle = (ModuleElement)element;
  83                 location = configuration.utils.getLocationForModule(mdle);
  84                 source = DocPaths.DOC_FILES;
  85                 break;
  86             case PACKAGE:
  87                 PackageElement pkg = (PackageElement)element;
  88                 location = configuration.utils.getLocationForPackage(pkg);
  89                 // Note, given that we have a module-specific location,
  90                 // we want a module-relative path for the source, and not the
  91                 // standard path that may include the module directory
  92                 source = DocPath.create(pkg.getQualifiedName().toString().replace('.', '/'))
  93                         .resolve(DocPaths.DOC_FILES);
  94                 break;
  95             default:
  96                 throw new AssertionError("unsupported element " + element);
  97         }


 143         DocFile dstdir = DocFile.createFileForOutput(configuration, dstDocPath);
 144         if (srcdir.isSameFile(dstdir)) {
 145             return;
 146         }
 147         for (DocFile srcfile: srcdir.list()) {
 148             DocFile destfile = dstdir.resolve(srcfile.getName());
 149             if (srcfile.isFile()) {
 150                 if (destfile.exists() && !first) {
 151                     configuration.messages.warning("doclet.Copy_Overwrite_warning",
 152                             srcfile.getPath(), dstdir.getPath());
 153                 } else {
 154                     if (Utils.toLowerCase(srcfile.getPath()).endsWith(".html")) {
 155                         handleHtmlFile(srcfile, dstDocPath);
 156                     } else {
 157                         configuration.messages.notice("doclet.Copying_File_0_To_Dir_1",
 158                                 srcfile.getPath(), dstdir.getPath());
 159                         destfile.copyFile(srcfile);
 160                     }
 161                 }
 162             } else if (srcfile.isDirectory()) {
 163                 if (configuration.copydocfilesubdirs
 164                         && !configuration.shouldExcludeDocFileDir(srcfile.getName())) {
 165                     DocPath dirDocPath = dstDocPath.resolve(srcfile.getName());
 166                     copyDirectory(srcfile, dirDocPath, first);
 167                 }
 168             }
 169         }
 170     }
 171 
 172     private void handleHtmlFile(DocFile srcfile, DocPath dstPath) throws DocFileIOException {
 173         Utils utils = configuration.utils;
 174         FileObject fileObject = srcfile.getFileObject();
 175         DocFileElement dfElement = new DocFileElement(utils, element, fileObject);
 176 
 177         DocPath dfilePath = dstPath.resolve(srcfile.getName());
 178         HtmlDocletWriter docletWriter = new DocFileWriter(configuration, dfilePath, element);
 179         configuration.messages.notice("doclet.Generating_0", docletWriter.filename.getPath());
 180 
 181         List<? extends DocTree> localTags = getLocalHeaderTags(utils.getPreamble(dfElement));
 182         Content localTagsContent = docletWriter.commentTagsToContent(null, dfElement, localTags, false);
 183 




  47 import jdk.javadoc.internal.doclets.toolkit.util.Utils;
  48 
  49 import javax.lang.model.element.Element;
  50 import javax.lang.model.element.ModuleElement;
  51 import javax.lang.model.element.PackageElement;
  52 import javax.tools.FileObject;
  53 import javax.tools.JavaFileManager.Location;
  54 
  55 import java.util.ArrayList;
  56 import java.util.Collections;
  57 import java.util.List;
  58 
  59 import jdk.javadoc.internal.doclets.formats.html.markup.Navigation.PageMode;
  60 
  61 public class DocFilesHandlerImpl implements DocFilesHandler {
  62 
  63     public final Element element;
  64     public final Location location;
  65     public final DocPath  source;
  66     public final HtmlConfiguration configuration;
  67     private final HtmlOptions options;
  68     private Navigation navBar;
  69 
  70     /**
  71      * Constructor to construct the DocFilesWriter object.
  72      *
  73      * @param configuration the configuration of this doclet.
  74      * @param element the containing element of the doc-files.
  75      *
  76      */
  77     public DocFilesHandlerImpl(HtmlConfiguration configuration, Element element) {
  78         this.configuration = configuration;
  79         this.options = configuration.getOptions();
  80         this.element = element;
  81 
  82         switch (element.getKind()) {
  83             case MODULE:
  84                 ModuleElement mdle = (ModuleElement)element;
  85                 location = configuration.utils.getLocationForModule(mdle);
  86                 source = DocPaths.DOC_FILES;
  87                 break;
  88             case PACKAGE:
  89                 PackageElement pkg = (PackageElement)element;
  90                 location = configuration.utils.getLocationForPackage(pkg);
  91                 // Note, given that we have a module-specific location,
  92                 // we want a module-relative path for the source, and not the
  93                 // standard path that may include the module directory
  94                 source = DocPath.create(pkg.getQualifiedName().toString().replace('.', '/'))
  95                         .resolve(DocPaths.DOC_FILES);
  96                 break;
  97             default:
  98                 throw new AssertionError("unsupported element " + element);
  99         }


 145         DocFile dstdir = DocFile.createFileForOutput(configuration, dstDocPath);
 146         if (srcdir.isSameFile(dstdir)) {
 147             return;
 148         }
 149         for (DocFile srcfile: srcdir.list()) {
 150             DocFile destfile = dstdir.resolve(srcfile.getName());
 151             if (srcfile.isFile()) {
 152                 if (destfile.exists() && !first) {
 153                     configuration.messages.warning("doclet.Copy_Overwrite_warning",
 154                             srcfile.getPath(), dstdir.getPath());
 155                 } else {
 156                     if (Utils.toLowerCase(srcfile.getPath()).endsWith(".html")) {
 157                         handleHtmlFile(srcfile, dstDocPath);
 158                     } else {
 159                         configuration.messages.notice("doclet.Copying_File_0_To_Dir_1",
 160                                 srcfile.getPath(), dstdir.getPath());
 161                         destfile.copyFile(srcfile);
 162                     }
 163                 }
 164             } else if (srcfile.isDirectory()) {
 165                 if (options.copyDocfileSubdirs
 166                         && !configuration.shouldExcludeDocFileDir(srcfile.getName())) {
 167                     DocPath dirDocPath = dstDocPath.resolve(srcfile.getName());
 168                     copyDirectory(srcfile, dirDocPath, first);
 169                 }
 170             }
 171         }
 172     }
 173 
 174     private void handleHtmlFile(DocFile srcfile, DocPath dstPath) throws DocFileIOException {
 175         Utils utils = configuration.utils;
 176         FileObject fileObject = srcfile.getFileObject();
 177         DocFileElement dfElement = new DocFileElement(utils, element, fileObject);
 178 
 179         DocPath dfilePath = dstPath.resolve(srcfile.getName());
 180         HtmlDocletWriter docletWriter = new DocFileWriter(configuration, dfilePath, element);
 181         configuration.messages.notice("doclet.Generating_0", docletWriter.filename.getPath());
 182 
 183         List<? extends DocTree> localTags = getLocalHeaderTags(utils.getPreamble(dfElement));
 184         Content localTagsContent = docletWriter.commentTagsToContent(null, dfElement, localTags, false);
 185 


< prev index next >