cancel
Showing results for 
Search instead for 
Did you mean: 

Access to a folder in km content in the portal

Former Member
0 Kudos

can i access with web dynpro to get xml documents in a folder located in the km in the portal? do you have code, tutorials or info about that (if is possible)

Thanks a lot

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

here is some source code that may help you:

		
try {
  com.sapportals.portal.security.usermanagement.IUser
   ep5User = WPUMFactory.getServiceUserFactory().getServiceUser(QUICKLINK_USER);
  ResourceContext context = new ResourceContext(ep5User);

  /*Give the path to KM in the variable path */
  RID rid = RID.getRID("folder/path");
  IResourceFactory factory = ResourceFactory.getInstance();
  ICollection folder = (ICollection) factory.getResource(rid, context);

  IResource resource = ResourceFactory.getInstance().getResource(RID.getRID("folder/path/file.xml"), context);	

  if (resource != null) {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = dbFactory.newDocumentBuilder();
    Document document = builder.parse(resource.getUnfilteredContent().getInputStream());

    // Here you can do your XML Stuff
  else {
    // File not found error handling goes here
  }

Hope it helps as a start point.

Have a nice weekend,

Frank

Answers (2)

Answers (2)

sajith_p
Participant
0 Kudos

Hi

I am getting java.lang.ClassCastException during casting from IResource to ICollection while running this code

try {

IWDClientUser wdClientUser1 = WDClientUser.getCurrentUser();

com.sap.security.api.IUser sapUser1 = wdClientUser1.getSAPUser();

com.sapportals.portal.security.usermanagement.IUser

ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser1);

ResourceContext context = new ResourceContext(ep5User);

IResourceFactory resourceFactory = ResourceFactory.getInstance();

/*Give the path to KM in the variable path */

RID rid = RID.getRID(wdContext.currentContextElement().getPath());

wdComponentAPI.getMessageManager().reportSuccess("rid "+rid);

IResource resource = resourceFactory.getResource(rid, context);

IResourceFactory factory = ResourceFactory.getInstance();

try{

ICollection folder = (ICollection)resource;

// wdComponentAPI.getMessageManager().reportSuccess("folder "+folder);

// IResourceList resourceList = folder.getChildren();

// IResourceListIterator resourceListIterator = resourceList.listIterator();

resource = ResourceFactory.getInstance().getResource(RID.getRID(wdContext.currentContextElement().getPath()), context);

wdComponentAPI.getMessageManager().reportSuccess("resource "+resource);

if (resource != null) {

DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = dbFactory.newDocumentBuilder();

Document document = builder.parse(resource.getUnfilteredContent().getInputStream());

}

// Here you can do your XML Stuff

else {

// File not found error handling goes here

}

}catch(Exception e1){

wdComponentAPI.getMessageManager().reportSuccess("e1 "+e1);

}

}catch(Exception e)

{

wdComponentAPI.getMessageManager().reportSuccess("err "+e);

}

please reply

Sajith

former_member182372
Active Contributor
0 Kudos

Hi Jose,

Did you check Tutorial "Using Knowledge Management Functions in Web Dynpro (26)" https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webdynpro/tutorial on using knowledge management functions in web dynpro - 26.htm

Best regards, Maksim Rashchynski.