?? a_cmsimport.java
字號:
target.getDateCreated(),
target.getUserCreated(),
target.getDateLastModified(),
target.getUserLastModified(),
CmsResource.DATE_RELEASED_DEFAULT,
CmsResource.DATE_EXPIRED_DEFAULT,
1,
0);
m_cms.importResource(key, resource, null, properties);
m_report.println(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_OK_0), I_CmsReport.FORMAT_OK);
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(
Messages.LOG_CONVERT_LINK_DOTS_OK_3,
String.valueOf(i),
String.valueOf(linksSize),
key));
}
} else {
m_cms.createResource(key, CmsResourceTypePointer.getStaticTypeId(), link.getBytes(), properties);
m_report.println(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_OK_0), I_CmsReport.FORMAT_OK);
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(
Messages.LOG_CONVERT_LINK_OK_3,
String.valueOf(i),
String.valueOf(linksSize),
key));
}
}
} catch (CmsException e) {
m_report.println();
m_report.print(
Messages.get().container(Messages.RPT_CONVERT_LINK_NOTFOUND_1, link),
I_CmsReport.FORMAT_WARNING);
if (LOG.isErrorEnabled()) {
LOG.error(Messages.get().getBundle().key(
Messages.ERR_IMPORTEXPORT_LINK_CONVERSION_FAILED_2,
key,
link), e);
}
}
}
} finally {
if (m_linkStorage != null) {
m_linkStorage.clear();
}
m_linkStorage = null;
if (m_linkPropertyStorage != null) {
m_linkPropertyStorage.clear();
}
m_linkPropertyStorage = null;
}
}
/**
* Returns a byte array containing the content of the file.<p>
*
* @param filename the name of the file to read
* @return a byte array containing the content of the file
*/
protected byte[] getFileBytes(String filename) {
try {
// is this a zip-file?
if (m_importZip != null) {
// yes
ZipEntry entry = m_importZip.getEntry(filename);
// path to file might be relative, too
if (entry == null && filename.startsWith("/")) {
entry = m_importZip.getEntry(filename.substring(1));
}
if (entry == null) {
throw new ZipException(Messages.get().getBundle().key(
Messages.LOG_IMPORTEXPORT_FILE_NOT_FOUND_IN_ZIP_1,
filename));
}
InputStream stream = m_importZip.getInputStream(entry);
int size = new Long(entry.getSize()).intValue();
return CmsFileUtil.readFully(stream, size);
} else {
// no - use directory
File file = new File(m_importResource, filename);
return CmsFileUtil.readFile(file);
}
} catch (FileNotFoundException fnfe) {
if (LOG.isErrorEnabled()) {
LOG.error(Messages.get().getBundle().key(Messages.ERR_IMPORTEXPORT_FILE_NOT_FOUND_1, filename), fnfe);
}
m_report.println(fnfe);
} catch (IOException ioe) {
if (LOG.isErrorEnabled()) {
LOG.error(Messages.get().getBundle().key(Messages.ERR_IMPORTEXPORT_ERROR_READING_FILE_1, filename), ioe);
}
m_report.println(ioe);
}
// this will only be returned in case there was an exception
return "".getBytes();
}
/**
* Creates a new access control entry and stores it for later write out.
*
* @param res the resource
* @param id the id of the principal
* @param allowed the allowed permissions
* @param denied the denied permissions
* @param flags the flags
*
* @return the created ACE
*/
protected CmsAccessControlEntry getImportAccessControlEntry(
CmsResource res,
String id,
String allowed,
String denied,
String flags) {
return new CmsAccessControlEntry(
res.getResourceId(),
new CmsUUID(id),
Integer.parseInt(allowed),
Integer.parseInt(denied),
Integer.parseInt(flags));
}
/**
* Returns the appropriate locale for the given destination.<p>
*
* @param destination the destination path (parent must exist)
* @param properties the properties to check at first
*
* @return the locale
*/
protected Locale getLocale(String destination, List properties) {
String localeName = CmsProperty.get(CmsPropertyDefinition.PROPERTY_LOCALE, properties).getValue();
if (localeName != null) {
// locale was already set on the files properties
return (Locale)OpenCms.getLocaleManager().getAvailableLocales(localeName).get(0);
}
// locale not set in properties, read default locales
return (Locale)OpenCms.getLocaleManager().getDefaultLocales(m_cms, CmsResource.getParentFolder(destination)).get(
0);
}
/**
* Writes alread imported access control entries for a given resource.
*
* @param resource the resource assigned to the access control entries
* @param aceList the access control entries to create
*/
protected void importAccessControlEntries(CmsResource resource, List aceList) {
if (aceList.size() == 0) {
// no ACE in the list
return;
}
try {
m_cms.importAccessControlEntries(resource, aceList);
} catch (CmsException exc) {
m_report.println(
Messages.get().container(Messages.RPT_IMPORT_ACL_DATA_FAILED_0),
I_CmsReport.FORMAT_WARNING);
}
}
/**
* Imports a single group.<p>
*
* @param name the name of the group
* @param description group description
* @param flags group flags
* @param parentgroupName name of the parent group
*
* @throws CmsImportExportException if something goes wrong
*/
protected void importGroup(String name, String description, String flags, String parentgroupName)
throws CmsImportExportException {
if (description == null) {
description = "";
}
CmsGroup parentGroup = null;
try {
if (CmsStringUtil.isNotEmpty(parentgroupName)) {
try {
parentGroup = m_cms.readGroup(parentgroupName);
} catch (CmsException exc) {
// parentGroup will be null
}
}
if (CmsStringUtil.isNotEmpty(parentgroupName) && (parentGroup == null)) {
// cannot create group, put on stack and try to create later
Map groupData = new HashMap();
groupData.put(CmsImportExportManager.N_NAME, name);
groupData.put(CmsImportExportManager.N_DESCRIPTION, description);
groupData.put(CmsImportExportManager.N_FLAGS, flags);
groupData.put(CmsImportExportManager.N_PARENTGROUP, parentgroupName);
m_groupsToCreate.push(groupData);
} else {
try {
m_report.print(Messages.get().container(Messages.RPT_IMPORT_GROUP_0), I_CmsReport.FORMAT_NOTE);
m_report.print(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_ARGUMENT_1,
name));
m_report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
m_cms.createGroup(name, description, Integer.parseInt(flags), parentgroupName);
m_report.println(
org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
I_CmsReport.FORMAT_OK);
} catch (CmsException exc) {
m_report.println(Messages.get().container(Messages.RPT_NOT_CREATED_0), I_CmsReport.FORMAT_OK);
}
}
} catch (Exception e) {
m_report.println(e);
CmsMessageContainer message = Messages.get().container(
Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_GROUP_1,
name);
if (LOG.isDebugEnabled()) {
LOG.debug(message.key(), e);
}
throw new CmsImportExportException(message, e);
}
}
/**
* Imports the OpenCms groups.<p>
*
* @throws CmsImportExportException if something goes wrong
*/
protected void importGroups() throws CmsImportExportException {
List groupNodes;
Element currentElement;
String name, description, flags, parentgroup;
try {
// getAll group nodes
groupNodes = m_docXml.selectNodes("//" + CmsImportExportManager.N_GROUPDATA);
// walk through all groups in manifest
for (int i = 0; i < groupNodes.size(); i++) {
currentElement = (Element)groupNodes.get(i);
name = CmsImport.getChildElementTextValue(currentElement, CmsImportExportManager.N_NAME);
name = OpenCms.getImportExportManager().translateGroup(name);
description = CmsImport.getChildElementTextValue(currentElement, CmsImportExportManager.N_DESCRIPTION);
flags = CmsImport.getChildElementTextValue(currentElement, CmsImportExportManager.N_FLAGS);
parentgroup = CmsImport.getChildElementTextValue(currentElement, CmsImportExportManager.N_PARENTGROUP);
if ((parentgroup != null) && (parentgroup.length() > 0)) {
parentgroup = OpenCms.getImportExportManager().translateGroup(parentgroup);
}
// import this group
importGroup(name, description, flags, parentgroup);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -