< prev index next >

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

Print this page




  57 public class DocFilesHandlerImpl implements DocFilesHandler {
  58 
  59     public final Element element;
  60     public final Location location;
  61     public final DocPath  source;
  62     public final HtmlConfiguration configuration;
  63 
  64     /**
  65      * Constructor to construct the DocFilesWriter object.
  66      *
  67      * @param configuration the configuration of this doclet.
  68      * @param element the containing element of the doc-files.
  69      *
  70      */
  71     public DocFilesHandlerImpl(HtmlConfiguration configuration, Element element) {
  72         this.configuration = configuration;
  73         this.element = element;
  74 
  75         switch (element.getKind()) {
  76             case MODULE:
  77                 location = configuration.utils.getLocationForModule((ModuleElement)element);

  78                 source = DocPaths.DOC_FILES;
  79                 break;
  80             case PACKAGE:
  81                 location = configuration.utils.getLocationForPackage((PackageElement)element);
  82                 source = DocPath.forPackage((PackageElement)element).resolve(DocPaths.DOC_FILES);





  83                 break;
  84             default:
  85                 throw new AssertionError("unsupported element " + element);
  86         }
  87     }
  88 
  89     /**
  90      * Copy doc-files directory and its contents from the source
  91      * elements directory to the generated documentation directory.
  92      *
  93      * @throws DocFileIOException if there is a problem while copying
  94      *         the documentation files
  95      */
  96 
  97     public void copyDocFiles()  throws DocFileIOException {
  98         boolean first = true;
  99         for (DocFile srcdir : DocFile.list(configuration, location, source)) {
 100             if (!srcdir.isDirectory()) {
 101                 continue;
 102             }
 103             DocPath path = null;
 104             switch (this.element.getKind()) {
 105                 case MODULE:
 106                     path = DocPath.forModule((ModuleElement)this.element);
 107                     break;
 108                 case PACKAGE:
 109                     path = DocPath.forPackage((PackageElement)this.element);
 110                     break;
 111                 default:
 112                     throw new AssertionError("unknown kind:" + this.element.getKind());
 113             }
 114             copyDirectory(srcdir, path.resolve(DocPaths.DOC_FILES), first);
 115             first = false;
 116         }
 117     }
 118 
 119 
 120     private void copyDirectory(DocFile srcdir, final DocPath dstDocPath,
 121                                boolean first) throws DocFileIOException {
 122         DocFile dstdir = DocFile.createFileForOutput(configuration, dstDocPath);
 123         if (srcdir.isSameFile(dstdir)) {
 124             return;
 125         }
 126         for (DocFile srcfile: srcdir.list()) {
 127             DocFile destfile = dstdir.resolve(srcfile.getName());
 128             if (srcfile.isFile()) {
 129                 if (destfile.exists() && !first) {




  57 public class DocFilesHandlerImpl implements DocFilesHandler {
  58 
  59     public final Element element;
  60     public final Location location;
  61     public final DocPath  source;
  62     public final HtmlConfiguration configuration;
  63 
  64     /**
  65      * Constructor to construct the DocFilesWriter object.
  66      *
  67      * @param configuration the configuration of this doclet.
  68      * @param element the containing element of the doc-files.
  69      *
  70      */
  71     public DocFilesHandlerImpl(HtmlConfiguration configuration, Element element) {
  72         this.configuration = configuration;
  73         this.element = element;
  74 
  75         switch (element.getKind()) {
  76             case MODULE:
  77                 ModuleElement mdle = (ModuleElement)element;
  78                 location = configuration.utils.getLocationForModule(mdle);
  79                 source = DocPaths.DOC_FILES;
  80                 break;
  81             case PACKAGE:
  82                 PackageElement pkg = (PackageElement)element;
  83                 location = configuration.utils.getLocationForPackage(pkg);
  84                 // Note, given that we have a module-specific location,
  85                 // we want a module-relative path for the source, and not the
  86                 // standard path that may include the module directory
  87                 source = DocPath.create(pkg.getQualifiedName().toString().replace('.', '/'))
  88                         .resolve(DocPaths.DOC_FILES);
  89                 break;
  90             default:
  91                 throw new AssertionError("unsupported element " + element);
  92         }
  93     }
  94 
  95     /**
  96      * Copy doc-files directory and its contents from the source
  97      * elements directory to the generated documentation directory.
  98      *
  99      * @throws DocFileIOException if there is a problem while copying
 100      *         the documentation files
 101      */
 102 
 103     public void copyDocFiles()  throws DocFileIOException {
 104         boolean first = true;
 105         for (DocFile srcdir : DocFile.list(configuration, location, source)) {
 106             if (!srcdir.isDirectory()) {
 107                 continue;
 108             }
 109             DocPath path = null;
 110             switch (this.element.getKind()) {
 111                 case MODULE:
 112                     path = DocPaths.forModule((ModuleElement)this.element);
 113                     break;
 114                 case PACKAGE:
 115                     path = configuration.docPaths.forPackage((PackageElement)this.element);
 116                     break;
 117                 default:
 118                     throw new AssertionError("unknown kind:" + this.element.getKind());
 119             }
 120             copyDirectory(srcdir, path.resolve(DocPaths.DOC_FILES), first);
 121             first = false;
 122         }
 123     }
 124 
 125 
 126     private void copyDirectory(DocFile srcdir, final DocPath dstDocPath,
 127                                boolean first) throws DocFileIOException {
 128         DocFile dstdir = DocFile.createFileForOutput(configuration, dstDocPath);
 129         if (srcdir.isSameFile(dstdir)) {
 130             return;
 131         }
 132         for (DocFile srcfile: srcdir.list()) {
 133             DocFile destfile = dstdir.resolve(srcfile.getName());
 134             if (srcfile.isFile()) {
 135                 if (destfile.exists() && !first) {


< prev index next >