[opencms-dev] OpenCms External link change programatically

Faisal Irfan faisalirfan at jabssolutions.com
Mon Sep 19 20:42:08 CEST 2011


HellO!

      I have to edit External links whenever something is published or a new external link is created, for when something is published I am doing following:


      	public void publishProject(CmsObject cms, CmsPublishList arg1,	int arg2, I_CmsReport arg3) {
			try {
		        
	                List links = cms.readResources("/", CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireType(CmsResourceTypePointer.getStaticTypeId()));
			        Iterator iterator = links.iterator();
		            HashMap brokenLinks = new HashMap();
	                for (int i = 1; iterator.hasNext(); i++) {
	                	String linkFIlePath = cms.getSitePath((CmsResource) iterator.next());
	                    CmsFile link = cms.readFile(linkFIlePath); 
 	                    String linkUrl = new String(link.getContents());
 	                    cms.getRequestContext().removeSiteRoot(linkUrl); 
 	                    link.setContents((("/myfolder")+linkUrl).getBytes());
 	                    cms.writeFile(link); 
 	                    cms.unlockResource(link);
 	                 	
	                } 
	              
		        } catch (Exception ee) {
		        }
		} 

but this does not make any change (does not change the link contents) any help it's kinda SOS


-- 
Regards

Faisal Irfan

JABS SOLUTIONS, Pakistan

Direct +92-312-5362438 

E-Mail:  faisalirfan at jabssolutions.com




More information about the opencms-dev mailing list