Thursday, March 11, 2010

SAP Portal - Create a Resource List Filter

There are many articles on Resource List Filter on web but few discussed how to create it in NWDS. Here are my steps on NWDS 7.0.
  1. Create a Portal Application in NWDS.
  2. Right click the project, New > Other... > Repository Framework 7.1.5 > Repository Filter Wizard
  3. Select NW04, check off Generate classpath (the generation didn't work for me), enter class name and package name
  4. A NamespaceFilter is created. It is not what I want. So I replace the class with the following source

import com.sapportals.wcm.WcmException;
import com.sapportals.wcm.repository.IProperty;
import com.sapportals.wcm.repository.IResource;
import com.sapportals.wcm.repository.IResourceList;
import com.sapportals.wcm.repository.PropertyName;
import com.sapportals.wcm.repository.service.layout.customizing.IParameters;
import com.sapportals.wcm.service.resourcelistfilter.IResourceListFilter;

/**
* @version 1.0
*/
public class NotificationFilter implements IResourceListFilter {

/**
* Returns a new instance of the resource list filter.
*/
public IResourceListFilter getNewInstance() {
return new NotificationFilter();
}

/**
* Filters the resource list
*/
public void filterResourceList(IResourceList list, IParameters parameters) throws WcmException {
IResource resource = null;
IProperty prop = null;
for (int i = list.size() - 1; i >= 0; i--) {
resource = list.get(i);
prop = resource.getProperty(PropertyName.createContentLength());
if (prop != null && prop.getLongIntValue() > 102400) { // remove resources greater than 100kB
list.remove(resource);
}
}
}

}


I have downloaded all 7.0.18 libraries to a local directory and defined it as PORTAL_HOME. So here is my project classpath.
  • ECLIPSE_HOME/plugins/com.sap.ep.applicationDevelopment_7.00/prtapi.jar
  • PORTAL_HOME/com.sap.netweaver.bc.util/lib/bc.util.public_api.jar
  • PORTAL_HOME/com.sap.km.cm.service/lib/km.shared.service.resourcelistfilter_api.jar
  • PORTAL_HOME/com.sap.netweaver.bc.rf/lib/bc.rf.framework_api.jar
  • PORTAL_HOME/com.sap.km.cm.repository.service.base/lib/km.shared.repository.service.layout_api.jar
  • PORTAL_HOME/com.sap.netweaver.bc.crt/lib/bc.crt_api.jar
Done.

No comments: