08-13-2012 04:51 AM
<items-list>
<item name="Espace invité"/>
<item name="Dictionnaire de données"/>
<item name="Sites"/>
<item name="Espaces Utilisateurs"/>
<item name="Human Factors"/>
</items-list>
import java.io.IOException;
import java.io.OutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchService;
import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.Format;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class getdocument extends AbstractWebScript
{
/**
* Content type.
*/
private static final String CONTENT_TYPE = Format.XML.mimetype() + ";charset=UTF-8";
@Override
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
{
// TODO Auto-generated method stub
String request = "PATH:\"/app:company_home/*\"";
ResultSet resulset = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,
SearchService.LANGUAGE_LUCENE, request);
try
{
res.setContentType(CONTENT_TYPE);
OutputStream out = res.getOutputStream();
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
// root elements
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("items-list");
doc.appendChild(rootElement);
for (NodeRef iNoderNodeRef : resulset.getNodeRefs())
{
Element elt = doc.createElement("item");
elt.setAttribute("name", (String) nodeService.getProperty(iNoderNodeRef, ContentModel.PROP_NAME));
rootElement.appendChild(elt);
}
// write the content on the XML stream
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(out);
transformer.transform(source, result);
}
catch (ParserConfigurationException pce)
{
throw new WebScriptException("exception", pce);
}
catch (TransformerException tfe)
{
throw new WebScriptException("exception", tfe);
}
}
private NodeService nodeService;
private SearchService searchService;
private FileFolderService fileFolderService;
/**
* @return the nodeService
*/
public NodeService getNodeService()
{
return nodeService;
}
/**
* @param nodeService
* the nodeService to set
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @return the searchService
*/
public SearchService getSearchService()
{
return searchService;
}
/**
* @param searchService
* the searchService to set
*/
public void setSearchService(SearchService searchService)
{
this.searchService = searchService;
}
/**
* @return the fileFolderService
*/
public FileFolderService getFileFolderService()
{
return fileFolderService;
}
/**
* @param fileFolderService
* the fileFolderService to set
*/
public void setFileFolderService(FileFolderService fileFolderService)
{
this.fileFolderService = fileFolderService;
}
}
08-14-2012 04:14 AM
08-14-2012 05:04 AM
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.