📄 cmscontentcheck.java
字号:
while (j.hasNext()) {
I_CmsContentCheck plugin = (I_CmsContentCheck)j.next();
if (plugin.isActive()) {
try {
// process the content check
res = plugin.executeContentCheck(m_cms, res);
} catch (CmsException e) {
errorWarning = true;
m_report.println(Messages.get().container(Messages.RPT_EMPTY_0), I_CmsReport.FORMAT_DEFAULT);
m_report.print(Messages.get().container(
Messages.RPT_CONTENT_PROCESS_ERROR_2,
plugin.getName(),
e), I_CmsReport.FORMAT_ERROR);
}
}
}
// check if there are some errors
List errors = res.getErrors();
if (errors != null && errors.size() > 0) {
errorWarning = true;
m_report.println(Messages.get().container(Messages.RPT_EMPTY_0), I_CmsReport.FORMAT_DEFAULT);
m_report.println(
Messages.get().container(Messages.RPT_CONTENT_PROCESS_ERROR_0),
I_CmsReport.FORMAT_ERROR);
Iterator k = errors.iterator();
while (k.hasNext()) {
String error = (String)k.next();
m_report.println(
Messages.get().container(Messages.RPT_CONTENT_PROCESS_ERROR_1, error),
I_CmsReport.FORMAT_ERROR);
}
}
// check if there are some warnings
List warnings = res.getWarnings();
if (warnings != null && warnings.size() > 0) {
errorWarning = true;
m_report.println(Messages.get().container(Messages.RPT_EMPTY_0), I_CmsReport.FORMAT_DEFAULT);
m_report.println(
Messages.get().container(Messages.RPT_CONTENT_PROCESS_WARNING_0),
I_CmsReport.FORMAT_WARNING);
Iterator k = warnings.iterator();
while (k.hasNext()) {
String warning = (String)k.next();
m_report.println(
Messages.get().container(Messages.RPT_CONTENT_PROCESS_WARNING_1, warning),
I_CmsReport.FORMAT_WARNING);
}
}
// store the updated CmsContentCheckResource
m_resources.put(resourceName, res);
if (!errorWarning) {
m_report.println(
org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
I_CmsReport.FORMAT_OK);
} else {
// there was an error or warning, so store the CmsContentCheckResource
// in the results
m_result.addResult(res);
}
}
m_report.print(
org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0),
I_CmsReport.FORMAT_HEADLINE);
m_report.println(Messages.get().container(Messages.RPT_CONTENT_PROCESS_END_0), I_CmsReport.FORMAT_HEADLINE);
m_report.println(Messages.get().container(Messages.RPT_CONTENT_CHECK_END_0), I_CmsReport.FORMAT_HEADLINE);
}
/**
*
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append("CmsContentCheck Paths=[");
for (int i = 0; i < m_paths.size(); i++) {
String path = (String)m_paths.get(i);
buf.append(path);
if (i < m_paths.size() - 1) {
buf.append(",");
}
}
buf.append("] Plugins=[");
for (int i = 0; i < m_plugins.size(); i++) {
I_CmsContentCheck plugin = (I_CmsContentCheck)m_plugins.get(i);
buf.append(plugin.getName());
buf.append(" (");
buf.append(plugin.isActive());
buf.append(")");
if (i < m_plugins.size() - 1) {
buf.append(",");
}
}
buf.append("]");
return buf.toString();
}
/**
* Collects all resources required for the content checks and stores them in a Set.<p>
*
* The collection of resources is build based on the vfs paths stored in this object.
* To prevent that resources are collected multiple times (in case of overlapping vfs paths),
* the results will be stored as a map.
*
* @param cms the CmsObject
* @return map of CmsContentCheckResources
*/
private SortedMap collectResources(CmsObject cms) {
SortedMap collectedResources = new TreeMap();
// get all vfs paths and extract the resources from there
Iterator i = CmsFileUtil.removeRedundancies(m_paths).iterator();
while (i.hasNext()) {
String path = (String)i.next();
m_report.print(
Messages.get().container(Messages.RPT_EXTRACT_FROM_PATH_BEGIN_1, path),
I_CmsReport.FORMAT_HEADLINE);
m_report.println(
org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0),
I_CmsReport.FORMAT_HEADLINE);
try {
List resources = cms.readResources(path, CmsResourceFilter.IGNORE_EXPIRATION, true);
// get the single resources and store them
Iterator j = resources.iterator();
while (j.hasNext()) {
CmsResource res = (CmsResource)j.next();
// m_report.print(
// Messages.get().container(Messages.RPT_EXTRACT_FROM_PATH_1, cms.getSitePath(res)),
// I_CmsReport.FORMAT_DEFAULT);
// m_report.print(
// org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0),
// I_CmsReport.FORMAT_DEFAULT);
// create a CmsContentCheckResource for each resource
CmsContentCheckResource contentCheckRes = new CmsContentCheckResource(res);
collectedResources.put(contentCheckRes.getResourceName(), contentCheckRes);
// m_report.println(
// org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
// I_CmsReport.FORMAT_OK);
}
} catch (CmsException e) {
m_report.println(
Messages.get().container(Messages.RPT_EXTRACT_FROM_PATH_ERROR_2, path, e),
I_CmsReport.FORMAT_ERROR);
}
m_report.print(
org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0),
I_CmsReport.FORMAT_HEADLINE);
m_report.println(
Messages.get().container(Messages.RPT_EXTRACT_FROM_PATH_END_0),
I_CmsReport.FORMAT_HEADLINE);
}
return collectedResources;
}
/**
* Initializes the CmsContent check and reads all available plugins.<p>
*/
private void init() throws CmsException {
// first get all installed plugins
// plugins are subfolders of the "/plugin/" folder with a template
// property holdding the name of the plugin class
List resources = m_cms.readResourcesWithProperty(VFS_PATH_PLUGIN_FOLDER, CmsToolManager.HANDLERCLASS_PROPERTY);
Iterator i = resources.iterator();
while (i.hasNext()) {
CmsResource res = (CmsResource)i.next();
// ony check folders
if (res.isFolder()) {
String classname = m_cms.readPropertyObject(
res.getRootPath(),
CmsToolManager.HANDLERCLASS_PROPERTY,
false).getValue();
try {
Object objectInstance = Class.forName(classname).newInstance();
if (objectInstance instanceof I_CmsContentCheck) {
I_CmsContentCheck plugin = (I_CmsContentCheck)objectInstance;
plugin.init(m_cms);
// store the plugin instance
m_plugins.add(plugin);
LOG.info(Messages.get().getBundle().key(Messages.LOG_CREATE_PLUGIN_1, classname));
} else {
LOG.warn(Messages.get().getBundle().key(Messages.LOG_CANNOT_CREATE_PLUGIN_1, classname));
}
} catch (Throwable t) {
LOG.error(Messages.get().getBundle().key(Messages.LOG_CANNOT_CREATE_PLUGIN_2, classname, t));
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -