Marc Orciuch wrote:
>Be aware of some outstanding problems with the current
CastorRegistryService
>when registry is changed programatically. I also have an application which
>manipulates portlet registry entries at runtime. It was orignally
developed
>using 1.3a1 code but when ported to 1.3a2, I started experiencing some
>problems. One of the problems has to do with adding new entries (see
>Bugzilla Bug 5091). I sumbitted a patch but the fix seems to be a lower
>priority right now. Another problem that I ran into has to do with
removing
>registry entries - they seem to mysteriously come back after the portal is
>restarted.
Hi Marc.
I solved the problem for my needs. It�s a quick and dirty hack ! So use
it only if you need it ;-)
I just added the following code to the getContent function in
VelocityPortlet.java:
---------------------------------------------------------- snip 1
-------------------------------------------------
String template = getPortletConfig().getInitParameter("template");
String actionName = getPortletConfig().getInitParameter("action");
String myURI = rundata.getRequest().getRequestURI();
// only need refresh if user tries customizing his page
if ( actionName.equals("portlets.CustomizeSetAction") && (
myURI.indexOf("add") > -1 ) )
{
CastorRegistryService fr = null;
fr
=(CastorRegistryService)TurbineServices.getInstance().getService(RegistryService.SERVICE_NAME);
ResourceService serviceConf = null;
serviceConf =
((TurbineServices)TurbineServices.getInstance()).getResources(RegistryService.SERVICE_NAME);
String directory = serviceConf.getString("directory");
try
{
if ( fr != null )
{
org.apache.jetspeed.om.registry.base.BaseRegistry portletsreg = new
org.apache.jetspeed.om.registry.base.BaseRegistry();
portletsreg =
(org.apache.jetspeed.om.registry.base.BaseRegistry)fr.get("Portlet");
Iterator myiter = portletsreg.listEntryNames();
Vector tempvect = new Vector();
List mylist = tempvect;
// generate a list of all portlets in memory
// for my purpose only portlets with "id" in
// their names
while (myiter.hasNext())
{
String myreg = (String)myiter.next();
if ( myreg.indexOf("id") > -1 )
{
mylist.add(myreg);
}
}
int listlen = mylist.size();
int counter;
for ( counter=0 ; counter<listlen; counter++ )
{
String myregnew = (String)mylist.remove(listlen -
counter - 1);
// delete all relevant portlets from memory to
ship around the bug
// [Bug 5627] New: - Removing registry entries
from the
// .xreg file does not remove form memmory
portletsreg.removeEntry(myregnew);
}
// Have to use a windows server :-(
String fixeddirectory = myreplace ( directory, "/", "\\",
true );
// for my "myreplace" function see below
// my portlets are in local-portlets.xreg
fr.loadFragment(fixeddirectory+"local-portlets.xreg");
fr.saveFragment(fixeddirectory+"local-portlets.xreg");
fr.refresh();
Log.debug("Debug: xregs refreshed !");
}
}
catch (Exception e)
{
Log.debug("NPE:\n"+e);
}
-------------------------------------------------------------------
SNIP1 -----------------------------------------------
--------------------------------------------------------------------
SNIP 2 ----------------------------------------------
public static String myreplace(String origstring, String o, String n,
boolean all) {
StringBuffer orig = new StringBuffer();
orig.append(origstring);
if (orig == null || o == null || o.length() == 0 || n == null)
throw new IllegalArgumentException("Null or zero-length String");
int i = 0;
while (i + o.length() <= orig.length()) {
if (orig.substring(i, i + o.length()).equals(o)) {
orig.replace(i, i + o.length(), n);
if (!all)
break;
else
i += n.length();
} else
i++;
}
return(orig.toString());
}
------------------------------------------------------------------------
SNIP 2 ----------------------------------------------------
regards
meik
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>