Skip to main content
1-Visitor
December 28, 2016
Question

how to read data of secondary content file using API.

  • December 28, 2016
  • 2 replies
  • 3387 views

Hello All,

I have a task in which i am to read data of attachment file(which is an xml file). can somebody guide me how i can achieve this. Is there any InputStream related API?

2 replies

1-Visitor
December 28, 2016

1.PNG

Do you mean you want to get the marked file(your file name is xxxx.xml) via API?

1-Visitor
December 29, 2016

Hello Chen,

Yes, basically i am using xml file for attachment, I am to read that xml tags in that file using APIs and generate UI based on those tags.

1-Visitor
December 30, 2016

I don't know how to read it online, but you can download it.

cadDoc is the host of the attachments.

EPMDocument latest = (EPMDocument) wt.vc.VersionControlHelper.service .allVersionsOf(cadDoc).nextElement();

ContentHolder holder = ContentHelper.service.getContents(latest);

Vector contents = ContentHelper.getContentListAll(holder);


Then you can traverse the contents then find the attachment and download it.

ContentServerHelper.service.writeContentStream((ApplicationData) contents.get(i), fullPath);


1-Visitor
December 28, 2016

I'm not sitting in front of my IDE, but I think this should about do it.

ContentHolder holder = (ContentHolder)new ReferenceFactory().getReference(String oid).getObject();

holder = wt.content.ContentHelper.service.getContents(holder);

final QueryResult contents = ContentHelper.service.getContentsByRole(holder,ContentRoleType.SECONDARY);

whlie(contents.hasMoreElements()) {

  ContentItem ci = (ContentItem)contents.nextElement();

  if(ci instanceof ApplicationData) {

  ApplicationData ad = (ApplicationData)ci;

  try(final InputStream is = wt.content.ContentServerHelper.service.findContentStream(ad)) {

  //get file info from ad

  final File temp = File.createTempFile("xxx","xxx");

  FileUtils.copyInputStreamToFile(is, temp);

  }

  }

}