03-24-2009 11:53 AM
public class GenDocActionExecuter extends ActionExecuterAbstractBase {
/** The logger */
private static Log logger = LogFactory.getLog("xxx.yyy");
/** The name of the action */
public static final String NAME = "gen_doc_eds-action";
/** The parameter names */
public static final String PARAM_XML_INPUT = "param-xml-input";
public static final String PARAM_DESTINATION_FILE = "param_destination-file";
public static final String PARAM_DESTINATION_FOLDER = "param_destination-folder";
/** Standard Alfresco manager allowing manipulating Alfresco object */
private ContentService contentService = null;
private NodeService nodeService = null;
/**
*
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action,
* org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
logger.debug("GenDocActionExecuter entering …");
if (!nodeService.exists(actionedUponNodeRef)) {
logger.error("GenDocActionExecuter template doesn't exist: " + actionedUponNodeRef.toString());
return;
}
/* get the parameter of the action */
String xmlInput = (String) action.getParameterValue(PARAM_XML_INPUT);
logger.debug("GenDocActionExecuter —> xmlInput " + xmlInput);
String fileName = (String) nodeService.getProperty(actionedUponNodeRef,
ContentModel.PROP_NAME);
logger.debug("GenDocActionExecuter —> fileName " + fileName);
// Get a reader, then ZipInputStream on the template
// ————————————————–
ContentReader reader = contentService.getReader(actionedUponNodeRef,
ContentModel.PROP_CONTENT);
InputStream in = reader.getContentInputStream();
ZipInputStream zin = new ZipInputStream(in);
// Get a writer, then a ZipOutputStrem on the generated document
// ————————————————————
String sdestinationFolder = (String) action
.getParameterValue(PARAM_DESTINATION_FOLDER);
String destinationFile = (String) action
.getParameterValue(PARAM_DESTINATION_FILE);
NodeRef nodeRef= ???? getNodeRef à partir de sdestinationFolder et destinationFile ?????
ContentWriter writer = contentService.getWriter(nodeRef,
ContentModel.PROP_CONTENT, true);
OutputStream outStream = writer.getContentOutputStream();
ZipOutputStream out = new ZipOutputStream(outStream);
byte[] buf = new byte[1024];
try {
ZipEntry entry = zin.getNextEntry();
while (entry != null) {
String name = entry.getName();
logger.debug("Extracting: " + name);
out.putNextEntry(new ZipEntry(entry.getName()));
OutputStream tempOut = null;
if (name.equals("customXml/item1.xml")) {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
tempOut = byteOut;
} else {
tempOut = out;
}
int len;
while ((len = zin.read(buf)) > 0) {
tempOut.write(buf, 0, len);
}
if (name.equals("customXml/item1.xml")) {
tempOut.write(xmlInput.getBytes("utf-8"));
}
entry = zin.getNextEntry();
}
zin.close();
out.close();
} catch (UnsupportedEncodingException e) {
logger.error("Error generating document", e);
} catch (IOException e) {
logger.error("Error generating document", e);
}
logger.debug("GenDocActionExecuter ending …");
}
03-24-2009 01:03 PM
03-24-2009 01:32 PM
03-24-2009 01:54 PM
03-24-2009 02:04 PM
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.