Page 1 of 1

Split FileName from the path (get only fileName)

PostPosted:Fri Apr 21, 2023 6:49 am
by nishant8900
Hi, Please kinldy look problem carefully.
We are using 6.3CE
Code: Select all
import com.openkm.bean.*;
import com.openkm.util.*;
import com.openkm.api.*;
List al = new ArrayList();
List<Document> doc = new ArrayList<Document>();
    doc = OKMDocument.getInstance().getChildren(null, "/okm:root/abc");

for (Document abc : doc)
{
    Map actMap = new HashMap();
    actMap.put("path", abc.getPath());
    actMap.put("author", abc.getAuthor());
    actMap.put("size",abc.getActualVersion().getSize());
    actMap.put("version",abc.getActualVersion().getName());
    actMap.put("ab",abc.VERSION_COMMENT);
    String[]  splittedPath = abc.getPath().split("/");
    actMap.put("fileName",splittedPath[splittedPath.length-1]);
   al.add(actMap);
    }
print(al);
this script is working fine.i got output for every fields. even i am getting file name also.
but the issue is if i run this script in rep file for generating the reports
it is shows like error.see the error below.
Code: Select all
Application error
Class:	net.sf.jasperreports.engine.design.JRValidationException
Message:	Report design not valid : 1. Field not found : FileName
Date:	Fri Apr 21 06:30:59 UTC 2023

in this script is working fine for only author,path and version in rep file. it is successfully generating the reports for those fields.
but is not generating for comment,size of the file and filename.
class="java.lang.String" - this claass name i have used for filename in rep file.
class="java.lang.Long" - this class name i have used for size of the document.

Code: Select all
<textField isStretchWithOverflow="true" isBlankWhenNull="false">
    <reportElement key="textField" x="1" y="0" width="510" height="18"/>
    <textElement>
        <font fontName="Arial" pdfFontName="unicode.ttf" pdfEncoding="Identity-H"/>
    </textElement>
    <textFieldExpression class="java.lang.String"><![CDATA[$F{FileName}]]></textFieldExpression>
</textField>
- this is the part i have added in rep file to get the value.
pease kindly give me the solution to get filename using reports.
please let me know which class name is need to use for getting filename , size of the file,comment.

Ex: /okm:root/abc/test.pdf
i need only file name.
test.pdf.


Please do the needful asap.

Thanks.

Re: Split FileName from the path (get only fileName)

PostPosted:Fri May 26, 2023 4:12 pm
by jllort
The application have a class named FileUtils for this purpose:
Code: Select all
String fileName = FileUtils.getName("/okm:root/folder/name.pdf");