cmsobjectwrapper.java
来自「找了很久才找到到源代码」· Java 代码 · 共 906 行 · 第 1/3 页
JAVA
906 行
CmsLock lock = null;
// iterate through all wrappers and call "getLock" till one does not return null
List wrappers = getWrappers();
Iterator iter = wrappers.iterator();
while (iter.hasNext()) {
I_CmsResourceWrapper wrapper = (I_CmsResourceWrapper)iter.next();
lock = wrapper.getLock(m_cms, resource);
if (lock != null) {
break;
}
}
// delegate the call to the CmsObject
if (lock == null) {
lock = m_cms.getLock(resource);
}
return lock;
}
/**
* Delegate method for {@link CmsObject#getRequestContext()}.<p>
*
* @see CmsObject#getRequestContext()
* @return the current users request context
*/
public CmsRequestContext getRequestContext() {
return m_cms.getRequestContext();
}
/**
* Returns all child resources of a resource, that is the resources
* contained in a folder.<p>
*
* First fetch all child resources from VFS by calling {@link CmsObject#getResourcesInFolder(String, CmsResourceFilter)}.
* After that all resource wrapper are called {@link I_CmsResourceWrapper#addResourcesToFolder(CmsObject, String, CmsResourceFilter)}
* to have the chance to add additional resources to those already existing. In that list every resource is given to
* the appropriate resource wrapper ({@link I_CmsResourceWrapper#wrapResource(CmsObject, CmsResource)}) to have the
* possibility to change the existing resources. The matching resource wrapper for a resource is found by a call to
* {@link I_CmsResourceWrapper#isWrappedResource(CmsObject, CmsResource)}.<p>
*
* @see I_CmsResourceWrapper#addResourcesToFolder(CmsObject, String, CmsResourceFilter)
* @see CmsObject#getResourcesInFolder(String, CmsResourceFilter)
*
* @param resourcename the full path of the resource to return the child resources for
* @param filter the resource filter to use
*
* @return a list of all child <code>{@link CmsResource}</code>s
*
* @throws CmsException if something goes wrong
*/
public List getResourcesInFolder(String resourcename, CmsResourceFilter filter) throws CmsException {
List list = new ArrayList();
// read children existing in the VFS
try {
list.addAll(m_cms.getResourcesInFolder(resourcename, filter));
} catch (CmsException ex) {
//noop
}
// iterate through all wrappers and call "addResourcesToFolder" and add the results to the list
List wrappers = getWrappers();
Iterator iter = wrappers.iterator();
while (iter.hasNext()) {
I_CmsResourceWrapper wrapper = (I_CmsResourceWrapper)iter.next();
List added = wrapper.addResourcesToFolder(m_cms, resourcename, filter);
if (added != null) {
list.addAll(added);
}
}
// create a new list to add all resources
ArrayList wrapped = new ArrayList();
// eventually wrap the found resources
iter = list.iterator();
while (iter.hasNext()) {
CmsResource res = (CmsResource)iter.next();
// correct the length of the content if an UTF-8 marker would be added later
if (needUtf8Marker(res)) {
CmsWrappedResource wrap = new CmsWrappedResource(res);
wrap.setLength(res.getLength() + CmsResourceWrapperUtils.UTF8_MARKER.length);
res = wrap.getResource();
}
// get resource type wrapper for the resource
I_CmsResourceWrapper resWrapper = getResourceTypeWrapper(res);
if (resWrapper != null) {
// adds the wrapped resources
wrapped.add(resWrapper.wrapResource(m_cms, res));
} else {
// add the resource unwrapped
wrapped.add(res);
}
}
// sort the wrapped list correctly
Collections.sort(wrapped, CmsResource.COMPARE_ROOT_PATH_IGNORE_CASE_FOLDERS_FIRST);
return wrapped;
}
/**
* Delegate method for {@link CmsObject#getSitePath(CmsResource)}.<p>
*
* @see CmsObject#getSitePath(org.opencms.file.CmsResource)
*
* @param resource the resource to get the adjusted site root path for
*
* @return the absolute resource path adjusted for the current site
*/
public String getSitePath(CmsResource resource) {
return m_cms.getSitePath(resource);
}
/**
* Returns the configured resource wrappers used by this instance.<p>
*
* Entries in list are from type {@link I_CmsResourceWrapper}.<p>
*
* @return the configured resource wrappers for this instance
*/
public List getWrappers() {
return m_wrappers;
}
/**
* Locks a resource.<p>
*
* Iterates through all configured resource wrappers till the first returns <code>true</code>.<p>
*
* @see I_CmsResourceWrapper#lockResource(CmsObject, String)
* @see CmsObject#lockResource(String)
*
* @param resourcename the name of the resource to lock (full path)
*
* @throws CmsException if something goes wrong
*/
public void lockResource(String resourcename) throws CmsException {
boolean exec = false;
// iterate through all wrappers and call "lockResource" till one does not return false
List wrappers = getWrappers();
Iterator iter = wrappers.iterator();
while (iter.hasNext()) {
I_CmsResourceWrapper wrapper = (I_CmsResourceWrapper)iter.next();
exec = wrapper.lockResource(m_cms, resourcename);
if (exec) {
break;
}
}
// delegate the call to the CmsObject
if (!exec) {
m_cms.lockResource(resourcename);
}
}
/**
* Moves a resource to the given destination.<p>
*
* Iterates through all configured resource wrappers till the first returns <code>true</code>.<p>
*
* @see I_CmsResourceWrapper#moveResource(CmsObject, String, String)
* @see CmsObject#moveResource(String, String)
*
* @param source the name of the resource to move (full path)
* @param destination the destination resource name (full path)
*
* @throws CmsException if something goes wrong
*/
public void moveResource(String source, String destination) throws CmsException {
boolean exec = false;
// iterate through all wrappers and call "moveResource" till one does not return false
List wrappers = getWrappers();
Iterator iter = wrappers.iterator();
while (iter.hasNext()) {
I_CmsResourceWrapper wrapper = (I_CmsResourceWrapper)iter.next();
exec = wrapper.moveResource(m_cms, source, destination);
if (exec) {
break;
}
}
// delegate the call to the CmsObject
if (!exec) {
m_cms.moveResource(source, destination);
}
}
/**
* Reads a file resource (including it's binary content) from the VFS,
* using the specified resource filter.<p>
*
* Iterates through all configured resource wrappers till the first returns not <code>null</code>.<p>
*
* If the resource contains textual content and the encoding is UTF-8, then the byte order mask
* for UTF-8 is added at the start of the content to make sure that a client using this content
* displays it correctly.<p>
*
* @see I_CmsResourceWrapper#readFile(CmsObject, String, CmsResourceFilter)
* @see CmsObject#readFile(String, CmsResourceFilter)
*
* @param resourcename the name of the resource to read (full path)
* @param filter the resource filter to use while reading
*
* @return the file resource that was read
*
* @throws CmsException if the file resource could not be read for any reason
*/
public CmsFile readFile(String resourcename, CmsResourceFilter filter) throws CmsException {
CmsFile res = null;
// iterate through all wrappers and call "readFile" till one does not return null
List wrappers = getWrappers();
Iterator iter = wrappers.iterator();
while (iter.hasNext()) {
I_CmsResourceWrapper wrapper = (I_CmsResourceWrapper)iter.next();
res = wrapper.readFile(m_cms, resourcename, filter);
if (res != null) {
break;
}
}
// delegate the call to the CmsObject
if (res == null) {
res = m_cms.readFile(resourcename, filter);
}
// for text based resources which are encoded in UTF-8 add the UTF marker at the start
// of the content
if (needUtf8Marker(res)) {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_ADD_UTF8_MARKER_1, res.getRootPath()));
}
res.setContents(CmsResourceWrapperUtils.addUtf8Marker(res.getContents()));
}
return res;
}
/**
* Delegate method for {@link CmsObject#readPropertyObject(CmsResource, String, boolean)}.<p>
*
* @see CmsObject#readPropertyObject(CmsResource, String, boolean)
*
* @param resource the resource where the property is attached to
* @param property the property name
* @param search if true, the property is searched on all parent folders of the resource,
* if it's not found attached directly to the resource
*
* @return the required property, or <code>{@link CmsProperty#getNullProperty()}</code> if the property was not found
*
* @throws CmsException if something goes wrong
*/
public CmsProperty readPropertyObject(CmsResource resource, String property, boolean search) throws CmsException {
return m_cms.readPropertyObject(resource, property, search);
}
/**
* Delegate method for {@link CmsObject#readResource(CmsUUID, CmsResourceFilter)}.<p>
*
* @see CmsObject#readResource(CmsUUID, CmsResourceFilter)
*
* @param structureID the ID of the structure to read
* @param filter the resource filter to use while reading
*
* @return the resource that was read
*
* @throws CmsException if the resource could not be read for any reason
*/
public CmsResource readResource(CmsUUID structureID, CmsResourceFilter filter) throws CmsException {
return m_cms.readResource(structureID, filter);
}
/**
* Reads a resource from the VFS,
* using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p>
*
* Iterates through all configured resource wrappers till the first returns not <code>null</code>.<p>
*
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?