📄 cmshtmlimport.java
字号:
/*
* 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.CmsFolder;
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
* @author Peter Bonrad
*
* @version $Revision: 1.15 $
*
* @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;
/** should broken links be kept. */
private String m_keepBrokenLinks;
/** the keep broken links mode flag. */
private boolean m_keepBrokenLinksMode;
/** leave downloads at the original location. */
private String m_leaveDownloads;
/** the leave downloads mode flag. */
private boolean m_leaveDownloadsMode;
/** leave external links at the original location. */
private String m_leaveExternalLinks;
/** the leave external links mode flag. */
private boolean m_leaveExternalLinksMode;
/** leave images at the original location. */
private String m_leaveImages;
/** the leave images mode flag. */
private boolean m_leaveImagesMode;
/** 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;
/** Map with all parents in file system to OpenCms. */
private HashMap m_parents;
/** 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"),
request.getParameter("leaveimages"),
request.getParameter("leavedownloads"),
request.getParameter("keepbrokenlinks"),
request.getParameter("leaveexternallinks"),
request);
}
/**
* 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
* @param leaveImages flag if images are left in original location
* @param leaveDownloads flag if downloads are left in original location
* @param keepBrokenLinks flag if broken links are kept or replaced by a '#'
* @param leaveExternalLinks flag if external links are left at their original location
*/
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,
String leaveImages,
String leaveDownloads,
String keepBrokenLinks,
String leaveExternalLinks,
HttpServletRequest request) {
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 = "";
}
String action = request.getParameter("action");
if (action == null) {
overwrite = "checked";
}
if (leaveImages == null) {
leaveImages = "";
}
if (leaveDownloads == null) {
leaveDownloads = "";
}
if (keepBrokenLinks == null) {
keepBrokenLinks = "";
}
if (leaveExternalLinks == null) {
leaveExternalLinks = "";
}
// 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();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -