public class CmsLinkRewriter
extends java.lang.Object
| 限定符和类型 | 字段和说明 |
|---|---|
protected java.util.Map<CmsUUID,CmsResource> |
m_translationsById
A map from source folder structure ids to corresponding target folder resources.
|
protected java.util.Map<java.lang.String,CmsResource> |
m_translationsByPath
A map from source folder root paths to the corresponding target folder resources.
|
| 构造器和说明 |
|---|
CmsLinkRewriter(CmsObject cms,
java.util.List<java.lang.String> sources,
java.lang.String target)
Creates a link rewriter for use after a multi-copy operation.
|
CmsLinkRewriter(CmsObject cms,
java.lang.String targetPath,
java.util.List<CmsPair<java.lang.String,java.lang.String>> sourceTargetPairs)
Creates a new link rewriter for a list of sources and corresponding targets.
|
CmsLinkRewriter(CmsObject cms,
java.lang.String source,
java.lang.String target)
Creates a link rewriter for use after a single copy operation.
|
| 限定符和类型 | 方法和说明 |
|---|---|
protected static void |
checkIsFolder(CmsResource resource)
Checks whether a given resource is a folder and throws an exception otherwise.
|
protected void |
checkNotSubPath(java.lang.String source,
java.lang.String target)
Checks that the target path is not a subfolder of the source path.
|
protected java.lang.String |
decode(byte[] bytes,
java.lang.String encoding)
Decodes a byte array into a string with a given encoding, or the default encoding if that fails.
|
protected CmsPair<java.lang.String,java.lang.String> |
decode(CmsFile file)
Decodes a file's contents and return the content string and the encoding to use for writing the file
back to the VFS.
|
protected java.util.List<CmsRelation> |
findRelationsFromTargetToSource()
Finds relations from the target root folder or its children to the source root folder or its children.
|
protected java.lang.String |
getConfiguredEncoding(CmsObject cms,
CmsResource resource)
Gets the encoding which is configured at the location of a given resource.
|
protected java.util.List<CmsPair<CmsResource,CmsResource>> |
getMatchingResources(java.lang.String source,
java.lang.String target)
Gets a list of resource pairs whose paths relative to the source/target roots passed match.
|
protected java.lang.String |
getRelativePath(java.lang.String ancestor,
java.lang.String rootPath)
Computes the relative path given an ancestor folder path.
|
protected CmsResource |
getResource(CmsUUID structureId)
Accesses a resource by structure id.
|
protected java.util.Map<java.lang.String,CmsResource> |
getResourcesByRelativePath(java.util.List<CmsResource> resources,
java.lang.String basePath)
Collects a list of resources in a map where the key for each resource is the path relative to a given folder.
|
protected void |
init()
Reads the data needed for rewriting the relations from the VFS.
|
protected static boolean |
isFolder(CmsResource resource)
Helper method to check whether a given resource is a folder.
|
protected boolean |
isInSources(java.lang.String path)
Checks if a path belongs to one of the sources.
|
protected boolean |
isInTargets(java.lang.String path)
Checks if a path belongs to one of the targets.
|
protected java.util.List<CmsResource> |
readTree(java.lang.String rootPath)
Reads the resources in a subtree.
|
protected void |
rewriteContent(CmsFile file,
java.util.Collection<CmsRelation> relations)
Rewrites the links included in the content itself.
|
protected java.lang.String |
rewriteContentString(java.lang.String originalContent)
Replaces structure ids of resources in the source subtree with the structure ids of the corresponding
resources in the target subtree inside a content string.
|
void |
rewriteLinks()
Starts the link rewriting process.
|
protected void |
rewriteLinks(CmsResource resource,
java.util.Collection<CmsRelation> relations)
Rewrites the links for a single resource.
|
protected void |
rewriteOtherRelations(CmsResource res,
java.util.Collection<CmsRelation> relations)
Rewrites relations which are not derived from links in the content itself.
|
void |
setRewriteAllContents(boolean rewriteAllContents)
Sets the 'rewriteAllContents' flag, which controls whether all XML contents will be rewritten
or just those whose links need to be corrected.
|
protected java.util.Map<CmsUUID,CmsResource> m_translationsById
protected java.util.Map<java.lang.String,CmsResource> m_translationsByPath
public CmsLinkRewriter(CmsObject cms, java.util.List<java.lang.String> sources, java.lang.String target)
cms - the current CMS contextsources - the list of source root pathstarget - the target parent folder root pathpublic CmsLinkRewriter(CmsObject cms, java.lang.String targetPath, java.util.List<CmsPair<java.lang.String,java.lang.String>> sourceTargetPairs)
cms - the current CMS contexttargetPath - the target root pathsourceTargetPairs - the list of source-target pairspublic CmsLinkRewriter(CmsObject cms, java.lang.String source, java.lang.String target)
cms - the current CMS contextsource - the source folder root pathtarget - the target folder root pathprotected static void checkIsFolder(CmsResource resource) throws CmsException
resource - the resource to checkCmsException - if something goes wrongprotected static boolean isFolder(CmsResource resource) throws CmsLoaderException
resource - the resouce to checkCmsLoaderException - if the resource type couldn't be foundpublic void rewriteLinks()
throws CmsException
CmsException - if something goes wrongpublic void setRewriteAllContents(boolean rewriteAllContents)
rewriteAllContents - if true, all contents will be rewrittenprotected void checkNotSubPath(java.lang.String source,
java.lang.String target)
source - the source pathtarget - the target pathprotected java.lang.String decode(byte[] bytes,
java.lang.String encoding)
bytes - the byte arrayencoding - the encoding to useprotected CmsPair<java.lang.String,java.lang.String> decode(CmsFile file) throws CmsException
file - the file to decodeCmsException - if something goes wrongprotected java.util.List<CmsRelation> findRelationsFromTargetToSource() throws CmsException
CmsException - if something goes wrongprotected java.lang.String getConfiguredEncoding(CmsObject cms, CmsResource resource) throws CmsException
cms - the current CMS contextresource - the resource for which the configured encoding should be retrievedCmsException - if something goes wrongprotected java.util.List<CmsPair<CmsResource,CmsResource>> getMatchingResources(java.lang.String source, java.lang.String target) throws CmsException
source - the source roottarget - the target rootCmsException - if something goes wrongprotected java.lang.String getRelativePath(java.lang.String ancestor,
java.lang.String rootPath)
ancestor - the ancestor folderrootPath - the path for which the relative path should be computedprotected CmsResource getResource(CmsUUID structureId) throws CmsException
structureId - the structure id of the resourceCmsException - if the resource couldn't be readprotected java.util.Map<java.lang.String,CmsResource> getResourcesByRelativePath(java.util.List<CmsResource> resources, java.lang.String basePath)
resources - the resources to put in the mapbasePath - the path relative to which the keys of the resulting map should be computedprotected void init()
throws CmsException
CmsException - if something goes wrongprotected boolean isInSources(java.lang.String path)
path - a root pathprotected boolean isInTargets(java.lang.String path)
path - a root pathprotected java.util.List<CmsResource> readTree(java.lang.String rootPath) throws CmsException
rootPath - the root of the subtreeCmsException - if something goes wrongprotected void rewriteContent(CmsFile file, java.util.Collection<CmsRelation> relations) throws CmsException
file - the file for which the links should be replacedrelations - the original relationsCmsException - if something goes wrongprotected java.lang.String rewriteContentString(java.lang.String originalContent)
originalContent - the original contentprotected void rewriteLinks(CmsResource resource, java.util.Collection<CmsRelation> relations) throws CmsException
resource - the resource for which the links should be rewrittenrelations - the relations to the source folder which have this resource as its sourceCmsException - if something goes wrongprotected void rewriteOtherRelations(CmsResource res, java.util.Collection<CmsRelation> relations) throws CmsException
res - the resource for which to rewrite the relationsrelations - the original relationsCmsException - if something goes wrong