Skip to Content
0
Former Member
Oct 16, 2006 at 04:48 AM

nullpointer exception while reading properties from km content

34 Views

//java file

package TestKMApi;

import com.sapportals.htmlb.page.DynPage;

import com.sapportals.htmlb.page.PageException;

import com.sapportals.portal.htmlb.page.JSPDynPage;

import com.sapportals.portal.htmlb.page.PageProcessorComponent;

import com.sapportals.portal.prt.component.IPortalComponentRequest;

import com.sapportals.portal.security.usermanagement.IUser;

import com.sapportals.wcm.repository.IProperty;

import com.sapportals.wcm.repository.IPropertyName;

import com.sapportals.wcm.repository.IResource;

import com.sapportals.wcm.repository.PropertyName;

import com.sapportals.wcm.repository.ResourceContext;

import com.sapportals.wcm.repository.ResourceFactory;

import com.sapportals.wcm.util.uri.RID;

import com.sapportals.wcm.util.usermanagement.WPUMFactory;

public class TestKMApi extends PageProcessorComponent {

public DynPage getPage() {

return new TestDynPage();

}

public static class TestDynPage extends JSPDynPage {

public void doInitialization() {

}

public void doProcessAfterInput() throws PageException {

final String OriginProp = "Origin.Country";

final String CREATED_BY_PROP_PREFIX ="http://sapportals.com/xmlns/cm/";

final String try {

IPortalComponentRequest request =

(IPortalComponentRequest) this.getRequest();

IUser user = WPUMFactory.getUserFactory().getEP5User(request.getUser());

//IUser user= (IUser)request.getUser();

ResourceContext ctxt = new ResourceContext(user);

RID rid = RID.getRID("/documents");

IResource res =

ResourceFactory.getInstance().getResource(rid, ctxt);

IPropertyName propName =

new PropertyName(CREATED_BY_PROP_PREFIX, OriginProp);

IProperty p = res.getProperty(propName);

request.getComponentSession().putValue("Country",p.getStringValue());

} catch (Exception e) {

e.printStackTrace();

}

}

public void doProcessBeforeOutput() throws PageException {

this.setJspName("TestKMApi.jsp");

}

}

}

//xml file

<?xml version="1.0" encoding="utf-8"?>

<application>

<application-config>

com.sap.km.cm"/>

</application-config>

<components>

<component name="TestKMApi">

<component-config>

<property name="ClassName" value="TestKMApi.TestKMApi"/>

</component-config>

<component-profile/>

</component>

</components>

<services/>

</application>

//jsp file

<%@ page language="java" %>

<%@ page import="java.util.*"%>

<%@ page import="javax.servlet.http.*"%>

<%@ page import="com.sapportals.htmlb.*" %>

<%@ page import="javax.servlet.jsp.*" %>

<%@ page import ="com.sapportals.portal.prt.component.*"%>

<%

String hi="hi";

String text="text";

IPortalComponentRequest currentRequest =(IPortalComponentRequest)pageContext.getAttribute(javax.servlet.jsp.PageContext.REQUEST);

try{

text = currentRequest.getComponentSession().getValue("Country").toString();

}

catch(Exception e)

{

hi=e.toString();

}

%>

<%=text%>

<%=hi%>

I am getting java.lang.NullPointerException.

I have already set properties.

plz help me.