02-08-2008 05:08 AM
02-08-2008 05:36 AM
public static boolean writeXML(OutputStream os, String firstName, String lastName ) throws Exception
{
// Start the session
try{ AuthenticationUtils.startSession(USERNAME, PASSWORD);
} catch(AuthenticationFault af)
{
System.out.println("authentication failed!");
}
List<GenericData> lijst;
//filename for the document
String filename = lastName+"_"+firstName+".xml";
// what kind of file is it?
String filetype = "text/xml";
try {
// get classification Service
ClassificationServiceSoapBindingStub classificationService = WebServiceFactory.getClassificationService();
ContentServiceSoapBindingStub contentService =WebServiceFactory.getContentService();
//create the parentReference
ParentReference parentReference = new ParentReference(STORE, null, xmlLocation ,ASSOC_CONTAINS, ASSOC_CONTAINS);
NamedValue[] properties = new NamedValue[1];
NamedValue contentName = Utils.createNamedValue(Constants.PROP_NAME,lastName+"_"+firstName+".xml" );
properties[0] = contentName;
CMLCreate create = new CMLCreate("1", parentReference, null, null, null, Constants.TYPE_CONTENT, properties);
CML cml = new CML();
cml.setCreate(new CMLCreate[]{create});
Predicate predicate = new Predicate(new Reference[]{parentReference}, null, null);
UpdateResult[] result;
RepositoryServiceSoapBindingStub repositoryService =WebServiceFactory.getRepositoryService();
Query query = new Query();
query.setLanguage("lucene");
/*The referenced Query statement is using "*" for finding all files. This is because I couldn't seem to get correct results by using the Lucene
search implemented by the SDK while searching for a specific file. This might be a bug because even copy-pasting it from the Nodebrowser wouldn't do the trick in every
situation */
query.setStatement("PATH:\""+parentReference.getPath()+"/*"+"\"");
System.out.println(query.getStatement());
ResultSet rs = repositoryService.query(STORE, query, true).getResultSet();
Reference queryRef;
if(rs.getTotalRowCount()> 0 )
{
ResultSetRow [] rows = rs.getRows();
for(ResultSetRow rowke : rows)
{
int q = 0;
for(int i = 0;i<rowke.getColumns().length;i++)
{
System.out.println(rowke.getColumns(i).getValue());
if(rowke.getColumns(i).getValue().equalsIgnoreCase(filename))
{
queryRef = new Reference(STORE, rowke.getNode().getId(), null);
System.out.println("Ik ben hier geraakt dus ik heb het fileke gevonden!");
cml = new CML();
Predicate queryPredicate = new Predicate(new Reference[]{queryRef},null,null);
CMLUpdate cmlupdate = new CMLUpdate(properties,queryPredicate, null);
cml.setUpdate(new CMLUpdate[]{cmlupdate});
//deleteRepoFile(queryRef);
}
}
q++;
}
}
result = WebServiceFactory.getRepositoryService().update(cml);
int i = 0;
Reference testRef;
// Get the created node and create the format
Reference newContentNode = result[0].getDestination();
ContentFormat format = new ContentFormat(filetype, "UTF-8");
ByteArrayOutputStream bao = (ByteArrayOutputStream)os;
byte[] bytes = bao.toByteArray();
// Write the content
WebServiceFactory.getContentService().write(newContentNode, Constants.PROP_CONTENT, bytes, format);
// Predicate predicate = new Predicate("rls:city",titledProps,new Reference[]{newContentNode}, "1");
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
AuthenticationUtils.endSession();
return true;
}
}
public static InputStream getSerializedData(String firstName,String lastName)
{
ObjectInputStream ois = null;
try {
AuthenticationUtils.startSession(USERNAME, PASSWORD);
}catch(AuthenticationFault af)
{
System.out.println("Invalid Credentials");
}
Content [] content=null;
ParentReference parentReference = new ParentReference(STORE, null, WriteFileWS.xmlLocation ,ASSOC_CONTAINS, ASSOC_CONTAINS);
Reference queryRef=null;
if(WriteFileWS.testHomeExists(parentReference))
{
Query query = new Query();
query.setLanguage("lucene");
query.setStatement("PATH:\""+parentReference.getPath()+"/*"+"\"");
//werkt echt ni! –>query.setStatement("PATH:\""+parentReference.getPath()+"/{http://www.alfresco.org/model/content/1.0}name'\''Change_x0020_CV'+'\"");
System.out.println(query.getStatement());
RepositoryServiceSoapBindingStub repositoryService =WebServiceFactory.getRepositoryService();
ResultSet rs=null;
try {
rs = repositoryService.query(STORE, query, true).getResultSet();
}catch (RepositoryFault rf)
{
}catch(RemoteException re)
{
}
if(rs.getTotalRowCount()> 0 )
{
boolean beenhere = false;
ResultSetRow [] rows = rs.getRows();
for(ResultSetRow rowke : rows)
{
int q = 0;
for(int i = 0;i<rowke.getColumns().length;i++)
{
System.out.println(rowke.getColumns(i).getValue()+"\t"+q+"\t"+i);
if(rowke.getColumns(i).getValue().equals(lastName+"_"+firstName+".xml"))
{
queryRef = new Reference(STORE, rowke.getNode().getId(), null);
System.out.println("Ik ben hier geraakt dus ik heb het fileke gevonden!");
beenhere=true;
// break; //TODO comment the break statement if situation got worse!
}
else if(beenhere==false)
{
queryRef = null;
}
}
q++;
}
}
} else
{
System.out.println("User Home Does not Exist!");
//TODO Misschien deze <h:message> returnen naar de bean met getFacesContext() implementatie?
return null;
}
if(queryRef!=null)
{
Predicate predicate = new Predicate(new Reference[]{queryRef}, STORE, null);
try {
content = WebServiceFactory.getContentService().read(predicate, Constants.PROP_CONTENT);
}catch(ContentFault cf)
{
//no stacktrace or action required.
}catch(RemoteException re)
{
//no stacktrace or action required.
}
System.out.println(content[0].getLength());
return ContentUtils.getContentAsInputStream(content[0]);
}
System.out.println("No matching file found!");
return null;
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.