use of org.opencms.file.types.CmsResourceTypePointer in project opencms-core by alkacon.
the class CmsResourceComparisonDialog method displayDialog.
/**
* Display method for two list dialogs.<p>
*
* @throws Exception if something goes wrong
*/
public void displayDialog() throws Exception {
CmsResourceInfoDialog fileInfo = new CmsResourceInfoDialog(getJsp()) {
@Override
protected String defaultActionHtmlEnd() {
return "";
}
};
fileInfo.displayDialog(true);
if (fileInfo.isForwarded()) {
return;
}
CmsPropertyComparisonList propertyDiff = new CmsPropertyComparisonList(getJsp());
CmsAttributeComparisonList attributeDiff = new CmsAttributeComparisonList(getJsp());
List<A_CmsListDialog> lists = new ArrayList<A_CmsListDialog>();
lists.add(attributeDiff);
I_CmsResourceType resourceType = OpenCms.getResourceManager().getResourceType(propertyDiff.getResourceType());
if ((resourceType instanceof CmsResourceTypeXmlContent) || (resourceType instanceof CmsResourceTypeXmlPage)) {
// display attributes, properties and compared elements
CmsElementComparisonList contentDiff = new CmsElementComparisonList(getJsp());
// get the content of the resource1 and resource2
byte[] content1 = readFile(getCms(), propertyDiff.getResource1().getStructureId(), getParamVersion1()).getContents();
byte[] content2 = readFile(getCms(), propertyDiff.getResource2().getStructureId(), getParamVersion2()).getContents();
// display the content comparison only if both files has contents
if ((content1.length > 0) && (content2.length > 0)) {
lists.add(contentDiff);
}
lists.add(propertyDiff);
CmsMultiListDialog threeLists = new CmsMultiListDialog(lists);
// perform the active list actions
threeLists.displayDialog(true);
// write the dialog just if no list has been forwarded
if (threeLists.isForwarded()) {
return;
}
fileInfo.writeDialog();
threeLists.writeDialog();
} else if (resourceType instanceof CmsResourceTypeImage) {
// display attributes, properties and images
lists.add(propertyDiff);
CmsMultiListDialog twoLists = new CmsMultiListDialog(lists) {
/**
* @see org.opencms.workplace.list.CmsMultiListDialog#defaultActionHtmlEnd()
*/
@Override
public String defaultActionHtmlEnd() {
return "";
}
};
twoLists.displayDialog(true);
if (twoLists.isForwarded()) {
return;
}
CmsImageComparisonDialog images = new CmsImageComparisonDialog(getJsp());
fileInfo.writeDialog();
twoLists.writeDialog();
// this is very dangerous
// it is possible that here a forward is tried, what should not be sence we already wrote to the output stream.
// CmsImageComparisonDialog should implement isForwarded, writeDialog and displayDialog(boolean) methods
images.displayDialog();
} else if (resourceType instanceof CmsResourceTypePointer) {
lists.add(propertyDiff);
CmsMultiListDialog twoLists = new CmsMultiListDialog(lists) {
/**
* @see org.opencms.workplace.list.CmsMultiListDialog#defaultActionHtmlEnd()
*/
@Override
public String defaultActionHtmlEnd() {
return "";
}
};
twoLists.displayDialog(true);
if (twoLists.isForwarded()) {
return;
}
CmsPointerComparisonDialog pointers = new CmsPointerComparisonDialog(getJsp());
fileInfo.writeDialog();
twoLists.writeDialog();
// same as for CmsImageComparisonDialog
pointers.displayDialog();
} else if (propertyDiff.getResource1().isFile()) {
// display attributes and properties
lists.add(propertyDiff);
CmsMultiListDialog twoLists = new CmsMultiListDialog(lists);
twoLists.displayDialog(true);
if (twoLists.isForwarded()) {
return;
}
CmsResource resource1 = propertyDiff.getResource1();
CmsResource resource2 = propertyDiff.getResource2();
String path1 = resource1.getRootPath();
String path2 = resource2.getRootPath();
byte[] content1 = readFile(getCms(), resource1.getStructureId(), getParamVersion1()).getContents();
byte[] content2 = readFile(getCms(), resource2.getStructureId(), getParamVersion2()).getContents();
String originalSource = null;
String copySource = null;
I_CmsTextExtractor textExtractor = null;
// only if both files have contents
if ((content1.length > 0) && (content2.length > 0)) {
if (path1.endsWith(".pdf") && path2.endsWith(".pdf")) {
textExtractor = CmsExtractorPdf.getExtractor();
} else if (path1.endsWith(".doc") && path2.endsWith(".doc")) {
textExtractor = CmsExtractorMsOfficeOLE2.getExtractor();
} else if (path1.endsWith(".xls") && path2.endsWith(".xls")) {
textExtractor = CmsExtractorMsOfficeOLE2.getExtractor();
} else if (path1.endsWith(".rtf") && path2.endsWith(".rtf")) {
textExtractor = CmsExtractorRtf.getExtractor();
} else if (path1.endsWith(".ppt") && path2.endsWith(".ppt")) {
textExtractor = CmsExtractorMsOfficeOLE2.getExtractor();
}
}
if (textExtractor != null) {
try {
// extract the content
originalSource = textExtractor.extractText(content1).getContent();
copySource = textExtractor.extractText(content2).getContent();
} catch (Exception e) {
// something goes wrong on extracting content
// set the content to null, so the content dialog will not be shown
originalSource = null;
copySource = null;
LOG.error(e.getMessage(), e);
}
} else if ((resourceType instanceof CmsResourceTypePlain) || (resourceType instanceof CmsResourceTypeJsp)) {
originalSource = new String(content1);
copySource = new String(content2);
}
fileInfo.writeDialog();
twoLists.writeDialog();
if (CmsStringUtil.isNotEmpty(originalSource) && CmsStringUtil.isNotEmpty(copySource)) {
m_differenceDialog.setCopySource(copySource);
m_differenceDialog.setOriginalSource(originalSource);
// same as for CmsImageComparisonDialog
m_differenceDialog.displayDialog();
}
} else {
// display attributes and properties
lists.add(propertyDiff);
CmsMultiListDialog twoLists = new CmsMultiListDialog(lists);
twoLists.displayDialog(true);
if (twoLists.isForwarded()) {
return;
}
fileInfo.writeDialog();
twoLists.writeDialog();
}
}
use of org.opencms.file.types.CmsResourceTypePointer in project opencms-core by alkacon.
the class CmsTextDiff method diff.
/**
* @see org.opencms.ui.dialogs.history.diff.I_CmsDiffProvider#diff(org.opencms.file.CmsObject, org.opencms.gwt.shared.CmsHistoryResourceBean, org.opencms.gwt.shared.CmsHistoryResourceBean)
*/
public Optional<Component> diff(CmsObject cms, CmsHistoryResourceBean v1, CmsHistoryResourceBean v2) throws CmsException {
CmsResource resource1 = A_CmsAttributeDiff.readResource(cms, v1);
String encoding = CmsLocaleManager.getResourceEncoding(cms, resource1);
I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(resource1);
if ((type instanceof CmsResourceTypeXmlContent) || (type instanceof CmsResourceTypePlain) || (type instanceof CmsResourceTypeJsp) || (type instanceof CmsResourceTypeXmlPage) || (type instanceof CmsResourceTypePointer) || (type instanceof CmsResourceTypeBinary)) {
CmsResource resource2 = A_CmsAttributeDiff.readResource(cms, v2);
String path1 = resource1.getRootPath();
String path2 = resource2.getRootPath();
CmsFile file1 = cms.readFile(resource1);
CmsFile file2 = cms.readFile(resource2);
byte[] content1 = file1.getContents();
byte[] content2 = file2.getContents();
String originalSource = null;
String copySource = null;
I_CmsTextExtractor textExtractor = null;
// only if both files have contents
if ((content1.length > 0) && (content2.length > 0)) {
if (path1.endsWith(".pdf") && path2.endsWith(".pdf")) {
textExtractor = CmsExtractorPdf.getExtractor();
} else if (path1.endsWith(".doc") && path2.endsWith(".doc")) {
textExtractor = CmsExtractorMsOfficeOLE2.getExtractor();
} else if (path1.endsWith(".xls") && path2.endsWith(".xls")) {
textExtractor = CmsExtractorMsOfficeOLE2.getExtractor();
} else if (path1.endsWith(".rtf") && path2.endsWith(".rtf")) {
textExtractor = CmsExtractorRtf.getExtractor();
} else if (path1.endsWith(".ppt") && path2.endsWith(".ppt")) {
textExtractor = CmsExtractorMsOfficeOLE2.getExtractor();
}
}
if (textExtractor != null) {
try {
// extract the content
originalSource = textExtractor.extractText(content1).getContent();
copySource = textExtractor.extractText(content2).getContent();
} catch (Exception e) {
// something goes wrong on extracting content
// set the content to null, so the content dialog will not be shown
originalSource = null;
copySource = null;
LOG.error(e.getMessage(), e);
}
} else if ((type instanceof CmsResourceTypePlain) || (type instanceof CmsResourceTypeJsp) || (type instanceof CmsResourceTypePointer)) {
try {
originalSource = new String(content1, encoding);
copySource = new String(content2, encoding);
} catch (UnsupportedEncodingException e) {
LOG.error(e.getLocalizedMessage(), e);
}
}
if ((copySource == null) || (originalSource == null)) {
return Optional.absent();
}
try {
CmsTextDiffPanel diffPanel = new CmsTextDiffPanel(originalSource, copySource, false, true);
diffPanel.setWidth("100%");
Panel panel = new Panel(CmsVaadinUtils.getMessageText(Messages.GUI_HISTORY_DIALOG_TEXT_COMPARISON_CAPTION_0));
panel.setWidth("100%");
VerticalLayout vl = new VerticalLayout();
vl.setMargin(true);
vl.addComponent(diffPanel);
panel.setContent(vl);
return Optional.<Component>fromNullable(panel);
} catch (Exception e) {
LOG.error(e.getLocalizedMessage(), e);
return Optional.absent();
}
} else {
return Optional.absent();
}
}
use of org.opencms.file.types.CmsResourceTypePointer in project opencms-core by alkacon.
the class CmsStandardVisibilityCheck method getSingleVisibility.
/**
* @see org.opencms.ui.contextmenu.A_CmsSimpleVisibilityCheck#getSingleVisibility(org.opencms.file.CmsObject, org.opencms.file.CmsResource)
*/
@Override
public CmsMenuItemVisibilityMode getSingleVisibility(CmsObject cms, CmsResource resource) {
boolean prioritize = false;
String inActiveKey = null;
if (resource != null) {
if (flag(roleeditor) && !OpenCms.getRoleManager().hasRoleForResource(cms, CmsRole.EDITOR, resource)) {
return VISIBILITY_INVISIBLE;
}
if (flag(rolewpuser) && !OpenCms.getRoleManager().hasRoleForResource(cms, CmsRole.WORKPLACE_USER, resource)) {
return VISIBILITY_INVISIBLE;
}
if (flag(rolevfsmanager)) {
if (!OpenCms.getRoleManager().hasRoleForResource(cms, CmsRole.VFS_MANAGER, resource)) {
return VISIBILITY_INVISIBLE;
}
}
if (flag(rolerootadmin) && !OpenCms.getRoleManager().hasRoleForResource(cms, CmsRole.ROOT_ADMIN, resource)) {
return VISIBILITY_INVISIBLE;
}
} else {
if (flag(roleeditor) && !OpenCms.getRoleManager().hasRole(cms, CmsRole.EDITOR)) {
return VISIBILITY_INVISIBLE;
}
if (flag(rolewpuser) && !OpenCms.getRoleManager().hasRole(cms, CmsRole.WORKPLACE_USER)) {
return VISIBILITY_INVISIBLE;
}
}
if (flag(notonline) && cms.getRequestContext().getCurrentProject().isOnlineProject()) {
return VISIBILITY_INVISIBLE;
}
if ((resource != null)) {
CmsResourceUtil resUtil = new CmsResourceUtil(cms, resource);
if (flag(file) && !resource.isFile()) {
return VISIBILITY_INVISIBLE;
}
if (flag(defaultfile)) {
if (!resource.isFile()) {
return VISIBILITY_INVISIBLE;
}
try {
CmsResource parentFolder = cms.readParentFolder(resource.getStructureId());
if (parentFolder == null) {
return VISIBILITY_INVISIBLE;
}
CmsResource defaultFile = cms.readDefaultFile(parentFolder, CmsResourceFilter.IGNORE_EXPIRATION);
if ((defaultFile == null) || !(defaultFile.getStructureId().equals(resource.getStructureId()))) {
return VISIBILITY_INVISIBLE;
}
} catch (CmsException e) {
LOG.error(e.getLocalizedMessage(), e);
return VISIBILITY_INVISIBLE;
}
}
if (flag(folder) && resource.isFile()) {
return VISIBILITY_INVISIBLE;
}
if (flag(pagefolder)) {
if (!resource.isFolder()) {
return VISIBILITY_INVISIBLE;
}
try {
CmsResource defaultFile;
defaultFile = cms.readDefaultFile("" + resource.getStructureId());
if ((defaultFile == null) || !CmsResourceTypeXmlContainerPage.isContainerPage(defaultFile)) {
return VISIBILITY_INVISIBLE;
}
} catch (CmsException e) {
LOG.warn(e.getLocalizedMessage(), e);
return VISIBILITY_INVISIBLE;
}
}
if (flag(pointer) && !OpenCms.getResourceManager().matchResourceType(CmsResourceTypePointer.getStaticTypeName(), resource.getTypeId())) {
return VISIBILITY_INVISIBLE;
}
if (flag(notpointer) && OpenCms.getResourceManager().matchResourceType(CmsResourceTypePointer.getStaticTypeName(), resource.getTypeId())) {
return VISIBILITY_INVISIBLE;
}
if (flag(replacable)) {
I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(resource);
boolean usesDumpLoader = type.getLoaderId() == CmsDumpLoader.RESOURCE_LOADER_ID;
if (!usesDumpLoader && !(type instanceof CmsResourceTypeImage)) {
return VISIBILITY_INVISIBLE;
}
}
if (flag(hassourcecodeeditor)) {
I_CmsResourceType type = resUtil.getResourceType();
boolean hasSourcecodeEditor = (type instanceof CmsResourceTypeXmlContent) || (type instanceof CmsResourceTypeXmlPage) || (type instanceof CmsResourceTypePointer) || OpenCms.getResourceManager().matchResourceType(BundleType.PROPERTY.toString(), resource.getTypeId());
if (!hasSourcecodeEditor) {
return VISIBILITY_INVISIBLE;
}
}
if (flag(unlocked)) {
CmsLock lock = resUtil.getLock();
if (!lock.isUnlocked()) {
return VISIBILITY_INVISIBLE;
}
prioritize = true;
}
if (flag(otherlock)) {
CmsLock lock = resUtil.getLock();
if (lock.isUnlocked() || lock.isOwnedBy(cms.getRequestContext().getCurrentUser())) {
return VISIBILITY_INVISIBLE;
}
prioritize = true;
}
if (flag(nootherlock)) {
CmsLock lock = resUtil.getLock();
if (!lock.isUnlocked() && !lock.isOwnedBy(cms.getRequestContext().getCurrentUser())) {
return VISIBILITY_INVISIBLE;
}
}
if (flag(mylock)) {
CmsLock lock = resUtil.getLock();
if (!lock.isOwnedBy(cms.getRequestContext().getCurrentUser())) {
return VISIBILITY_INVISIBLE;
}
prioritize = true;
}
if (flag(noinheritedlock)) {
CmsLock lock = resUtil.getLock();
if (lock.isInherited()) {
return VISIBILITY_INVISIBLE;
}
}
if (flag(notunchangedfile) && resource.isFile() && resUtil.getResource().getState().isUnchanged()) {
inActiveKey = Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_UNCHANGED_0;
}
if (flag(notnew) && (inActiveKey == null) && resource.getState().isNew()) {
inActiveKey = Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_NEW_UNCHANGED_0;
}
if (flag(xmlunmarshal)) {
if (CmsResourceTypeXmlContent.isXmlContent(resource)) {
try {
CmsXmlContentFactory.unmarshal(cms, cms.readFile(resource));
} catch (Exception e) {
LOG.error(e.getLocalizedMessage(), e);
return VISIBILITY_INVISIBLE;
}
}
}
if (flag(haseditor) && (OpenCms.getWorkplaceAppManager().getEditorForResource(cms, resource, false) == null)) {
return VISIBILITY_INVISIBLE;
}
if (flag(inproject) && (!resUtil.isInsideProject() || resUtil.getProjectState().isLockedForPublishing())) {
return VISIBILITY_INVISIBLE;
}
if (flag(notinproject) && (resUtil.isInsideProject() || resUtil.getProjectState().isLockedForPublishing())) {
return VISIBILITY_INVISIBLE;
}
if (flag(publishpermission)) {
try {
if (!cms.hasPermissions(resource, CmsPermissionSet.ACCESS_DIRECT_PUBLISH, false, CmsResourceFilter.ALL)) {
return VISIBILITY_INVISIBLE;
}
} catch (CmsException e) {
LOG.error(e.getLocalizedMessage(), e);
}
}
if (flag(controlpermission)) {
try {
if (!cms.hasPermissions(resource, CmsPermissionSet.ACCESS_CONTROL, false, CmsResourceFilter.IGNORE_EXPIRATION)) {
return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
}
} catch (CmsException e) {
LOG.warn("Error checking context menu entry permissions", e);
return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
}
}
if (flag(writepermisssion)) {
try {
if (!resUtil.getLock().isLockableBy(cms.getRequestContext().getCurrentUser())) {
// set invisible if not lockable
return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
}
if (!resUtil.isEditable() || !cms.hasPermissions(resUtil.getResource(), CmsPermissionSet.ACCESS_WRITE, false, CmsResourceFilter.ALL)) {
inActiveKey = Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_PERM_WRITE_0;
}
} catch (CmsException e) {
LOG.debug("Error checking context menu entry permissions.", e);
return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
}
}
if (flag(notdeleted) && (inActiveKey == null) && resUtil.getResource().getState().isDeleted()) {
inActiveKey = Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_DELETED_0;
}
if (flag(deleted) && !resource.getState().isDeleted()) {
return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
}
} else {
return VISIBILITY_INVISIBLE;
}
if (inActiveKey != null) {
return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE.addMessageKey(inActiveKey).prioritize(prioritize);
}
return VISIBILITY_ACTIVE.prioritize(prioritize);
}
Aggregations