• Split FileName from the path (get only fileName)

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #54165  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.

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.