[opencms-dev] How to move content properly

Wiesner, Daniel daniel.wiesner at av-studio.de
Tue May 3 06:53:17 CEST 2005


hello,

because there seems to be no support for internal link management in OCMS 6.0 I have 
to try writing a module for moving/renaming resources. I have digged a bit in the sources and found a lot usefull.

I think the goal is a dialog in the admin/content-tools area containing input for source-folder and target-folder. 

All resources witch are childs of the source-folder will be stored in a List. Then all relevant resourses in the 
current site including the just copied (moving is copying and deleting) are scanned for every resource in the
stored list and if required corrected.

 

I think starting with findLinks(CmsObject cms, CmsResource resource) from CmsResourceTypeXmlPage is not a bad idea.

I used the code and had success replacing links:


..

	CmsFile file = cmsobj.readFile(resourceName , CmsResourceFilter.IGNORE_EXPIRATION);
	CmsXmlPage xmlPage = CmsXmlPageFactory.unmarshal(cmsobj, file);
	List locales = xmlPage.getLocales();

	Iterator i = locales.iterator();

		
	while (i.hasNext()) {
                Locale locale = (Locale)i.next();
                List elementNames = xmlPage.getNames(locale);

                // iterate over all body elements per language
                Iterator j = elementNames.iterator();
                while (j.hasNext()) {
                   String elementName = (String)j.next();
                   CmsLinkTable linkTable = xmlPage.getLinkTable(elementName, locale);

                   // iterate over all links inside a body element
                   Iterator k = linkTable.iterator();
					
                   while (k.hasNext()) {
                   	CmsLink link = (CmsLink)k.next();

                        // external links are ommitted
                        if (link.getTarget().equals(movedResourceOldName)) {
                           link.updateLink(movedResourceNewName);

											
                       }
                    }
                }
            }

	
	byte[] contentByteArray = xmlPage.marshal();
	file.setContents(contentByteArray);
	
	cmsobj.lockResource(resourceName);
	cmsobj.writeFile(file);
	cmsobj.unlockResource(resourceName);


	...


I hope someone will help me to fix this problem.

Daniel



Stephan Hartmann schrieb:


>> no
>>
>> Daniel Wiesner schrieb:
>>
>  
>
>>>> So in OCMS 5.0 internal links are corrected automatic?
>>>>
>>>> Stephan Hartmann schrieb:
>>>>
>>    
>>
>>>>>> Internal links could be tracked in an additional table as it was in 
>>>>>> OpenCms 5. Maybe this concept has been dropped due to overhead of 
>>>>>> maintenance and access rights (when an editor moves a resource you 
>>>>>> have to check if he has the rights to edit the pages that link to it).
>>>>>>
>>>>>> Daniel Wiesner schrieb:
>>>>>>
>>>      
>>>
>>>>>>>> I think the first option is the better one. The kind of internal 
>>>>>>>> links in this style: "/en/projects/overview.html" istead of 
>>>>>>>> "page?id=4532534..." includes additional information for users and 
>>>>>>>> searchbots.
>>>>>>>> Maybe there is a way to rewrite internal links after moving a page 
>>>>>>>> in a new module under admin/content-tools?
>>>>>>>>
>>>>>>>> Daniel
>>>>>>>>
>>>>>>>> Peter Birchmeier schrieb:
>>>>>>>>
>>>>        
>>>>
>>>>>>>>>> Hi
>>>>>>>>>>
>>>>>>>>>> to be honest, I also wonder about the content addressing mechanism 
>>>>>>>>>> used by OpenCms. In my opinion, it is one of the main tasks of a 
>>>>>>>>>> CMS to take over the automated linking between content objects.
>>>>>>>>>> I think there exist two ways to go:
>>>>>>>>>>
>>>>>>>>>> 1. Content objects (xml content, jsp/html pages, ..) are further 
>>>>>>>>>> addressed by its VFS file name. Whenever an object shall be 
>>>>>>>>>> renamed/moved, all other objects linking to the previous should be 
>>>>>>>>>> adapted. A good solution would be to store additional infos for 
>>>>>>>>>> each content object, infos containing a list of all objects 
>>>>>>>>>> linking to the specific one. Thus instead of starting a complete 
>>>>>>>>>> search over a wide range of objects to find all linking objects, 
>>>>>>>>>> only the objects in the list have to updated.
>>>>>>>>>>
>>>>>>>>>> 2. More complicated but more effective: content objects are only 
>>>>>>>>>> addressed by its id.
>>>>>>>>>> Disadvantage: Building and maintaining JSP files manually is nasty 
>>>>>>>>>> since links (includes, ..) contain ids instead of comprehensible 
>>>>>>>>>> file names of objects.
>>>>>>>>>> Advantage: objects can be renamed, moved, whatever you like to do 
>>>>>>>>>> with it. If there is enough support in automating the process of 
>>>>>>>>>> linking (e.g. inserting a link: OpenCms asks to chose a file (= 
>>>>>>>>>> object) and inserts its id), it is the way to go.
>>>>>>>>>>
>>>>>>>>>> kind regards, Peter
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> _______________________________________________
>>>>>>>>>> This mail is send to you from the opencms-dev mailing list
>>>>>>>>>> To change your list options, or to unsubscribe from the list, 
>>>>>>>>>> please visit
>>>>>>>>>> http://mail.opencms.org/mailman/listinfo/opencms-dev
>>>>>          
>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>        
>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> This mail is send to you from the opencms-dev mailing list
>>>>>> To change your list options, or to unsubscribe from the list, please 
>>>>>> visit
>>>>>> http://mail.opencms.org/mailman/listinfo/opencms-dev
>>>      
>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> This mail is send to you from the opencms-dev mailing list
>>>> To change your list options, or to unsubscribe from the list, please 
>>>> visit
>>>> http://mail.opencms.org/mailman/listinfo/opencms-dev
>>    
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> This mail is send to you from the opencms-dev mailing list
>> To change your list options, or to unsubscribe from the list, please 
>> visit
>> http://mail.opencms.org/mailman/listinfo/opencms-dev
>  
>





_______________________________________________
This mail is send to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://mail.opencms.org/mailman/listinfo/opencms-dev



More information about the opencms-dev mailing list