private void doActionMerge() throws ApplicationException, PageException, IOException, DocumentException {
if(source==null && params==null && directory==null)
throw new ApplicationException("at least one of the following constellation must be defined" +
" attribute source, attribute directory or cfpdfparam child tags");
if(destination==null && StringUtil.isEmpty(name,true))
throw new ApplicationException("at least one of the following attributes must be defined " +
"[destination,name]");
if(destination!=null && !overwrite)
throw new ApplicationException("destination file ["+destination+"] already exists");
ArrayList docs = new ArrayList();
PDFDocument doc;
boolean isListing=false;
// source
if(source!=null) {
if(Decision.isArray(source)) {
Array arr = Caster.toArray(source);
int len = arr.size();
for(int i=1;i<=len;i++) {
docs.add(doc=toPDFDocument(arr.getE(i),password,null));
doc.setPages(pages);
}
}
else if(source instanceof String) {
String[] sources = ListUtil.toStringArrayTrim(ListUtil.listToArrayRemoveEmpty((String)source, ','));
for(int i=0;i<sources.length;i++) {
docs.add(doc=toPDFDocument(sources[i],password,null));
doc.setPages(pages);
}
}
else docs.add(toPDFDocument(source,password,null));
}
boolean destIsSource = false;
// params
if(directory!=null && !directory.isDirectory()) {
if(!directory.exists())
throw new ApplicationException("defined attribute directory does not exist");
throw new ApplicationException("defined attribute directory is not a directory");
}
if(params!=null) {
Iterator it = params.iterator();
PDFParamBean param;
while(it.hasNext()) {
param=(PDFParamBean) it.next();
docs.add(doc=toPDFDocument(param.getSource(), param.getPassword(),directory));
doc.setPages(param.getPages());
}
}
else if(directory!=null) {
isListing=true;
Resource[] children = ResourceUtil.listResources(directory, filter);
if(ascending) {
for(int i=children.length-1;i>=0;i--) {
if(destination!=null && children[i].equals(destination)) destIsSource=true;
docs.add(doc=toPDFDocument(children[i],password,null));
doc.setPages(pages);
}
}
else {
for(int i=0;i<children.length;i++) {
if(destination!=null && children[i].equals(destination)) destIsSource=true;
docs.add(doc=toPDFDocument(children[i],password,null));
doc.setPages(pages);
}
}
}
int doclen=docs.size();
if(doclen==0)
throw new ApplicationException("you have to define at leat 1 pdf file");
// output
OutputStream os=null;
if(!StringUtil.isEmpty(name) || destIsSource){
os=new ByteArrayOutputStream();