jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ulrich <For...@gombers.de>
Subject Re: How search file content in jackrabbit repository.
Date Fri, 08 Mar 2013 13:38:24 GMT
To store the file it has to be of type Binary.

ValueFactory valueFactory = session.getValueFactory();
Binary contentValue = valueFactory.createBinary(file)
contentNode.setProperty("jcr:data", contentValue);


Am 08.03.2013 um 10:21 schrieb shahidiqbal <snowstormuser@gmail.com>:

> Hi,
> 
> I'm using the following code to add a file in the repository.
> //===================================================
> public class SaveFile {
> 
>    public void storeFile(File file, String fileInfo) {
>        try {
>            InputStream fileStream = new FileInputStream(file);
>            Session session = ConnectRespository.getSession();
>            String fileName = FilenameUtils.removeExtension(file.getName());
>            String extension = FilenameUtils.getExtension(file.getName());
>            // First check the type of the file to add 
>            MimeTable mt = MimeTable.getDefaultTable();
>            String mimeType = mt.getContentTypeFor(fileName);
> 
>            if (mimeType == null) {
>                mimeType = "application/octet-stream";
>            }
>            System.out.println(mimeType);
>            Node root = session.getRootNode();
>            Node sstormNode = null;
>            try {
>                sstormNode = root.getNode("sstorm");
>            } catch (Exception e) {
>                System.out.println("sstorm==> " + e);
>            }
> 
> 
>            if (sstormNode == null) {
>                sstormNode = root.addNode("sstorm");
>            }
> 
>            Node fileNode = sstormNode.addNode(fileName, "nt:file");
> 
>            fileNode.addMixin(JcrConstants.MIX_VERSIONABLE); //to set
> versions
>            fileNode.addMixin("ss:file");
>            fileNode.setProperty("ss:extension", extension);
>            fileNode.setProperty("ss:filename", fileName);
>            fileNode.setProperty("ss:fileinfo", fileInfo);
>            Node contentNode = fileNode.addNode("jcr:content",
> "nt:resource");
>            // set the mandatory properties 
>            contentNode.setProperty("jcr:data", fileStream);
>            contentNode.setProperty("jcr:lastModified",
> Calendar.getInstance());
>            contentNode.setProperty("jcr:mimeType", mimeType);
> 
>            System.out.println("DataSaved");
>            session.save();
>        } catch (Exception e) {
>            System.out.println("File Not Saved............... " + e);
>        }
>    }
> 
>    public static void main(String args[]) {
>        SaveFile saveFile = new SaveFile();
>        File file = new
> File("C:\\Users\\sstorm1\\Documents\\woprdpadshahid.txt");
>        saveFile.storeFile(file, "HSSC");
> 
>    }
> }
> //====================================================
> 
> 
> I'm using the following xpath or JCR_SQL2 query but i'm not able to get the
> result.
> 
> xpath :
> 1. //element(*, nt:file)//element(*,
> nt:resource)[jcr:contains(jcr:content,'shahid')]/rep:excerpt(.)
> 2. //element(*,
> nt:resource)[jcr:contains(jcr:content,'shahid')]/rep:excerpt(.)
> 
> JCR_SQL2 :
> 
> 1. select * from [nt:file] AS file where contains(file.*, '%shahid%')
> 2. select * from [nt:resource] AS resource where contains(resource .*,
> '%shahid%')
> 
> I'm not able to get where the problem is ?
> So can anyone please tell me where is the problem in code or query.
> 
> 
> 
> 
> 
> 
> 
> 
> --
> View this message in context: http://jackrabbit.510166.n4.nabble.com/How-search-file-content-in-jackrabbit-repository-tp4657899.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Mime
View raw message