Search in sources :

Example 1 with CmsResourceUtil

use of org.opencms.workplace.explorer.CmsResourceUtil in project opencms-core by alkacon.

the class CmsFileExplorer method updateResourceInTree.

/**
 * Updates the give tree item.<p>
 *
 * @param cms the cms context
 * @param id the item id
 */
public void updateResourceInTree(CmsObject cms, CmsUUID id) {
    try {
        CmsResource resource = cms.readResource(id, CmsResourceFilter.IGNORE_EXPIRATION);
        if (resource.isFile()) {
            return;
        }
        // ensuring to only add items belonging to the current site
        if (!resource.getRootPath().startsWith(cms.getRequestContext().getSiteRoot())) {
            m_treeContainer.removeItemRecursively(id);
            return;
        }
        CmsResource parent = cms.readParentFolder(id);
        CmsUUID parentId = null;
        if (parent != null) {
            parentId = parent.getStructureId();
        } else {
            LOG.debug("Parent for resource '" + resource.getRootPath() + "' is null");
        }
        Item resourceItem = m_treeContainer.getItem(id);
        if (resourceItem != null) {
            // use the root path as name in case of the root item
            String resName = parentId == null ? resource.getRootPath() : resource.getName();
            resourceItem.getItemProperty(CmsResourceTableProperty.PROPERTY_RESOURCE_NAME).setValue(resName);
            CmsResourceUtil resUtil = new CmsResourceUtil(cms, resource);
            String iconHTML = CmsResourceIcon.getTreeCaptionHTML(resName, resUtil, null, false);
            resourceItem.getItemProperty(CmsResourceTableProperty.PROPERTY_TREE_CAPTION).setValue(iconHTML);
            resourceItem.getItemProperty(CmsResourceTableProperty.PROPERTY_STATE).setValue(resource.getState());
            if (parentId != null) {
                m_treeContainer.setParent(resource.getStructureId(), parentId);
            }
        } else {
            addTreeItem(cms, resource, parentId, false, m_treeContainer);
        }
        m_fileTree.markAsDirty();
    } catch (CmsVfsResourceNotFoundException e) {
        m_treeContainer.removeItemRecursively(id);
        LOG.debug(e.getLocalizedMessage(), e);
    } catch (CmsException e) {
        CmsErrorDialog.showErrorDialog(e);
        LOG.error(e.getLocalizedMessage(), e);
    }
}
Also used : Item(com.vaadin.v7.data.Item) CmsVfsResourceNotFoundException(org.opencms.file.CmsVfsResourceNotFoundException) CmsResourceUtil(org.opencms.workplace.explorer.CmsResourceUtil) CmsResource(org.opencms.file.CmsResource) CmsException(org.opencms.main.CmsException) CmsUUID(org.opencms.util.CmsUUID)

Example 2 with CmsResourceUtil

use of org.opencms.workplace.explorer.CmsResourceUtil in project opencms-core by alkacon.

the class CmsResourceTable method fillItemDefault.

/**
 * Static helper method to initialize the 'standard' properties of a data item from a given resource.<p>
 * @param resourceItem the resource item to fill
 * @param cms the CMS context
 * @param resource the resource
 * @param locale the locale
 */
public static void fillItemDefault(Item resourceItem, CmsObject cms, CmsResource resource, Locale locale) {
    if (resource == null) {
        LOG.error("Error rendering item for 'null' resource");
        return;
    }
    if (resourceItem == null) {
        LOG.error("Error rendering 'null' item for resource " + resource.getRootPath());
        return;
    }
    if (cms == null) {
        cms = A_CmsUI.getCmsObject();
        LOG.warn("CmsObject was 'null', using thread local CmsObject");
    }
    CmsResourceUtil resUtil = new CmsResourceUtil(cms, resource);
    Map<String, CmsProperty> resourceProps = null;
    try {
        List<CmsProperty> props = cms.readPropertyObjects(resource, false);
        resourceProps = new HashMap<String, CmsProperty>();
        for (CmsProperty prop : props) {
            resourceProps.put(prop.getName(), prop);
        }
    } catch (CmsException e1) {
        LOG.debug("Unable to read properties for resource '" + resource.getRootPath() + "'.", e1);
    }
    I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(resource);
    if (resourceItem.getItemProperty(PROPERTY_TYPE_ICON) != null) {
        resourceItem.getItemProperty(PROPERTY_TYPE_ICON).setValue(new CmsResourceIcon(resUtil, resource.getState(), true));
    }
    if (resourceItem.getItemProperty(PROPERTY_PROJECT) != null) {
        Label projectFlag = null;
        switch(resUtil.getProjectState().getMode()) {
            case 1:
                projectFlag = new Label(new CmsCssIcon(OpenCmsTheme.ICON_PROJECT_CURRENT).getHtml(resUtil.getLockedInProjectName()), ContentMode.HTML);
                break;
            case 2:
                projectFlag = new Label(new CmsCssIcon(OpenCmsTheme.ICON_PROJECT_OTHER).getHtml(resUtil.getLockedInProjectName()), ContentMode.HTML);
                break;
            case 5:
                projectFlag = new Label(new CmsCssIcon(OpenCmsTheme.ICON_PUBLISH).getHtml(resUtil.getLockedInProjectName()), ContentMode.HTML);
                break;
            default:
        }
        resourceItem.getItemProperty(PROPERTY_PROJECT).setValue(projectFlag);
    }
    if (resourceItem.getItemProperty(PROPERTY_INSIDE_PROJECT) != null) {
        resourceItem.getItemProperty(PROPERTY_INSIDE_PROJECT).setValue(Boolean.valueOf(resUtil.isInsideProject()));
    }
    if (resourceItem.getItemProperty(PROPERTY_RELEASED_NOT_EXPIRED) != null) {
        resourceItem.getItemProperty(PROPERTY_RELEASED_NOT_EXPIRED).setValue(Boolean.valueOf(resUtil.isReleasedAndNotExpired()));
    }
    if (resourceItem.getItemProperty(PROPERTY_RESOURCE_NAME) != null) {
        resourceItem.getItemProperty(PROPERTY_RESOURCE_NAME).setValue(resource.getName());
    }
    if (resourceItem.getItemProperty(PROPERTY_SITE_PATH) != null) {
        resourceItem.getItemProperty(PROPERTY_SITE_PATH).setValue(cms.getSitePath(resource));
    }
    if ((resourceItem.getItemProperty(PROPERTY_TITLE) != null) && (resourceProps != null)) {
        resourceItem.getItemProperty(PROPERTY_TITLE).setValue(resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_TITLE) ? resourceProps.get(CmsPropertyDefinition.PROPERTY_TITLE).getValue() : "");
    }
    boolean inNavigation = false;
    if ((resourceItem.getItemProperty(PROPERTY_NAVIGATION_TEXT) != null) && (resourceProps != null)) {
        resourceItem.getItemProperty(PROPERTY_NAVIGATION_TEXT).setValue(resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_NAVTEXT) ? resourceProps.get(CmsPropertyDefinition.PROPERTY_NAVTEXT).getValue() : "");
        inNavigation = resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_NAVTEXT);
    }
    if ((resourceItem.getItemProperty(PROPERTY_NAVIGATION_POSITION) != null) && (resourceProps != null)) {
        try {
            Float navPos = resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_NAVPOS) ? Float.valueOf(resourceProps.get(CmsPropertyDefinition.PROPERTY_NAVPOS).getValue()) : (inNavigation ? Float.valueOf(Float.MAX_VALUE) : null);
            resourceItem.getItemProperty(PROPERTY_NAVIGATION_POSITION).setValue(navPos);
            inNavigation = navPos != null;
        } catch (Exception e) {
            LOG.debug("Error evaluating navPos property", e);
        }
    }
    if (resourceItem.getItemProperty(PROPERTY_IN_NAVIGATION) != null) {
        if (inNavigation && (resourceProps != null) && resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_NAVINFO) && CmsClientSitemapEntry.HIDDEN_NAVIGATION_ENTRY.equals(resourceProps.get(CmsPropertyDefinition.PROPERTY_NAVINFO).getValue())) {
            inNavigation = false;
        }
        resourceItem.getItemProperty(PROPERTY_IN_NAVIGATION).setValue(Boolean.valueOf(inNavigation));
    }
    if ((resourceItem.getItemProperty(PROPERTY_COPYRIGHT) != null) && (resourceProps != null)) {
        resourceItem.getItemProperty(PROPERTY_COPYRIGHT).setValue(resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_COPYRIGHT) ? resourceProps.get(CmsPropertyDefinition.PROPERTY_COPYRIGHT).getValue() : "");
    }
    if ((resourceItem.getItemProperty(PROPERTY_CACHE) != null) && (resourceProps != null)) {
        resourceItem.getItemProperty(PROPERTY_CACHE).setValue(resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_CACHE) ? resourceProps.get(CmsPropertyDefinition.PROPERTY_CACHE).getValue() : "");
    }
    if (resourceItem.getItemProperty(PROPERTY_RESOURCE_TYPE) != null) {
        resourceItem.getItemProperty(PROPERTY_RESOURCE_TYPE).setValue(CmsWorkplaceMessages.getResourceTypeName(locale, type.getTypeName()));
    }
    if (resourceItem.getItemProperty(PROPERTY_INTERNAL_RESOURCE_TYPE) != null) {
        resourceItem.getItemProperty(PROPERTY_INTERNAL_RESOURCE_TYPE).setValue(type.getTypeName());
    }
    if (resourceItem.getItemProperty(PROPERTY_IS_FOLDER) != null) {
        resourceItem.getItemProperty(PROPERTY_IS_FOLDER).setValue(Boolean.valueOf(resource.isFolder()));
    }
    if (resourceItem.getItemProperty(PROPERTY_SIZE) != null) {
        if (resource.isFile()) {
            resourceItem.getItemProperty(PROPERTY_SIZE).setValue(Integer.valueOf(resource.getLength()));
        }
    }
    if (resourceItem.getItemProperty(PROPERTY_PERMISSIONS) != null) {
        resourceItem.getItemProperty(PROPERTY_PERMISSIONS).setValue(resUtil.getPermissionString());
    }
    if (resourceItem.getItemProperty(PROPERTY_DATE_MODIFIED) != null) {
        resourceItem.getItemProperty(PROPERTY_DATE_MODIFIED).setValue(Long.valueOf(resource.getDateLastModified()));
    }
    if (resourceItem.getItemProperty(PROPERTY_USER_MODIFIED) != null) {
        resourceItem.getItemProperty(PROPERTY_USER_MODIFIED).setValue(resUtil.getUserLastModified());
    }
    if (resourceItem.getItemProperty(PROPERTY_DATE_CREATED) != null) {
        resourceItem.getItemProperty(PROPERTY_DATE_CREATED).setValue(Long.valueOf(resource.getDateCreated()));
    }
    if (resourceItem.getItemProperty(PROPERTY_USER_CREATED) != null) {
        resourceItem.getItemProperty(PROPERTY_USER_CREATED).setValue(resUtil.getUserCreated());
    }
    if (resourceItem.getItemProperty(PROPERTY_DATE_RELEASED) != null) {
        long release = resource.getDateReleased();
        if (release != CmsResource.DATE_RELEASED_DEFAULT) {
            resourceItem.getItemProperty(PROPERTY_DATE_RELEASED).setValue(Long.valueOf(release));
        } else {
            resourceItem.getItemProperty(PROPERTY_DATE_RELEASED).setValue(null);
        }
    }
    if (resourceItem.getItemProperty(PROPERTY_DATE_EXPIRED) != null) {
        long expire = resource.getDateExpired();
        if (expire != CmsResource.DATE_EXPIRED_DEFAULT) {
            resourceItem.getItemProperty(PROPERTY_DATE_EXPIRED).setValue(Long.valueOf(expire));
        } else {
            resourceItem.getItemProperty(PROPERTY_DATE_EXPIRED).setValue(null);
        }
    }
    if (resourceItem.getItemProperty(PROPERTY_STATE_NAME) != null) {
        resourceItem.getItemProperty(PROPERTY_STATE_NAME).setValue(resUtil.getStateName());
    }
    if (resourceItem.getItemProperty(PROPERTY_STATE) != null) {
        resourceItem.getItemProperty(PROPERTY_STATE).setValue(resource.getState());
    }
    if (resourceItem.getItemProperty(PROPERTY_USER_LOCKED) != null) {
        resourceItem.getItemProperty(PROPERTY_USER_LOCKED).setValue(resUtil.getLockedByName());
    }
}
Also used : CmsResourceUtil(org.opencms.workplace.explorer.CmsResourceUtil) Label(com.vaadin.v7.ui.Label) CmsCssIcon(org.opencms.ui.CmsCssIcon) CmsException(org.opencms.main.CmsException) I_CmsResourceType(org.opencms.file.types.I_CmsResourceType) CmsProperty(org.opencms.file.CmsProperty) CmsException(org.opencms.main.CmsException)

Example 3 with CmsResourceUtil

use of org.opencms.workplace.explorer.CmsResourceUtil in project opencms-core by alkacon.

the class CmsResourceInfo method createSitemapResourceInfo.

/**
 * Creates a resource info widget for a resource that looks like the sitemap entry for that resource.<p>
 *
 * @param resource the resource
 * @param baseSite the base site
 *
 * @return the resource info widget
 */
public static CmsResourceInfo createSitemapResourceInfo(CmsResource resource, CmsSite baseSite) {
    String title = resource.getName();
    String path = resource.getRootPath();
    CmsResourceInfo info = new CmsResourceInfo();
    CmsResourceUtil resUtil = new CmsResourceUtil(A_CmsUI.getCmsObject(), resource);
    CmsObject cms = A_CmsUI.getCmsObject();
    try {
        Map<String, CmsProperty> props = CmsProperty.toObjectMap(cms.readPropertyObjects(resource, false));
        CmsProperty navtextProp = props.get(CmsPropertyDefinition.PROPERTY_NAVTEXT);
        CmsProperty titleProp = props.get(CmsPropertyDefinition.PROPERTY_TITLE);
        if ((navtextProp != null) && (navtextProp.getValue() != null)) {
            title = navtextProp.getValue();
        } else if ((titleProp != null) && (titleProp.getValue() != null)) {
            title = titleProp.getValue();
        }
    } catch (Exception e) {
        LOG.error(e.getLocalizedMessage(), e);
    }
    info.getTopLine().setValue(title);
    if (baseSite != null) {
        String siteRoot = baseSite.getSiteRoot();
        if (path.startsWith(siteRoot)) {
            path = path.substring(siteRoot.length());
            path = CmsStringUtil.joinPaths("/", path);
        }
    }
    info.getBottomLine().setValue(path);
    Resource icon = CmsResourceIcon.getSitemapResourceIcon(A_CmsUI.getCmsObject(), resUtil.getResource(), IconMode.localeCompare);
    info.getResourceIcon().initContent(resUtil, icon, null, true, false);
    return info;
}
Also used : CmsResourceUtil(org.opencms.workplace.explorer.CmsResourceUtil) CmsObject(org.opencms.file.CmsObject) CmsProperty(org.opencms.file.CmsProperty) CmsResource(org.opencms.file.CmsResource) ExternalResource(com.vaadin.server.ExternalResource) Resource(com.vaadin.server.Resource)

Example 4 with CmsResourceUtil

use of org.opencms.workplace.explorer.CmsResourceUtil in project opencms-core by alkacon.

the class CmsSearchResultsList method getCollector.

/**
 * @see org.opencms.workplace.list.A_CmsListExplorerDialog#getCollector()
 */
@Override
public I_CmsListResourceCollector getCollector() {
    if (m_collector == null) {
        m_collector = new CmsSearchResourcesCollector(this, getSearchParams().getQuery(), getSearchParams().getSortOrder(), getSearchParams().getFields(), Collections.singletonList(getSearchParams().getSearchPath()), getSearchParams().getMinDateCreated(), getSearchParams().getMaxDateCreated(), getSearchParams().getMinDateLastModified(), getSearchParams().getMaxDateLastModified(), getSearchParams().getIndexName());
        // set the right resource util parameters
        CmsResourceUtil resUtil = getResourceUtil();
        resUtil.setAbbrevLength(50);
        resUtil.setSiteMode(CmsResourceUtil.SITE_MODE_MATCHING);
    }
    return m_collector;
}
Also used : CmsResourceUtil(org.opencms.workplace.explorer.CmsResourceUtil)

Example 5 with CmsResourceUtil

use of org.opencms.workplace.explorer.CmsResourceUtil in project opencms-core by alkacon.

the class CmsListEditResourceAction method getResourceName.

/**
 * Returns the most possible right resource name.<p>
 *
 * @return the most possible right resource name
 */
private String getResourceName() {
    CmsResourceUtil resUtil = getResourceUtil();
    if (resUtil != null) {
        CmsObject cms = resUtil.getCms();
        String resource = cms.getSitePath(resUtil.getResource());
        return resource;
    } else {
        String resource = getItem().get(m_resColumnPathId).toString();
        if (!getWp().getCms().existsResource(resource, CmsResourceFilter.DEFAULT)) {
            String siteRoot = OpenCms.getSiteManager().getSiteRoot(resource);
            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(siteRoot)) {
                resource = resource.substring(siteRoot.length());
            }
            if (!getWp().getCms().existsResource(resource, CmsResourceFilter.DEFAULT)) {
                resource = null;
            }
        }
        return resource;
    }
}
Also used : CmsResourceUtil(org.opencms.workplace.explorer.CmsResourceUtil) CmsObject(org.opencms.file.CmsObject)

Aggregations

CmsResourceUtil (org.opencms.workplace.explorer.CmsResourceUtil)31 CmsResource (org.opencms.file.CmsResource)10 CmsException (org.opencms.main.CmsException)10 CmsObject (org.opencms.file.CmsObject)8 I_CmsResourceType (org.opencms.file.types.I_CmsResourceType)7 Date (java.util.Date)6 Locale (java.util.Locale)6 CmsUUID (org.opencms.util.CmsUUID)6 CmsProperty (org.opencms.file.CmsProperty)5 CmsPermissionInfo (org.opencms.gwt.shared.CmsPermissionInfo)5 CmsLock (org.opencms.lock.CmsLock)5 CmsUser (org.opencms.file.CmsUser)4 CmsResourceTypeXmlContent (org.opencms.file.types.CmsResourceTypeXmlContent)4 LinkedHashMap (java.util.LinkedHashMap)3 CmsVfsResourceNotFoundException (org.opencms.file.CmsVfsResourceNotFoundException)3 Item (com.vaadin.v7.data.Item)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 CmsPublishResource (org.opencms.ade.publish.shared.CmsPublishResource)2 CmsResourceTypeImage (org.opencms.file.types.CmsResourceTypeImage)2