use of org.opencms.file.types.CmsResourceTypeImage 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.CmsResourceTypeImage in project opencms-core by alkacon.
the class CmsGalleryService method buildSingleSearchResultItem.
/**
* Builds a single search result list item for the client from a server-side search result.<p>
*
* @param cms the current CMS context
* @param sResult the server-side search result
* @param presetResult the preselected result
*
* @return the client side search result item
*
* @throws CmsException if something goes wrong
* @throws ParseException if date parsing fails
*/
private CmsResultItemBean buildSingleSearchResultItem(CmsObject cms, CmsGallerySearchResult sResult, CmsGallerySearchResult presetResult) throws CmsException, ParseException {
Locale wpLocale = getWorkplaceLocale();
CmsResultItemBean bean = new CmsResultItemBean();
if (sResult == presetResult) {
bean.setPreset(true);
}
bean.setReleasedAndNotExpired(sResult.isReleaseAndNotExpired(cms));
String path = sResult.getPath();
path = cms.getRequestContext().removeSiteRoot(path);
// resource path as id
bean.setPath(path);
// title
String rawTitle = CmsStringUtil.isEmptyOrWhitespaceOnly(sResult.getTitle()) ? CmsResource.getName(sResult.getPath()) : sResult.getTitle();
bean.setTitle(rawTitle);
bean.setRawTitle(rawTitle);
// resource type
bean.setType(sResult.getResourceType());
CmsResource resultResource = cms.readResource(new CmsUUID(sResult.getStructureId()), CmsResourceFilter.ONLY_VISIBLE_NO_DELETED);
bean.setBigIconClasses(CmsIconUtil.getIconClasses(CmsIconUtil.getDisplayType(cms, resultResource), path, false));
String detailType = CmsResourceIcon.getDefaultFileOrDetailType(cms, resultResource);
if (detailType != null) {
bean.setSmallIconClasses(CmsIconUtil.getIconClasses(detailType, null, true));
}
// structured id
bean.setClientId(sResult.getStructureId());
CmsVfsService.addLockInfo(cms, resultResource, bean);
String permalinkId = sResult.getStructureId().toString();
String permalink = CmsStringUtil.joinPaths(OpenCms.getSystemInfo().getOpenCmsContext(), CmsPermalinkResourceHandler.PERMALINK_HANDLER, permalinkId);
bean.setViewLink(permalink);
// set nice resource type name as subtitle
I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(sResult.getResourceType());
String resourceTypeDisplayName = CmsWorkplaceMessages.getResourceTypeName(wpLocale, type.getTypeName());
String description = sResult.getDescription();
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(description)) {
bean.setDescription(description);
bean.addAdditionalInfo(Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_RESULT_LABEL_DESCRIPTION_0), description);
if (sResult.getResourceType().equals(CmsResourceTypeFunctionConfig.TYPE_NAME)) {
bean.setSubTitle(description);
}
} else {
bean.setDescription(resourceTypeDisplayName);
}
bean.setUserLastModified(sResult.getUserLastModified());
Date lastModDate = sResult.getDateLastModified();
String formattedDate = lastModDate != null ? CmsDateUtil.getDateTime(lastModDate, DateFormat.MEDIUM, wpLocale) : "";
bean.setDateLastModified(formattedDate);
if (!type.getTypeName().equals(CmsResourceTypeImage.getStaticTypeName())) {
bean.addAdditionalInfo(Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_RESULT_LABEL_RESOURCE_TYPE_0), resourceTypeDisplayName);
}
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(sResult.getExcerpt())) {
bean.addAdditionalInfo(Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_RESULT_LABEL_EXCERPT_0), sResult.getExcerpt(), CmsListInfoBean.CSS_CLASS_MULTI_LINE);
}
if (type instanceof CmsResourceTypeImage) {
CmsProperty copyrightProp = cms.readPropertyObject(resultResource, CmsPropertyDefinition.PROPERTY_COPYRIGHT, false);
if (!copyrightProp.isNullProperty()) {
bean.addAdditionalInfo(Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_RESULT_LABEL_COPYRIGHT_0), copyrightProp.getValue());
}
CmsProperty imageDimensionProp = cms.readPropertyObject(resultResource, CmsPropertyDefinition.PROPERTY_IMAGE_SIZE, false);
if (!imageDimensionProp.isNullProperty()) {
String dimensions = imageDimensionProp.getValue();
dimensions = dimensions.substring(2).replace(",h:", " x ");
bean.setDimension(dimensions);
bean.addAdditionalInfo(Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_RESULT_LABEL_DIMENSION_0), dimensions);
}
}
if (type instanceof CmsResourceTypeXmlContent) {
CmsProperty elementModelProperty = cms.readPropertyObject(resultResource, CmsPropertyDefinition.PROPERTY_ELEMENT_MODEL, true);
if (!elementModelProperty.isNullProperty()) {
if (Boolean.valueOf(elementModelProperty.getValue()).booleanValue()) {
bean.setIsCopyModel(true);
}
}
}
bean.setResourceState(resultResource.getState());
bean.addAdditionalInfo(Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_RESULT_LABEL_SIZE_0), (sResult.getLength() / 1000) + " kb");
if (lastModDate != null) {
bean.addAdditionalInfo(Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_RESULT_LABEL_DATE_CHANGED_0), CmsDateUtil.getDate(lastModDate, DateFormat.SHORT, getWorkplaceLocale()));
}
if ((sResult.getDateExpired().getTime() != CmsResource.DATE_EXPIRED_DEFAULT) && !sResult.getDateExpired().equals(CmsSearchFieldMapping.getDefaultDateExpired())) {
bean.addAdditionalInfo(Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_RESULT_LABEL_DATE_EXPIRED_0), CmsDateUtil.getDate(sResult.getDateExpired(), DateFormat.SHORT, getWorkplaceLocale()));
}
bean.setNoEditReson(new CmsResourceUtil(cms, resultResource).getNoEditReason(OpenCms.getWorkplaceManager().getWorkplaceLocale(cms)));
bean.setMarkChangedState(true);
return bean;
}
use of org.opencms.file.types.CmsResourceTypeImage 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