⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmshtmlimport.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        // body element should be set by html-form
        m_inputDir = inputDir.trim();

        // cut of a trailing '/' or '\'
        if (m_inputDir.endsWith("/") || m_inputDir.endsWith("\\")) {
            m_inputDir = m_inputDir.substring(0, m_inputDir.length() - 1);
        }

        m_destinationDir = destinationDir.trim();
        if ((!m_destinationDir.equals("")) && (!m_destinationDir.endsWith("/"))) {
            m_destinationDir += "/";
        }

        m_imageGallery = imageGallery.trim();
        if ((!m_imageGallery.equals("")) && (!m_imageGallery.endsWith("/"))) {
            m_imageGallery += "/";
        }

        m_linkGallery = linkGallery.trim();
        if ((!m_linkGallery.equals("")) && (!m_linkGallery.endsWith("/"))) {
            m_linkGallery += "/";
        }

        m_downloadGallery = downloadGallery.trim();
        if ((!m_downloadGallery.equals("")) && (!m_downloadGallery.endsWith("/"))) {
            m_downloadGallery += "/";
        }

        m_template = template;
        m_element = element;
        m_inputEncoding = encoding;

        if (CmsStringUtil.isEmpty(m_inputEncoding)) {
            m_inputEncoding = CmsEncoder.ENCODING_ISO_8859_1;
        }
        m_startPattern = startPattern;
        m_endPattern = endPattern;

        m_overwrite = overwrite.trim();
        if (m_overwrite.equals("checked")) {
            m_overwriteMode = true;
        } else {
            m_overwriteMode = false;
        }

        m_leaveImages = leaveImages.trim();
        if (m_leaveImages.equals("checked")) {
            m_leaveImagesMode = true;
        } else {
            m_leaveImagesMode = false;
        }

        m_leaveDownloads = leaveDownloads.trim();
        if (m_leaveDownloads.equals("checked")) {
            m_leaveDownloadsMode = true;
        } else {
            m_leaveDownloadsMode = false;
        }

        m_keepBrokenLinks = keepBrokenLinks.trim();
        if (m_keepBrokenLinks.equals("checked")) {
            m_keepBrokenLinksMode = true;
        } else {
            m_keepBrokenLinksMode = false;
        }

        m_leaveExternalLinks = leaveExternalLinks.trim();
        if (m_leaveExternalLinks.equals("checked")) {
            m_leaveExternalLinksMode = true;
        } else {
            m_leaveExternalLinksMode = false;
        }

        // create all other required member objects
        m_fileIndex = new HashMap();
        m_parents = new HashMap();
        m_externalLinks = new HashSet();
        m_imageInfo = new HashMap();
        m_extensions = OpenCms.getResourceManager().getExtensionMapping();
        m_htmlConverter = new CmsHtmlImportConverter(this, false);
        m_baseUrl = null;
        try {
            m_baseUrl = new URL("file://");
        } catch (MalformedURLException e) {
            // this won't happen
        }
    }

    /**
     * Tests if all given input parameters for the HTML Import are valid, i.e. that all the 
     * given folders do exist. <p>
     * 
     * @throws CmsIllegalArgumentException if some parameters are not valid
     */
    public void checkParameters() throws CmsIllegalArgumentException {

        // check the input directory
        File inputDir = new File(m_inputDir);
        if (!inputDir.exists() || inputDir.isFile()) {
            // the input directory is not valid
            throw new CmsIllegalArgumentException(Messages.get().container(
                Messages.GUI_HTMLIMPORT_INPUTDIR_1,
                m_inputDir));
        }

        // check the destination directory        
        try {
            m_cmsObject.readFolder(m_destinationDir);
        } catch (CmsException e) {
            // an excpetion is thrown if the folder does not exist
            throw new CmsIllegalArgumentException(Messages.get().container(
                Messages.GUI_HTMLIMPORT_DESTDIR_1,
                m_destinationDir), e);
        }

        // check the image gallery
        // only if flag for leaving images at original location is off
        if (!m_leaveImagesMode) {
            try {
                CmsFolder folder = m_cmsObject.readFolder(m_imageGallery);
                // check if folder is a image gallery
                String name = OpenCms.getResourceManager().getResourceType(folder.getTypeId()).getTypeName();
                if (!name.equals("imagegallery")) {
                    throw new CmsIllegalArgumentException(Messages.get().container(
                        Messages.GUI_HTMLIMPORT_IMGGALLERY_INVALID_1,
                        m_imageGallery));
                }
            } catch (CmsException e) {
                // an excpetion is thrown if the folder does not exist
                throw new CmsIllegalArgumentException(Messages.get().container(
                    Messages.GUI_HTMLIMPORT_IMGGALLERY_1,
                    m_imageGallery), e);
            }
        }

        // check the link gallery
        // only if flag for leaving external links at original location is off
        if (!m_leaveExternalLinksMode) {
            try {
                CmsFolder folder = m_cmsObject.readFolder(m_linkGallery);
                // check if folder is a link gallery
                String name = OpenCms.getResourceManager().getResourceType(folder.getTypeId()).getTypeName();
                if (!name.equals("linkgallery")) {
                    throw new CmsIllegalArgumentException(Messages.get().container(
                        Messages.GUI_HTMLIMPORT_LINKGALLERY_INVALID_1,
                        m_linkGallery));
                }
            } catch (CmsException e) {
                // an excpetion is thrown if the folder does not exist
                throw new CmsIllegalArgumentException(Messages.get().container(
                    Messages.GUI_HTMLIMPORT_LINKGALLERY_1,
                    m_linkGallery), e);
            }
        }

        // check the download gallery
        if ((!isExternal(m_downloadGallery)) && (!m_leaveDownloadsMode)) {
            try {
                CmsFolder folder = m_cmsObject.readFolder(m_downloadGallery);
                // check if folder is a download gallery
                String name = OpenCms.getResourceManager().getResourceType(folder.getTypeId()).getTypeName();
                if (!name.equals("downloadgallery")) {
                    throw new CmsIllegalArgumentException(Messages.get().container(
                        Messages.GUI_HTMLIMPORT_DOWNGALLERY_INVALID_1,
                        m_downloadGallery));
                }
            } catch (CmsException e) {
                // an excpetion is thrown if the folder does not exist
                throw new CmsIllegalArgumentException(Messages.get().container(
                    Messages.GUI_HTMLIMPORT_DOWNGALLERY_1,
                    m_downloadGallery), e);
            }
        }

        // check the template
        try {
            m_cmsObject.readResource(m_template, CmsResourceFilter.ALL);
        } catch (CmsException e) {
            // an excpetion is thrown if the template does not exist
            if (!isValidElement()) {
                throw new CmsIllegalArgumentException(Messages.get().container(
                    Messages.GUI_HTMLIMPORT_TEMPLATE_1,
                    m_template), e);
            }
        }

        // check the element
        if (!isValidElement()) {
            throw new CmsIllegalArgumentException(Messages.get().container(
                Messages.GUI_HTMLIMPORT_INVALID_ELEM_2,
                m_element,
                m_template));
        }

        // check if we are in an offline project
        if (m_cmsObject.getRequestContext().currentProject().isOnlineProject()) {
            throw new CmsIllegalArgumentException(
                Messages.get().container(Messages.GUI_HTMLIMPORT_CONSTRAINT_OFFLINE_0));
        }
    }

    /**
     * Calculates an absolute uri from a relative "uri" and the given absolute "baseUri".<p> 
     * 
     * If "uri" is already absolute, it is returned unchanged.
     * This method also returns "uri" unchanged if it is not well-formed.<p>
     *    
     * @param relativeUri the relative uri to calculate an absolute uri for
     * @param baseUri the base uri, this must be an absolute uri
     * @return an absolute uri calculated from "uri" and "baseUri"
     */
    public String getAbsoluteUri(String relativeUri, String baseUri) {

        if ((relativeUri == null) || (relativeUri.charAt(0) == '/') || (relativeUri.startsWith("#"))) {

            return relativeUri;
        }

        // if we are on a windows system, we must add a ":" in the uri later               
        String windowsAddition = "";
        if (File.separator.equals("\\")) {
            windowsAddition = ":";
        }

        try {
            URL url = new URL(new URL(m_baseUrl, "file://" + baseUri), relativeUri);
            if (url.getQuery() == null) {
                if (url.getRef() == null) {
                    return url.getHost() + windowsAddition + url.getPath();
                } else {
                    return url.getHost() + windowsAddition + url.getPath() + "#" + url.getRef();
                }
            } else {
                return url.getHost() + windowsAddition + url.getPath() + "?" + url.getQuery();
            }
        } catch (MalformedURLException e) {
            return relativeUri;
        }
    }

    /**
     * Returns the destinationDir.<p>
     *
     * @return the destinationDir
     */
    public String getDestinationDir() {

        return m_destinationDir;
        //        return m_destinationDir.substring(0, m_destinationDir.length() - 1);
    }

    /**
     * Returns the downloadGallery.<p>
     *
     * @return the downloadGallery
     */
    public String getDownloadGallery() {

        return m_downloadGallery;
    }

    /**
     * Returns the element.<p>
     *
     * @return the element
     */
    public String getElement() {

        return m_element;
    }

    /**
     * Returns the endPattern.<p>
     *
     * @return the endPattern
     */
    public String getEndPattern() {

        return m_endPattern;
    }

    /**
     * Returns the imageGallery.<p>
     *
     * @return the imageGallery
     */
    public String getImageGallery() {

        return m_imageGallery;
    }

    /**
     * Returns the inputDir.<p>
     *
     * @return the inputDir
     */
    public String getInputDir() {

        return m_inputDir;
    }

    /**
     * Returns the inputEncoding.<p>
     *
     * @return the inputEncoding
     */
    public String getInputEncoding() {

        return m_inputEncoding;
    }

    /**
     * Returns the keepBrokenLinks.<p>
     *
     * @return the keepBrokenLinks
     */
    public String getKeepBrokenLinks() {

        return m_keepBrokenLinks;
    }

    /**
     * Returns the leaveDownloads.<p>
     *
     * @return the leaveDownloads
     */
    public String getLeaveDownloads() {

        return m_leaveDownloads;
    }

    /**
     * Returns the leaveExternalLinks.<p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -