Skip to Content
author's profile photo Former Member
Former Member

RID and getContent()

Hello,

I have th following code:

...

...

...

public void doContent(

IPortalComponentRequest request,

IPortalComponentResponse response)

{

IResource aResource = null;

ResourceContext rContext = new ResourceContext(aUser);

RID aRid = new RID("/documents/test/myfile.xml");

try

{

IResourceFactory aResourceFactory = ResourceFactory.getInstance();

aResource =

ResourceFactory.getInstance().getResource(aRid, rContext);

IContent con = aResource.getContent();

}

catch (AccessDeniedException ex)

{

ex.getLocalizedMessage();

}

catch (com.sapportals.wcm.repository.ResourceException ex)

{

ex.getLocalizedMessage();

}

}

...

...

...

myfile.xml has just a line like "test"

How could I read the myfile.xml content ? I want to get the above string.

Thanks for any feeback

Regards.

Altafin

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Dec 10, 2004 at 03:50 PM

    Hi Altafin,

    1.) Just for the code being beautiful: Replace RID aRid = new RID("/documents/test/myfile.xml"); by RID aRid = RID.getRID("/documents/test/myfile.xml");

    2.)

    InputStream xmlIS = con.getInputStream();
    BufferedReader br =
        new BufferedReader(new InputStreamReader(xmlIS));
    String yourLine = br.readLine();
    br.close();
    

    etc. pp.

    Hope it helps

    Detlev

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Altafin,

      sorry, a small mistake in my code: readLine() only reads lines ending with cr/lf/cr-lf.

      So if the one (last) line is not guaranteed to end by one of these codes, code is a bit more complex (but now also complete file is read, for your convenience):

      InputStream xmlIS = con.getInputStream();
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      byte[] buffer = new byte[4096]; // as you like
      int bytesread = 0;
      while ((bytesread = in.read(buffer)) != -1) {
        out.write(buffer, 0, bytesread);
      }
      String myFile = out.toString("UTF-8"); // as saved  
      

      Hope it helps

      Detlev

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.