Skip to content

Commit

Permalink
Fixing null-pointer issue when generating context menu for empty
Browse files Browse the repository at this point in the history
XML-contents.
  • Loading branch information
tHerrmann committed Aug 8, 2019
1 parent 922de00 commit 7ffc8b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
8 changes: 6 additions & 2 deletions src/org/opencms/ui/apps/CmsWorkplaceAppManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,12 @@ public I_CmsEditor getEditorForResource(CmsResource resource, boolean plainText)

List<I_CmsEditor> editors = new ArrayList<I_CmsEditor>();
for (int i = 0; i < EDITORS.length; i++) {
if (EDITORS[i].matchesResource(resource, plainText)) {
editors.add(EDITORS[i]);
try {
if (EDITORS[i].matchesResource(resource, plainText)) {
editors.add(EDITORS[i]);
}
} catch (Exception e) {
LOG.error(e.getLocalizedMessage(), e);
}
}
I_CmsEditor result = null;
Expand Down
31 changes: 16 additions & 15 deletions src/org/opencms/workplace/editors/CmsWorkplaceEditorManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

package org.opencms.workplace.editors;

import org.opencms.ade.contenteditor.CmsContentTypeVisitor;
import org.opencms.cache.CmsVfsMemoryObjectCache;
import org.opencms.configuration.CmsParameterConfiguration;
import org.opencms.db.CmsUserSettings;
Expand Down Expand Up @@ -148,32 +147,34 @@ public CmsWorkplaceEditorManager(CmsObject cms) {
* @param resource the resource to check
*
* @return false if for some fields the new Acacia widgets are not available
*
* @throws CmsException if something goes wrong
*/
public static boolean checkAcaciaEditorAvailable(CmsObject cms, CmsResource resource) {

boolean result = false;
if (resource == null) {
try {
// we want a stack trace
throw new Exception();
} catch (Exception e) {
LOG.error("Can't check widget availability because resource is null!", e);
}
return false;
}
try {
CmsFile file = (resource instanceof CmsFile) ? (CmsFile)resource : cms.readFile(resource);
CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms, file);
if (content.getContentDefinition().getContentHandler().isAcaciaEditorDisabled()) {
return false;
} else {
try {
CmsFile file = (resource instanceof CmsFile) ? (CmsFile)resource : cms.readFile(resource);
if (file.getContents().length > 0) {
CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms, file);
if (!content.getContentDefinition().getContentHandler().isAcaciaEditorDisabled()) {
result = true;
}
}
} catch (CmsException e) {
LOG.info(
"error thrown in checkAcaciaEditorAvailable for " + resource + " : " + e.getLocalizedMessage(),
e);
result = true;
}
CmsContentTypeVisitor visitor = new CmsContentTypeVisitor(cms, file, cms.getRequestContext().getLocale());
return visitor.isEditorCompatible(content.getContentDefinition());
} catch (CmsException e) {
LOG.info("error thrown in checkAcaciaEditorAvailable for " + resource + " : " + e.getLocalizedMessage(), e);
return true;
}
return result;
}

/**
Expand Down

0 comments on commit 7ffc8b1

Please sign in to comment.