Fallback to Default Icon if Specified File is Missing

XMLWordPrintable

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Minor
    • Component/s: htmlpublisher-plugin
    • None

      While testing the icon feature in the htmlpublisher-plugin, I noticed that if the user specifies a file that does not exist, the plugin does not fall back to the default icon, attempting instead to load a missing file, resulting in a broken image in the UI.

      Steps to reproduce:
      1) In the job configuration, set an icon to a file that does not exist
      2) Run the job
      3) The UI attempts to load a file that is missing, without falling back to the default icon

      Proposed fix
      A simple fix to this issue can be to edit the getIconFileName() method (in HtmlPublisherTarget.java), adding the check for the file existence:

            public String getIconFileName() {
                  String icon;
                  if (StringUtils.isNotBlank(actualHtmlPublisherTarget.icon)) {
                      if (actualHtmlPublisherTarget.icon.startsWith("symbol-")) {
                          icon = actualHtmlPublisherTarget.icon;
                      }
                      else {
                          File iconFile = new File(dir(), actualHtmlPublisherTarget.icon);
      
                          if(iconFile.exists()){
                              icon = project.getUrl() + dir().getName() + "/" + 
             actualHtmlPublisherTarget.icon;
                          }else{
                              icon = "symbol-document-text"; 
                          }
                      }
                  } else {
                      icon = "symbol-document-text";
                  }
                  return dir().exists() ? icon : null;
            }
      

      Would this be a useful improvement? If so, I'd be happy to submit a PR!

            Assignee:
            Unassigned
            Reporter:
            Giovanni
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: