Class CmsHtmlImport

java.lang.Object
org.opencms.workplace.tools.database.CmsHtmlImport

public class CmsHtmlImport extends Object
This class implements the HTML->OpenCms Template converter for OpenCms 6.x.

The HTML files can lay in a directory or in a zip file. The entries in the zip file are saved temporary in the tmp-directory of the system. Every file is stored into the correct location in the OpenCms VFS.

Since:
6.0.0
  • Field Details

  • Constructor Details

    • CmsHtmlImport

      public CmsHtmlImport()
      Default Constructor.

    • CmsHtmlImport

      public CmsHtmlImport(org.opencms.file.CmsObject cms)
      Creates a new import object for the given cms object.

      Parameters:
      cms - the current cms context
  • Method Details

    • createTempFolder

      public static File createTempFolder(String name) throws Exception
      This function creates a folder in the temporary-directory.

      Parameters:
      name - the name of the folder
      Returns:
      the folder file
      Throws:
      Exception - if the folder can not create
    • getAbsoluteUri

      public String getAbsoluteUri(String relativeUri, String baseUri)
      Calculates an absolute uri from a relative "uri" and the given absolute "baseUri".

      If "uri" is already absolute, it is returned unchanged. This method also returns "uri" unchanged if it is not well-formed.

      Parameters:
      relativeUri - the relative uri to calculate an absolute uri for
      baseUri - the base uri, this must be an absolute uri
      Returns:
      an absolute uri calculated from "uri" and "baseUri"
    • getDestinationDir

      Returns the destinationDir.

      Returns:
      the destinationDir
    • getDownloadGallery

      Returns the downloadGallery.

      Returns:
      the downloadGallery
    • getElement

      public String getElement()
      Returns the element.

      Returns:
      the element
    • getEndPattern

      Returns the endPattern.

      Returns:
      the endPattern
    • getHttpDir

      public String getHttpDir()
      Returns the httpDir.

      Returns:
      the httpDir
    • getImageGallery

      Returns the imageGallery.

      Returns:
      the imageGallery
    • getInputDir

      public String getInputDir()
      Returns the inputDir.

      Returns:
      the inputDir
    • getInputEncoding

      Returns the inputEncoding.

      Returns:
      the inputEncoding
    • getLinkGallery

      Returns the linkGallery.

      Returns:
      the linkGallery
    • getLocale

      public String getLocale()
      Returns the local.

      Returns:
      the local
    • getStartPattern

      Returns the startPattern.

      Returns:
      the startPattern
    • getTemplate

      public String getTemplate()
      Returns the template.

      Returns:
      the template
    • isKeepBrokenLinks

      public boolean isKeepBrokenLinks()
      Returns the keepBrokenLinks.

      Returns:
      the keepBrokenLinks
    • isOverwrite

      public boolean isOverwrite()
      Returns the overwrite.

      Returns:
      the overwrite
    • setCmsObject

      public void setCmsObject(org.opencms.file.CmsObject cmsObject)
      Sets the cmsObject.

      Parameters:
      cmsObject - the cmsObject to set
    • setDestinationDir

      public void setDestinationDir(String destinationDir)
      Sets the destinationDir.

      Parameters:
      destinationDir - the destinationDir to set
    • setDownloadGallery

      public void setDownloadGallery(String downloadGallery)
      Sets the downloadGallery.

      Parameters:
      downloadGallery - the downloadGallery to set
    • setElement

      public void setElement(String element)
      Sets the element.

      Parameters:
      element - the element to set
    • setEndPattern

      public void setEndPattern(String endPattern)
      Sets the endPattern.

      Parameters:
      endPattern - the endPattern to set
    • setHttpDir

      public void setHttpDir(String httpDir)
      Sets the httpDir.

      Parameters:
      httpDir - the httpDir to set
    • setImageGallery

      public void setImageGallery(String imageGallery)
      Sets the imageGallery.

      Parameters:
      imageGallery - the imageGallery to set
    • setInputDir

      public void setInputDir(String inputDir)
      Sets the inputDir.

      Parameters:
      inputDir - the inputDir to set
    • setInputEncoding

      public void setInputEncoding(String inputEncoding)
      Sets the inputEncoding.

      Parameters:
      inputEncoding - the inputEncoding to set
    • setKeepBrokenLinks

      public void setKeepBrokenLinks(boolean keepBrokenLinks)
      Sets the keepBrokenLinks.

      Parameters:
      keepBrokenLinks - the keepBrokenLinks to set
    • setLinkGallery

      public void setLinkGallery(String linkGallery)
      Sets the linkGallery.

      Parameters:
      linkGallery - the linkGallery to set
    • setLocale

      public void setLocale(String locale)
      Sets the local.

      Parameters:
      locale - the local to set
    • setOverwrite

      public void setOverwrite(boolean overwrite)
      Sets the overwrite.

      Parameters:
      overwrite - the overwrite to set
    • setStartPattern

      public void setStartPattern(String startPattern)
      Sets the startPattern.

      Parameters:
      startPattern - the startPattern to set
    • setTemplate

      public void setTemplate(String template)
      Sets the template.

      Parameters:
      template - the template to set
    • startImport

      public void startImport(org.opencms.report.I_CmsReport report) throws Exception
      Imports all resources from the real file system, stores them into the correct locations in the OpenCms VFS and modifies all links. This method is called form the JSP to start the import process.

      Parameters:
      report - StringBuffer for reporting
      Throws:
      Exception - if something goes wrong
    • storeExternalLink

      public String storeExternalLink(String externalLink)
      Add a new external link to the storage of external links.

      All links in this storage are later used to create entries in the external link gallery.

      Parameters:
      externalLink - link to an external resource
      Returns:
      the complete path to the external link file, if one is created.
    • storeImageInfo

      public void storeImageInfo(String image, String altText)
      Add a new image info to the storage of image info's.

      The image info's are later used to set the description properties of the images.

      Parameters:
      image - the name of the image
      altText - the alt-text of the image
    • translateLink

      public String translateLink(String link)
      Translated a link into the real file system to its new location in the OpenCms VFS.

      This is needed by the HtmlConverter to get the correct links for link translation.

      Parameters:
      link - link to the real file system
      Returns:
      string containing absolute link into the OpenCms VFS
    • validate

      public void validate(org.apache.commons.fileupload.FileItem fi, boolean isdefault) throws org.opencms.main.CmsIllegalArgumentException
      Tests if all given input parameters for the HTML Import are valid, that is that all the given folders do exist.

      Parameters:
      fi - a file item if a file is uploaded per HTTP otherwise null
      isdefault - if this sets, then the destination and input directory can be empty
      Throws:
      org.opencms.main.CmsIllegalArgumentException - if some parameters are not valid