Just FYI:
This code is just for demonstration purpose and is optimized to be readable and 
to understand the basic concepts of how to work with CMIS.

There are many places for optimizations when using in production like closing 
the resources in a finally statement etc
(just wrote it down in half an hour ;) )

Anyway I hope it helps you as a starting point ;)

Cheers
Sascha

Am 07.05.2015 um 21:22 schrieb Sascha Homeier 
<shome...@meyle-mueller.de<mailto:shome...@meyle-mueller.de>>:

Hi Matheus,

as we have some customers which are building own client implementations to 
connect to our DAM system via CMIS I have setup a very minimalistic CMIS client 
sample code for them which also demonstrates the use case you mentioned.

You can check it out from GitHub here:
https://github.com/shomeier/cmis-client-sample

It is only about 250 lines of code and it is checked in as an Eclipse project 
so you should be able to easily import it into your Eclipse IDE.
The connection parameters like credentials and cmis endpoint url are read from 
a properties file.
The configuration is explained in the README at the github url above.

In general you simply have to store the InputStream of the ContentStream of 
your CmisDocument to a File.
You can find a simple implementation of how this could be achieved at 
de.apollon.cmis.client.sample.CmisClient#writeContentStreamToFile(ContentStream 
cs):

——— Java code starts here ——

public void writeContenStreamToFile(ContentStream cs)
{
InputStream in = cs.getStream();
String targetPath = this.props.getProperty("temp_path") + File.separator + 
cs.getFileName();
File file = new File(targetPath);
System.out.println("Writing stream to file: " + file.getAbsolutePath());
try
{
OutputStream out = new FileOutputStream(file);
byte[] buf = new byte[1024];
int len;
while (( len = in.read(buf) ) > 0)
{
out.write(buf, 0, len);
}
out.close();
in.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}

——— Java code ends here ——


This method is called like:
cmisClient.writeContenStreamToFile(cmisDocument.getContentStream());

To summarize it up:

——— Java code starts here ----

// get the ContentStream of the CmisDocument
ContentStream contentStream = cmisDocument.getContentStream();

// get the InputStream of the ContentStream of the CmisDocument
InputStream stream = contentStream.getStream();

// create the File where you want to store the InputStream of the CmisDocument
// here we use the filename of the ContentStream of the CmisDocument but we 
could also choose another
File file = new File("/usr/local/" + contentStream.getFileName());

// write stream to file
try
{
OutputStream out = new FileOutputStream(file);
byte[] buf = new byte[1024];
int len;
while (( len = stream.read(buf) ) > 0)
{
out.write(buf, 0, len);
}
out.close();
stream.close();
}
catch (Exception e)
{
e.printStackTrace();
}

——— Java code ends here ----


Hope this helps.


Cheers
Sascha

Am 07.05.2015 um 20:34 schrieb Matheus de Oliveira Barreto 
<math...@foxfly.com.br<mailto:math...@foxfly.com.br>>:

Hey guys, how are you doing?


I have some doubts developing with Apache Chemistry CMIS and I think that this 
is the right place to ask. If not, please excuse me in advance and if possible, 
just tell me where to go.


So, I've been working on a class to do some basic actions on a CMIS repository. 
My main goals is to connect to and download files from a CMIS repository 
(already done with FileUtils method Download) and get this file as a Java IO 
File (so my code can work with it or anything like that). There is exactly 
where my problem is. How do I get this CMIS Document (that I know is a file, 
already checked for the type) to be a Java IO File? A direct cast doesn't work, 
of course, I believe because of the structure of the objects... So, is there a 
class or a method that can help me with this?


I've tried to find it on old emails and also on the documentation, but I'm not 
a very experienced programmer, and if there is something already said or 
written about it in a place where I should have found it on my own, I apologize.


Thanks to all you guys in advance and I hope I can help people in the future 
too on Apache Chemistry doubts or problems too.


Regards,

Atenciosamente,
Matheus Barreto
eMail          
math...@foxfly.com.br<mailto:math...@foxfly.com.br><mailto:j...@foxfly.com.br>?
Comercial  +55 11 5503-6710
WebSite     http://www.foxfly.com.br<http://www.foxfly.com.br/>

foxfly IT & Marketing
Av. Das Nações Unidas, 12995 - 10º andar
CEP 04578-000, Brooklin Novo
São Paulo, SP


Reply via email to