cancel
Showing results for 
Search instead for 
Did you mean: 

How long WebDynpro deprecated methods/API's exists?

praveenkumar_kadi
Active Contributor
0 Kudos

Hi,

I am forced to use some deprecated methods like

IWDModifiableBinaryType in my application because of it's convenient to download a specific resource file (For: excel sheet from Sever). However I would like to replace this with recommended method: IWDResource. I am not sure How I use this method to replace following code. Please help.

IWDAttributeInfo aInfo = wdContext.getNodeInfo().getAttribute(IPrivateMYUploadView.IContextElement.EXCEL_SHEET);

IWDModifiableBinaryType binaryType =

(IWDModifiableBinaryType) aInfo.getModifiableSimpleType();

binaryType.setFileName(ExcelsheetPath);

binaryType.setMimeType(WDWebResourceType.XLS);

Currently with the above code, I am able to download an excel sheet sucessfully after creating an input stream (binary Type) to the context attribiute--link to download UI element. I am looking out to avoid this deprecated method somehow.

If someone have gone through similar type/know how it can be done using IWDResource, Please help.

Thanks

Praveen

Accepted Solutions (1)

Accepted Solutions (1)

pravesh_verma
Active Contributor
0 Kudos

Hi Praveen,

Please check this code:


// Please note that FileResource is value of the file source. I am getting this value using the element of a node.
// You can create a attribute fileResource and then can use its element to store the value of the file source.

IWDResource resource = element.getFileResource();
InputStream stream = resource.read(true);
String resourceName = resource.getResourceName();
String resourceExtn = resource.getResourceType().getFileExtension();

Here InputStream is - abstract class is the superclass of all classes representing an input stream of bytes.

I hope this solves your issue of getting the input stream using the IWDResource.

Thanks and Regards,

Pravesh

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

If you are accessing from remote machine you have to use the fully qualified name,....

You can achieve this by taking link to URL UI element and download a file from KM content.

Code how to do this

accessURI string will contain the full path try this code..

Assuming your folder location is /documents/xxx. chekc the sample code below.

IHierarchicalUri uri = null;
int localPort = 0;
String localhost = null;
String accessURI = null;
IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
com.sap.security.api.IUser sapUser = wdClientUser.getSAPUser();
user = WPUMFactory.getUserFactory().getEP5User(sapUser);
String location = "/documents/xxx";
IResourceContext resourceContext = new ResourceContext(user);
RID rid = RID.getRID(location);
IResource resource = ResourceFactory.getInstance().getResource(rid,resourceContext);
uri = ug.createAbsoluteUri(uriRef);
IWDRequest req = WDProtocolAdapter.getProtocolAdapter().getRequestObject();
if(req != null)
{
localhost = req.getServerName();
localPort = req.getServerPort();
}
if(uri != null)
{

accessURI = "http://"+localhost+":"+localPort+uri.getPath();
}

ICollection collection = (ICollection) resource;
IResourceList resourceList = collection.getChildren(); //Gives list of files and folders inside the KM location//
for(int i=0;i<resourceList.size();i++) {
IResource res = resourceList.get(i);
//Get the required info from the resource object and display
}

Hope this helps you..

Regards,

Saleem

praveenkumar_kadi
Active Contributor
0 Kudos

Hi Pravesh,

No LinkToURL is not the one I have to try....If I use that I can't get the excel sheet as server has the access not as enduser(me).

Server is the actor here. end user doesn't know from which location he is downloading the excel sheet.

So, we need to use IWDResource to do this.

Also It's a shared network path accessible only to the server. I am trying to know how we can use this path in IWDResource since IWDResource instance only accepts parameter of type IWDResource not string (If we try to pass an shared network path - ex: //usr/sap/some.xls, It passes as a string not as resource type, there comes cast error, Please test this FYI)

I appreciate someone's answer on this. I am leaving this thread for another day before closing it.

Thanks

Praveen

praveenkumar_kadi
Active Contributor
0 Kudos

Hi Pravesh,

Thanks for the reply.

Have you used "type as com.sap.ide.webdynpro.uielementdefinitions.Resource" for your FileResource context attribute. I think you have to..If you use that, How do you get file path as It's coming as a string.

(For://usr/sap/some.xls)

IWDResource resource = element.getFileResource();

I am particularly want to know how you decalre a file path(From the shared drive resource -//usr/sap/some.xls) and subsequent usage in the code till we download it. I think you are almost solving the issue. Please try answer this.

Thanks

Praveen

pravesh_verma
Active Contributor
0 Kudos

Hi Praveen,

File path can be whatever you have the file strcuture for your file. Forexample if that is located on some remote machine then yu can use the //FQDN/<COMPLETE_FILE_PATH>.

FQDN: Fully qualified domain name. You can get this value by using this command in command line.

tracert <IP Address of the machine>

Also if your requirement is just to download a excel from a path which you know, you can directly use the linktoURL UI element and give the source path as the path of your file. You can directly download the excel file using this.

I hope this solves the issue. Please revert back in case you have any further questions else kindly close the thread.

Thanks and Regards

Pravesh