cancel
Showing results for 
Search instead for 
Did you mean: 

Access Km repository dynamically from Web dynpro application

Former Member
0 Kudos

Hi experts,

I need to develop a web dynpro application where there is a link that should connect to a specific repository and pull up the particular document in a folder.

Based on one useful sdn thread, I am using the following code.

//@@begin imports

import java.io.ByteArrayInputStream;

import javax.swing.text.AbstractDocument.Content;

import com.l.wdp.IPrivateDynamicKMContentAccessView;

import com.sap.dictionary.runtime.ISimpleTypeModifiable;

import com.sap.security.api.IUser;

import com.sap.tc.webdynpro.progmodel.api.IWDAttributeInfo;

import com.sap.tc.webdynpro.progmodel.api.IWDModifiableBinaryType;

import com.sap.tc.webdynpro.progmodel.mime.ResourceFactory;

import com.sap.tc.webdynpro.services.sal.um.api.IWDClientUser;

import com.sap.tc.webdynpro.services.sal.um.api.WDClientUser;

import com.sapportals.wcm.repository.ICollection;

import com.sapportals.wcm.repository.IResource;

import com.sapportals.wcm.repository.IResourceFactory;

import com.sapportals.wcm.repository.ResourceContext;

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

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

//@@end

//@@begin documentation

//@@end

public class DynamicKMContentAccessView

{

/**

  • Logging location.

*/

private static final com.sap.tc.logging.Location logger =

com.sap.tc.logging.Location.getLocation(DynamicKMContentAccessView.class);

static

{

//@@begin id

String id = "$Id$";

//@@end

com.sap.tc.logging.Location.getLocation("ID.com.sap.tc.webdynpro").infoT(id);

}

/**

  • Private access to the generated Web Dynpro counterpart

  • for this controller class. </p>

*

  • Use <code>wdThis</code> to gain typed access to the context,

  • to trigger navigation via outbound plugs, to get and enable/disable

  • actions, fire declared events, and access used controllers and/or

  • component usages.

*

  • @.wdp.IPrivateDynamicKMContentAccessView for more details

*/

private final IPrivateDynamicKMContentAccessView wdThis;

/**

  • Root node of this controller's context. </p>

*

  • Provides typed access not only to the elements of the root node

  • but also to all nodes in the context (methods node<i>XYZ</i>())

  • and their currently selected element (methods current<i>XYZ</i>Element()).

  • It also facilitates the creation of new elements for all nodes

  • (methods create<i>XYZ</i>Element()). </p>

*

  • @see comwdp.IPrivateDynamicKMContentAccessView.IContextNode for more details.

*/

private final IPrivateDynamicKMContentAccessView.IContextNode wdContext;

/**

  • A shortcut for <code>wdThis.wdGetAPI()</code>. </p>

  • Represents the generic API of the generic Web Dynpro counterpart

  • for this controller. </p>

*/

private final com.sap.tc.webdynpro.progmodel.api.IWDViewController wdControllerAPI;

/**

  • A shortcut for <code>wdThis.wdGetAPI().getComponent()</code>. </p>

  • Represents the generic API of the Web Dynpro component this controller

  • belongs to. Can be used to access the message manager, the window manager,

  • to add/remove event handlers and so on. </p>

*/

private final com.sap.tc.webdynpro.progmodel.api.IWDComponent wdComponentAPI;

public DynamicKMContentAccessView(IPrivateDynamicKMContentAccessView wdThis)

{

this.wdThis = wdThis;

this.wdContext = wdThis.wdGetContext();

this.wdControllerAPI = wdThis.wdGetAPI();

this.wdComponentAPI = wdThis.wdGetAPI().getComponent();

}

//@@begin javadoc:wdDoInit()

/** Hook method called to initialize controller. */

//@@end

public void wdDoInit()

{

//@@begin wdDoInit()

IPrivateDynamicKMContentAccessView.IFileNodeElement fileelement = null;

try {

fileelement = wdContext.nodeFileNode().createFileNodeElement();

if (fileelement != null) {

wdContext.nodeFileNode().bind(fileelement);

IWDAttributeInfo attInfo =

wdContext.nodeFileNode().getNodeInfo().getAttribute(

"FileData");

ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();

IWDModifiableBinaryType binaryType =

(IWDModifiableBinaryType) type;

// wdContext.nodeFilenode().addElement(fileelement);

} else {

wdComponentAPI.getMessageManager().reportSuccess("error");

}

} catch (Exception e) {

wdComponentAPI.getMessageManager().reportSuccess(

" catch error" + e);

}

//@@end

}

//@@begin javadoc:wdDoExit()

/** Hook method called to clean up controller. */

//@@end

public void wdDoExit()

{

//@@begin wdDoExit()

//@@end

}

//@@begin javadoc:wdDoModifyView

/**

  • Hook method called to modify a view just before rendering.

  • This method conceptually belongs to the view itself, not to the

  • controller (cf. MVC pattern).

  • It is made static to discourage a way of programming that

  • routinely stores references to UI elements in instance fields

  • for access by the view controller's event handlers, and so on.

  • The Web Dynpro programming model recommends that UI elements can

  • only be accessed by code executed within the call to this hook method.

*

  • @param wdThis Generated private interface of the view's controller, as

  • provided by Web Dynpro. Provides access to the view controller's

  • outgoing controller usages, etc.

  • @param wdContext Generated interface of the view's context, as provided

  • by Web Dynpro. Provides access to the view's data.

  • @param view The view's generic API, as provided by Web Dynpro.

  • Provides access to UI elements.

  • @param firstTime Indicates whether the hook is called for the first time

  • during the lifetime of the view.

*/

//@@end

public static void wdDoModifyView(IPrivateDynamicKMContentAccessView wdThis, IPrivateDynamicKMContentAccessView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

{

//@@begin wdDoModifyView

//@@end

}

//@@begin javadoc:onActionSubmit(ServerEvent)

/** Declared validating event handler. */

//@@end

public void onActionSubmit(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionSubmit(ServerEvent)

try {

IWDAttributeInfo attributeInfo = wdContext.nodeFileNode().getNodeInfo().getAttribute("FileData") ;

IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) attributeInfo.getModifiableSimpleType();

// IPrivateAdd_Edit_PublicationDetails.IVnFldNamesPubElement element = wdContext.currentVnFldNamesPubElement();

byte[] fileByteArray = wdContext.currentFileNodeElement().getFileData();

IWDClientUser wdClientUser = WDClientUser.getCurrentUser();

IUser sapUser = wdClientUser.getSAPUser();

// create an ep5 user from the retrieved user

IUser ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser);

ResourceContext resourseContext = new ResourceContext(ep5User);

/*path to KM in the variable path */

RID pathRID = RID.getRID("/documents/Public Documents");

IResourceFactory resourseFactory = ResourceFactory.getInstance();

ICollection collection = (ICollection) resourseFactory.getResource(pathRID,resourseContext);

ByteArrayInputStream byetArrStream = new ByteArrayInputStream( fileByteArray ) ;

Content con = new Content( byetArrStream , "application/octet-stream", -1,"UTF-16");

IResource resource = collection.createResource(binaryType.getFileName(), null, con);

long contentLen = resource.getContent().getContentLength() ;

if ( contentLen < 0)

{

}else

{

wdComponentAPI.getMessageManager().reportSuccess("File uploaded is "+binaryType.getFileName());

}

} catch (Exception e) {

wdComponentAPI.getMessageManager().reportSuccess("error" +e.toString() );

}

//@@end

}

/*

  • The following code section can be used for any Java code that is

  • not to be visible to other controllers/views or that contains constructs

  • currently not supported directly by Web Dynpro (such as inner classes or

  • member variables etc.). </p>

*

  • Note: The content of this section is in no way managed/controlled

  • by the Web Dynpro Designtime or the Web Dynpro Runtime.

*/

//@@begin others

//@@end

}

I included 3 jar files additionally

security.api.jar

framework.jar

public_api.jar

I dont see anymore errors under the code now, but on the extreme top left corner in the view implementation i see an error synbol showing the following message:

The compilation unit indirectly references the missing type com.sapportals.portal.security.usermanagement.IUserFactory(typically some required class file is referencing a type outside the classpath)

How can I remove this error so that I can test my application?

Thanks

Anjana

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi ,

check this...

webdynpro reference->sharing reference>add the following

PORTAL:sap.com/com.sap.km.application

Regards,

P.Manivannan

Former Member
0 Kudos

Hi,

additionally you import following jar files

1.com.sap.security.api.ep5

2.com.sap.security.api

3.prtapi

4.bc.rf.framework_api

5.bc.rf.global.service.urlgenerator_api

6.bc.sf.framework_api

7.bc.util.public_api

check in your code following files are imported or not

import java.io.ByteArrayInputStream;

import com.sap.dictionary.runtime.ISimpleTypeModifiable;

import com.sap.tc.webdynpro.progmodel.api.IWDAttributeInfo;

import com.sap.tc.webdynpro.progmodel.api.IWDModifiableBinaryType;

import com.sap.tc.webdynpro.services.sal.um.api.IWDClientUser;

import com.sap.tc.webdynpro.services.sal.um.api.WDClientUser;

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

import com.sapportals.wcm.repository.Content;

import com.sapportals.wcm.repository.ICollection;

import com.sapportals.wcm.repository.IResource;

import com.sapportals.wcm.repository.IResourceFactory;

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;

Regards,

P.Manivannan.

Former Member
0 Kudos

Hi Manivannan,

My application is missiong some of the jar files u have specified. Hopefully it should solve the problem.

Thanks

Anjana

former_member751941
Active Contributor