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

📄 cmshtmlimport.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*
 * File   :
 * Date   : 
 * Version: 
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.workplace.tools.database;

import org.opencms.db.CmsDbIoException;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsProperty;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.file.types.CmsResourceTypeFolder;
import org.opencms.file.types.CmsResourceTypeImage;
import org.opencms.file.types.CmsResourceTypePlain;
import org.opencms.file.types.CmsResourceTypePointer;
import org.opencms.file.types.CmsResourceTypeXmlPage;
import org.opencms.i18n.CmsEncoder;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.i18n.CmsMessageContainer;
import org.opencms.importexport.CmsImportExportException;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.loader.CmsResourceManager;
import org.opencms.lock.CmsLock;
import org.opencms.main.CmsException;
import org.opencms.main.CmsIllegalArgumentException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.report.I_CmsReport;
import org.opencms.staticexport.CmsLink;
import org.opencms.staticexport.CmsLinkTable;
import org.opencms.util.CmsStringUtil;
import org.opencms.xml.page.CmsXmlPage;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.collections.ExtendedProperties;
import org.apache.commons.logging.Log;

/**
 * This class implements the HTML->OpenCms Template converter for OpenCms 6.x.<p>
 * 
 * @author Michael Emmerich 
 * @author Armen Markarian 
 * 
 * @version $Revision: 1.12 $ 
 * 
 * @since 6.0.0 
 */
public class CmsHtmlImport {

    /** filename of the meta.properties file. */
    public static final String META_PROPERTIES = "meta.properties";

    /** The log object for this class. */
    private static final Log LOG = CmsLog.getLog(CmsHtmlImport.class);

    /** the base URL for link modification. */
    private URL m_baseUrl;

    private CmsJspActionElement m_cms;

    /** the CmsObject to use. */
    private CmsObject m_cmsObject;

    /** the destination directory in the OpenCms VFS. */
    private String m_destinationDir;

    /** he download gallery name. */
    private String m_downloadGallery;

    private String m_element;

    /** the end pattern for extracting content. */
    private String m_endPattern;

    /** HashMap of all known extensions in OpenCms. */
    private Map m_extensions;

    /**
     * Storage for external links.<p>
     * 
     * It is filled by the HtmlConverter each time a new external link is found.<p>
     */
    private HashSet m_externalLinks;

    /** 
     * The file index contains all resourcenames in the real file system and their renamed ones in the OpenCms VFS.<p>
     */
    private HashMap m_fileIndex;

    /** the HTML converter to parse and modifiy the content. */
    private CmsHtmlImportConverter m_htmlConverter;

    /** reference to the import thread. */
    private CmsHtmlImportThread m_htmlImportThread;

    /** the image gallery name. */
    private String m_imageGallery;

    /**
     * Storage for image alt tags, it is filled by the HtmlConverter each time a new image is found.
     */
    private HashMap m_imageInfo;

    /** the input directory in the "real" file system. */
    private String m_inputDir;

    /** the encoding used for all imported input files. */
    private String m_inputEncoding;

    /** the external link gallery name. */
    private String m_linkGallery;

    /** the locale use for content definition. */
    private Locale m_locale;

    /** the overwrite value new resources. */
    private String m_overwrite;

    /** the overwrite mode flag. */
    private boolean m_overwriteMode;

    /** the report for the output. */
    private I_CmsReport m_report;

    /** the start pattern for extracting content. */
    private String m_startPattern;

    /** the template use for all pages. */
    private String m_template;

    /**
     * Creates new HtmlImport Object with http request parameters.<p>
     * 
     * @param cms the current CmsJspActionElement  
     * @param request the http servlet request
     */
    public CmsHtmlImport(CmsJspActionElement cms, HttpServletRequest request) {

        this(
            cms,
            request.getParameter("inputDir"),
            request.getParameter("destinationDir"),
            request.getParameter("imageGallery"),
            request.getParameter("linkGallery"),
            request.getParameter("downloadGallery"),
            request.getParameter("template"),
            request.getParameter("element"),
            request.getParameter("locale"),
            request.getParameter("encoding"),
            request.getParameter("startPattern"),
            request.getParameter("endPattern"),
            request.getParameter("overwrite"));
    }

    /**
     * Constructor, creates a new HtmlImport.<p>
     * 
     * @param cms the current CmsJspActionElement 
     * @param inputDir the input directory in the "real" file system 
     * @param destinationDir the destination directory in the OpenCms VFS
     * @param imageGallery the image gallery name
     * @param linkGallery the external link gallery name
     * @param downloadGallery the download gallery name
     * @param template the template use for all pages
     * @param element the element property use for all pages
     * @param locale the full locale name 
     * @param encoding encoding used for importing all pages
     * @param startPattern the start pattern definition for content extracting
     * @param endPattern the end pattern definition for content extracting 
     * @param overwrite the overwrite mode
     */
    public CmsHtmlImport(
        CmsJspActionElement cms,
        String inputDir,
        String destinationDir,
        String imageGallery,
        String linkGallery,
        String downloadGallery,
        String template,
        String element,
        String locale,
        String encoding,
        String startPattern,
        String endPattern,
        String overwrite) {

        if (inputDir == null) {
            inputDir = "";
        }
        if (destinationDir == null) {
            destinationDir = "/";
        }
        if (imageGallery == null) {
            imageGallery = "";
        }
        if (linkGallery == null) {
            linkGallery = "";
        }
        if (downloadGallery == null) {
            downloadGallery = "";
        }
        if (template == null) {
            template = "";
        }
        if (element == null) {
            element = "body";
        }
        if (encoding == null) {
            encoding = "";
        }
        if (startPattern == null) {
            startPattern = "";
        }
        if (endPattern == null) {
            endPattern = "";
        }
        if (overwrite == null) {
            overwrite = "checked";
        }

        // store all member variables
        m_cms = cms;
        m_cmsObject = m_cms.getCmsObject();
        m_locale = CmsLocaleManager.getLocale(locale);
        if (m_locale == null) {
            m_locale = m_cms.getRequestContext().getLocale();
        }
        // 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.endsWith("/")) {
            m_destinationDir += "/";
        }

        m_imageGallery = imageGallery.trim();
        if (!m_imageGallery.endsWith("/")) {
            m_imageGallery += "/";
        }
        m_linkGallery = linkGallery.trim();
        if (!m_linkGallery.endsWith("/")) {
            m_linkGallery += "/";
        }
        m_downloadGallery = downloadGallery.trim();
        if (!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;
        }

        // create all other required member objects
        m_fileIndex = 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
        try {
            m_cmsObject.readFolder(m_imageGallery);
        } 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_imageGallery), e);
        }

        // check the link gallery
        try {
            m_cmsObject.readFolder(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,

⌨️ 快捷键说明

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