?? a_cmsimport.java
字號:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/importexport/A_CmsImport.java,v $
* Date : $Date: 2006/03/27 14:52:54 $
* Version: $Revision: 1.84 $
*
* 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.importexport;
import org.opencms.db.CmsUserSettings;
import org.opencms.file.CmsGroup;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsProperty;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsResource;
import org.opencms.file.types.CmsResourceTypePointer;
import org.opencms.i18n.CmsMessageContainer;
import org.opencms.i18n.I_CmsMessageBundle;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.report.I_CmsReport;
import org.opencms.security.CmsAccessControlEntry;
import org.opencms.util.CmsFileUtil;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsUUID;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Stack;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.logging.Log;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
/**
* Collection of common used methods for implementing OpenCms Import classes.<p>
*
* This class does not implement a real OpenCms import, real import implmentation should be
* inherited form this class.<p>
*
* @author Michael Emmerich
* @author Thomas Weckert
*
* @version $Revision: 1.84 $
*
* @since 6.0.0
*
* @see org.opencms.importexport.I_CmsImport
*/
public abstract class A_CmsImport implements I_CmsImport {
/** The name of the legacy resource type "page". */
public static final String RESOURCE_TYPE_LEGACY_PAGE_NAME = "page";
/** Debug flag to show debug output. */
protected static final int DEBUG = 0;
/** The id of the legacy resource type "link". */
protected static final int RESOURCE_TYPE_LINK_ID = 1024;
/** The name of the legacy resource type "link". */
protected static final String RESOURCE_TYPE_LINK_NAME = "link";
/** The id of the legacy resource type "newpage". */
protected static final int RESOURCE_TYPE_NEWPAGE_ID = 9;
/** The name of the legacy resource type "newpage". */
protected static final String RESOURCE_TYPE_NEWPAGE_NAME = "newpage";
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(A_CmsImport.class);
/** The cms context to do the import operations with. */
protected CmsObject m_cms;
/** Flag for conversion to xml pages. */
protected boolean m_convertToXmlPage;
/** The xml manifest-file. */
protected Document m_docXml;
/** Groups to create during import are stored here. */
protected Stack m_groupsToCreate;
/** Indicates if module data is being imported. */
protected boolean m_importingChannelData;
/** The import-path to write resources into the cms. */
protected String m_importPath;
/** The import-resource (folder) to load resources from. */
protected File m_importResource;
/** The import-resource (zip) to load resources from. */
protected ZipFile m_importZip;
/** Storage for all pointer properties which must be converted into links. */
protected Map m_linkPropertyStorage;
/** Storage for all pointers which must be converted into links. */
protected Map m_linkStorage;
/** The object to report the log messages. */
protected I_CmsReport m_report;
/** Messages object with the locale of the current user. */
protected I_CmsMessageBundle m_userMessages;
/**
* Converts a given digest to base64 encoding.<p>
*
* @param value the digest value in the legacy encoding
* @return the digest in the new encoding
*/
public String convertDigestEncoding(String value) {
byte[] data = new byte[value.length() / 2];
for (int i = 0; i < data.length; i++) {
data[i] = (byte)(Integer.parseInt(value.substring(i * 2, i * 2 + 2), 16) - 128);
}
return new String(Base64.encodeBase64(data));
}
/**
* Checks if the resources is in the list of immutalbe resources. <p>
*
* @param translatedName the name of the resource
* @param immutableResources the list of the immutable resources
* @return true or false
*/
protected boolean checkImmutable(String translatedName, List immutableResources) {
boolean resourceNotImmutable = true;
if (immutableResources.contains(translatedName)) {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_IMPORTEXPORT_RESOURCENAME_IMMUTABLE_1,
translatedName));
}
// this resource must not be modified by an import if it already exists
m_cms.getRequestContext().saveSiteRoot();
try {
m_cms.getRequestContext().setSiteRoot("/");
m_cms.readResource(translatedName);
resourceNotImmutable = false;
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_IMPORTEXPORT_IMMUTABLE_FLAG_SET_1,
translatedName));
}
} catch (CmsException e) {
// resourceNotImmutable will be true
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_IMPORTEXPORT_ERROR_ON_TEST_IMMUTABLE_1,
translatedName), e);
}
} finally {
m_cms.getRequestContext().restoreSiteRoot();
}
}
return resourceNotImmutable;
}
/**
* Cleans up member variables after the import is finished.<p>
*
* This is required since there is only one instance for
* each import version that is kept in memory and reused.<p>
*/
protected void cleanUp() {
m_importResource = null;
m_importZip = null;
m_report = null;
m_linkStorage = null;
m_linkPropertyStorage = null;
m_groupsToCreate = null;
m_cms = null;
}
/**
* Converts old style pointers to siblings if possible.<p>
*/
protected void convertPointerToSiblings() {
Iterator keys = m_linkStorage.keySet().iterator();
int linksSize = m_linkStorage.size();
int i = 0;
CmsResource resource = null;
String link = null;
String key = null;
try {
// loop through all links to convert
while (keys.hasNext()) {
try {
key = (String)keys.next();
link = (String)m_linkStorage.get(key);
List properties = (List)m_linkPropertyStorage.get(key);
CmsProperty.setAutoCreatePropertyDefinitions(properties, true);
m_report.print(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_SUCCESSION_2,
String.valueOf(++i),
String.valueOf(linksSize)), I_CmsReport.FORMAT_NOTE);
m_report.print(Messages.get().container(Messages.RPT_CONVERT_LINK_0), I_CmsReport.FORMAT_NOTE);
m_report.print(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_ARGUMENT_1,
key + " "));
m_report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
// check if this is an internal pointer
if (link.startsWith("/")) {
// check if the pointer target is existing
CmsResource target = m_cms.readResource(link);
// create a new sibling as CmsResource
resource = new CmsResource(
new CmsUUID(), // structure ID is always a new UUID
target.getResourceId(),
key,
target.getTypeId(),
target.isFolder(),
0,
m_cms.getRequestContext().currentProject().getId(), // TODO: pass flags from import
CmsResource.STATE_NEW,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -