|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectorg.opencms.file.CmsLinkRewriter
public class CmsLinkRewriter
A class used to rewrite links and relations in one subtree such that relations from that subtree to another given subtree replaced with relations to the first subtree.
| Field Summary | |
|---|---|
protected Map<CmsUUID,CmsResource> |
m_translationsById
A map from source folder structure ids to corresponding target folder resources. |
protected Map<String,CmsResource> |
m_translationsByPath
A map from source folder root paths to the corresponding target folder resources. |
| Constructor Summary | |
|---|---|
CmsLinkRewriter(CmsObject cms,
List<String> sources,
String target)
Creates a link rewriter for use after a multi-copy operation. |
|
CmsLinkRewriter(CmsObject cms,
String targetPath,
List<CmsPair<String,String>> sourceTargetPairs)
Creates a new link rewriter for a list of sources and corresponding targets. |
|
CmsLinkRewriter(CmsObject cms,
String source,
String target)
Creates a link rewriter for use after a single copy operation. |
|
| Method Summary | |
|---|---|
protected static void |
checkIsFolder(CmsResource resource)
Checks whether a given resource is a folder and throws an exception otherwise. |
protected void |
checkNotSubPath(String source,
String target)
Checks that the target path is not a subfolder of the source path. |
protected String |
decode(byte[] bytes,
String encoding)
Decodes a byte array into a string with a given encoding, or the default encoding if that fails. |
protected CmsPair<String,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 List<CmsRelation> |
findRelationsFromTargetToSource()
Finds relations from the target root folder or its children to the source root folder or its children. |
protected String |
getConfiguredEncoding(CmsObject cms,
CmsResource resource)
Gets the encoding which is configured at the location of a given resource. |
protected List<CmsPair<CmsResource,CmsResource>> |
getMatchingResources(String source,
String target)
Gets a list of resource pairs whose paths relative to the source/target roots passed match. |
protected String |
getRelativePath(String ancestor,
String rootPath)
Computes the relative path given an ancestor folder path. |
protected CmsResource |
getResource(CmsUUID structureId)
Accesses a resource by structure id. |
protected Map<String,CmsResource> |
getResourcesByRelativePath(List<CmsResource> resources,
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(String path)
Checks if a path belongs to one of the sources. |
protected boolean |
isInTargets(String path)
Checks if a path belongs to one of the targets. |
protected List<CmsResource> |
readTree(String rootPath)
Reads the resources in a subtree. |
protected void |
rewriteContent(CmsFile file,
Collection<CmsRelation> relations)
Rewrites the links included in the content itself. |
protected String |
rewriteContentString(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,
Collection<CmsRelation> relations)
Rewrites the links for a single resource. |
protected void |
rewriteOtherRelations(CmsResource res,
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected Map<CmsUUID,CmsResource> m_translationsById
protected Map<String,CmsResource> m_translationsByPath
| Constructor Detail |
|---|
public CmsLinkRewriter(CmsObject cms,
List<String> sources,
String target)
cms - the current CMS contextsources - the list of source root pathstarget - the target parent folder root path
public CmsLinkRewriter(CmsObject cms,
String targetPath,
List<CmsPair<String,String>> sourceTargetPairs)
cms - the current CMS contexttargetPath - the target root pathsourceTargetPairs - the list of source-target pairs
public CmsLinkRewriter(CmsObject cms,
String source,
String target)
cms - the current CMS contextsource - the source folder root pathtarget - the target folder root path| Method Detail |
|---|
protected static void checkIsFolder(CmsResource resource)
throws CmsException
resource - the resource to check
CmsException - if something goes wrong
protected static boolean isFolder(CmsResource resource)
throws CmsLoaderException
resource - the resouce to check
CmsLoaderException - if the resource type couldn't be found
public void rewriteLinks()
throws CmsException
CmsException - if something goes wrongpublic void setRewriteAllContents(boolean rewriteAllContents)
rewriteAllContents - if true, all contents will be rewritten
protected void checkNotSubPath(String source,
String target)
source - the source pathtarget - the target path
protected String decode(byte[] bytes,
String encoding)
bytes - the byte arrayencoding - the encoding to use
protected CmsPair<String,String> decode(CmsFile file)
throws CmsException
file - the file to decode
CmsException - if something goes wrong
protected List<CmsRelation> findRelationsFromTargetToSource()
throws CmsException
CmsException - if something goes wrong
protected String getConfiguredEncoding(CmsObject cms,
CmsResource resource)
throws CmsException
cms - the current CMS contextresource - the resource for which the configured encoding should be retrieved
CmsException - if something goes wrong
protected List<CmsPair<CmsResource,CmsResource>> getMatchingResources(String source,
String target)
throws CmsException
source - the source roottarget - the target root
CmsException - if something goes wrong
protected String getRelativePath(String ancestor,
String rootPath)
ancestor - the ancestor folderrootPath - the path for which the relative path should be computed
protected CmsResource getResource(CmsUUID structureId)
throws CmsException
structureId - the structure id of the resource
CmsException - if the resource couldn't be read
protected Map<String,CmsResource> getResourcesByRelativePath(List<CmsResource> resources,
String basePath)
resources - the resources to put in the mapbasePath - the path relative to which the keys of the resulting map should be computed
protected void init()
throws CmsException
CmsException - if something goes wrongprotected boolean isInSources(String path)
path - a root path
protected boolean isInTargets(String path)
path - a root path
protected List<CmsResource> readTree(String rootPath)
throws CmsException
rootPath - the root of the subtree
CmsException - if something goes wrong
protected void rewriteContent(CmsFile file,
Collection<CmsRelation> relations)
throws CmsException
file - the file for which the links should be replacedrelations - the original relations
CmsException - if something goes wrongprotected String rewriteContentString(String originalContent)
originalContent - the original content
protected void rewriteLinks(CmsResource resource,
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 source
CmsException - if something goes wrong
protected void rewriteOtherRelations(CmsResource res,
Collection<CmsRelation> relations)
throws CmsException
res - the resource for which to rewrite the relationsrelations - the original relations
CmsException - if something goes wrong
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||