/** * @see org.opencms.ui.contextmenu.I_CmsHasMenuItemVisibility#getVisibility(org.opencms.file.CmsObject, java.util.List) */ public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, List<CmsResource> resources) { if ((resources.size() == 1) && resources.get(0).isFile() && !CmsResourceTypeXmlContainerPage.isContainerPage(resources.get(0))) { return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE; } else { return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; } } }
/** * Sets the parent path to read visited resources from using the given resource as parent.<p> * * @param parentResource the resource to use as parent resource */ public void setParentResource(CmsResource parentResource) { if (parentResource.isFile()) { m_parentPath = CmsResource.getFolderPath(parentResource.getRootPath()); } else { m_parentPath = parentResource.getRootPath(); } }
/** * Returns <code>true</code> if this resource is a temporary file.<p> * * A resource is considered a temporary file it is a file where the * {@link CmsResource#FLAG_TEMPFILE} flag has been set, or if the file name (without parent folders) * starts with the prefix char <code>'~'</code> (tilde).<p> * * @return <code>true</code> if the given resource name is a temporary file * * @see #isTemporaryFileName(String) */ public boolean isTemporaryFile() { return isFile() && (((getFlags() & CmsResource.FLAG_TEMPFILE) > 0) || isTemporaryFileName(getName())); }
/** * Returns <code>true</code> if the given resource is a temporary file.<p> * * A resource is considered a temporary file it is a file where the * {@link CmsResource#FLAG_TEMPFILE} flag has been set, or if the file name (without parent folders) * starts with the prefix char <code>'~'</code> (tilde).<p> * * @param resource the resource name to check * * @return <code>true</code> if the given resource name is a temporary file * * @see #getTemporaryFileName(String) * @see #isTemporaryFileName(String) */ public static boolean isTemporaryFile(CmsResource resource) { return (resource != null) && ((resource.isFile() && (((resource.getFlags() & CmsResource.FLAG_TEMPFILE) > 0) || (isTemporaryFileName(resource.getName()))))); }
/** * @see org.opencms.repository.I_CmsRepositoryItem#getContent() */ public byte[] getContent() { if (!m_resource.isFile()) { return null; } if (m_content == null) { try { String filename = m_cms.getSitePath(m_resource); // read and return the file CmsFile file = m_cms.readFile(filename, CmsResourceFilter.IGNORE_EXPIRATION); m_content = file.getContents(); } catch (CmsException ex) { // noop } } return m_content; }
/** * @see org.opencms.repository.I_CmsRepositoryItem#getContent() */ public byte[] getContent() { if (!m_resource.isFile()) { return null; } if (m_content == null) { try { String filename = m_cms.getSitePath(m_resource); // read and return the file CmsFile file = m_cms.readFile(filename, CmsResourceFilter.IGNORE_EXPIRATION); m_content = file.getContents(); } catch (CmsException ex) { // noop } } return m_content; }
/** * Returns <code>true</code> if the given resource is a temporary file.<p> * * A resource is considered a temporary file it is a file where the * {@link CmsResource#FLAG_TEMPFILE} flag has been set, or if the file name (without parent folders) * starts with the prefix char <code>'~'</code> (tilde).<p> * * @param resource the resource name to check * * @return <code>true</code> if the given resource name is a temporary file * * @see #getTemporaryFileName(String) * @see CmsResource#isTemporaryFileName(String) */ public static boolean isTemporaryFile(CmsResource resource) { return (resource != null) && ((resource.isFile() && (((resource.getFlags() & CmsResource.FLAG_TEMPFILE) > 0) || (CmsResource.isTemporaryFileName(resource.getName()))))); }
/** * Checks if the file content already contains the UTF8 marker.<p> * * @param res the resource to check * * @return <code>true</code> if the file content already contains the UTF8 marker */ private boolean startsWithUtf8Marker(CmsResource res) { boolean result = false; try { if (res.isFile()) { CmsFile file = m_cms.readFile(res); if ((file.getContents().length >= 3) && (file.getContents()[0] == CmsResourceWrapperUtils.UTF8_MARKER[0]) && (file.getContents()[1] == CmsResourceWrapperUtils.UTF8_MARKER[1]) && (file.getContents()[2] == CmsResourceWrapperUtils.UTF8_MARKER[2])) { result = true; } } } catch (CmsException e) { LOG.debug(e); } return result; } }
/** * Validates that the length setting of a resource is always correct.<p> * * Files need to have a resource length of >= 0, while folders require * a resource length of -1.<p> * * @param resource the resource to check the length for * @throws CmsDataAccessException if the resource length is not correct */ protected void internalValidateResourceLength(CmsResource resource) throws CmsDataAccessException { if (resource.isFolder() && (resource.getLength() == -1)) { return; } if (resource.isFile() && (resource.getLength() >= 0)) { return; } throw new CmsDataAccessException(Messages.get().container( Messages.ERR_INVALID_RESOURCE_LENGTH_2, new Integer(resource.getLength()), resource.getRootPath())); }
/** * Validates that the length setting of a resource is always correct.<p> * * Files need to have a resource length of >= 0, while folders require * a resource length of -1.<p> * * @param resource the resource to check the length for * @throws CmsDataAccessException if the resource length is not correct */ protected void internalValidateResourceLength(CmsResource resource) throws CmsDataAccessException { if (resource.isFolder() && (resource.getLength() == -1)) { return; } if (resource.isFile() && (resource.getLength() >= 0)) { return; } throw new CmsDataAccessException( Messages.get().container( Messages.ERR_INVALID_RESOURCE_LENGTH_2, new Integer(resource.getLength()), resource.getRootPath())); }
/** * Validates that the length setting of a resource is always correct.<p> * * Files need to have a resource length of >= 0, while folders require * a resource length of -1.<p> * * @param resource the resource to check the length for * * @throws CmsDataAccessException if something goes wrong */ protected void internalValidateResourceLength(CmsResource resource) throws CmsDataAccessException { if (resource.isFolder() && (resource.getLength() == -1)) { return; } if (resource.isFile() && (resource.getLength() >= 0)) { return; } throw new CmsDataAccessException( Messages.get().container( Messages.ERR_INVALID_RESOURCE_LENGTH_2, new Integer(resource.getLength()), resource.getRootPath())); }
/** * Returns the drag target id.<p> * * @param dragEvent the drag event * * @return the drag target id */ protected CmsUUID getTargetId(DragAndDropEvent dragEvent) { CmsUUID targetId = null; if (dragEvent.getTargetDetails() instanceof AbstractSelectTargetDetails) { AbstractSelectTargetDetails target = (AbstractSelectTargetDetails)dragEvent.getTargetDetails(); targetId = (CmsUUID)target.getItemIdOver(); } try { CmsObject cms = A_CmsUI.getCmsObject(); CmsResource target = cms.readResource(targetId); if (target.isFile()) { targetId = null; } } catch (CmsException e) { targetId = null; LOG.debug("Checking drop target failed, use current folder.", e); } if (targetId == null) { targetId = getCurrentFolder(); } return targetId; }
/** * Copies state information from the internal CmsResource object to this object.<p> */ protected void updateFromResource() { setCreationDate(m_resource.getDateCreated()); int length = m_resource.getLength(); if (m_resource.isFolder()) { length = 1; } setFileSize(length); setModifyDate(m_resource.getDateLastModified()); setAttributes(m_resource.isFile() ? FileAttribute.Normal : FileAttribute.Directory); }
/** * @see org.opencms.repository.I_CmsRepositoryItem#getMimeType() */ public String getMimeType() { if (!m_resource.isFile()) { return null; } if (m_mimeType == null) { try { String encoding = m_cms.readPropertyObject( m_resource, CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING, true).getValue(OpenCms.getSystemInfo().getDefaultEncoding()); m_mimeType = OpenCms.getResourceManager().getMimeType( m_resource.getRootPath(), encoding, CmsResourceManager.MIMETYPE_TEXT); } catch (CmsException ex) { // noop } } return m_mimeType; }
/** * Enumeration class for the mode parameter in the * {@link CmsDriverManager#readChangedResourcesInsideProject(CmsDbContext, CmsUUID, CmsReadChangedProjectResourceMode)} * method.<p> */ private static class CmsReadChangedProjectResourceMode { /** * Default constructor.<p> */ protected CmsReadChangedProjectResourceMode() { // noop } }
/** * @see org.opencms.repository.I_CmsRepositoryItem#getMimeType() */ public String getMimeType() { if (!m_resource.isFile()) { return null; } if (m_mimeType == null) { try { String encoding = m_cms.readPropertyObject( m_resource, CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING, true).getValue(OpenCms.getSystemInfo().getDefaultEncoding()); m_mimeType = OpenCms.getResourceManager().getMimeType( m_resource.getRootPath(), encoding, CmsResourceManager.MIMETYPE_TEXT); } catch (CmsException ex) { // noop } } return m_mimeType; }
/** * Loads the file data from the VFS.<p> * * @param needContent true if we need the file content to be loaded * * @throws IOException if an IO error happens * @throws CmsException if a CMS operation fails */ protected void load(boolean needContent) throws IOException, CmsException { try { if (m_resource.isFolder() && needContent) { throw new AccessDeniedException("Operation not supported for directories!"); } if (m_resource.isFile() && needContent && (!(m_resource instanceof CmsFile))) { m_resource = m_cms.readFile(m_cms.getSitePath(m_resource), CmsJlanDiskInterface.STANDARD_FILTER); } if (!m_bufferInitialized && (getFile() != null)) { // readResource may already have returned a CmsFile, this is why we need to initialize the buffer // here and not in the if-block above m_buffer.init(getFile().getContents()); m_bufferInitialized = true; } } catch (CmsException e) { throw e; } }
/** * Adds an item to the folder tree.<p> * * @param cms the CMS context * @param resource the folder resource * @param parentId the parent folder id */ public void addTreeItem(CmsObject cms, CmsResource resource, CmsUUID parentId) { List<Container.Filter> filters = Lists.newArrayList(getContainerFilters()); // getItem only finds an existing item if it isn't filtered out by the container // filters, so we temporarily remove the filters to access the complete data set removeAllContainerFilters(); try { Item resourceItem = getItem(resource.getStructureId()); if (resourceItem == null) { resourceItem = addItem(resource.getStructureId()); } fillProperties(cms, resourceItem, resource, parentId); if (resource.isFile()) { setChildrenAllowed(resource.getStructureId(), false); } if (parentId != null) { setParent(resource.getStructureId(), parentId); } } finally { for (Container.Filter filter : filters) { addContainerFilter(filter); } } }
/** * @see org.opencms.workplace.explorer.menu.I_CmsMenuItemRule#getVisibility(org.opencms.file.CmsObject, CmsResourceUtil[]) */ @Override public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, CmsResourceUtil[] resourceUtil) { if (resourceUtil[0].getResource().getState().isDeleted()) { return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; } else if (resourceUtil[0].getResource().getState().isNew() || (resourceUtil[0].getResource().isFile() && resourceUtil[0].getResource().getState().isUnchanged())) { return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE.addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_NEW_UNCHANGED_0); } try { if (!resourceUtil[0].isEditable() || !cms.hasPermissions( resourceUtil[0].getResource(), CmsPermissionSet.ACCESS_WRITE, false, CmsResourceFilter.ALL)) { return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE.addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_PERM_WRITE_0); } } catch (CmsException e) { // error checking permissions, disable entry completely return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; } return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE; }
/** * @see org.opencms.workplace.explorer.menu.I_CmsMenuItemRule#getVisibility(org.opencms.file.CmsObject, CmsResourceUtil[]) */ @Override public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, CmsResourceUtil[] resourceUtil) { if (resourceUtil[0].getResource().getState().isDeleted()) { return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; } else if (resourceUtil[0].getResource().getState().isNew() || (resourceUtil[0].getResource().isFile() && resourceUtil[0].getResource().getState().isUnchanged())) { return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE.addMessageKey( Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_NEW_UNCHANGED_0); } try { if (!resourceUtil[0].isEditable() || !cms.hasPermissions( resourceUtil[0].getResource(), CmsPermissionSet.ACCESS_WRITE, false, CmsResourceFilter.ALL)) { return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE.addMessageKey( Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_PERM_WRITE_0); } } catch (CmsException e) { // error checking permissions, disable entry completely return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; } return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE; }