Store metadata into Jackrabbit repository

后端 未结 3 670
情话喂你
情话喂你 2021-01-31 23:39

can anybody explain to me, how to proceed in following scenario ?

  1. receiving documents (MS docs, ODS, PDF)

  2. Dublic core metadata extraction via Ap

3条回答
  •  梦如初夏
    2021-01-31 23:48

    I am new to Jackrabbit, working on 2.4.2. As for your solution, you can check for the type using a core java logic and put cases defining any variation in your action.

    You won't need to worry about issues with saving contents of different .txt or .pdf as their content is converted into binary and saved. Here is a small sample in which I uploaded and downloaded a pdf file in/from jackrabbit repo.

        // Import the pdf file unless already imported 
                // This program is for sample purpose only so everything is hard coded.
            if (!root.hasNode("Alfresco_E0_Training.pdf"))
            { 
                System.out.print("Importing PDF... "); 
    
                // Create an unstructured node under which to import the XML 
                //Node node = root.addNode("importxml", "nt:unstructured"); 
                Node file = root.addNode("Alfresco_E0_Training.pdf","nt:file");
    
                // Import the file "Alfresco_E0_Training.pdf" under the created node 
                FileInputStream stream = new FileInputStream("\\Alfresco_E0_Training.pdf");
                Node content = file.addNode("jcr:content","nt:resource");
                Binary binary = session.getValueFactory().createBinary(stream);
                content.setProperty("jcr:data",binary);
                stream.close();
                session.save(); 
                //System.out.println("done."); 
                System.out.println("::::::::::::::::::::Checking content of the node:::::::::::::::::::::::::");
                System.out.println("File Node Name : "+file.getName());
                System.out.println("File Node Identifier : "+file.getIdentifier());
                System.out.println("File Node child : "+file.JCR_CHILD_NODE_DEFINITION);
                System.out.println("Content Node Name : "+content.getName());
                System.out.println("Content Node Identifier : "+content.getIdentifier());
                System.out.println("Content Node Content : "+content.getProperty("jcr:data"));
                System.out.println(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::");
    
            }else
            {
                session.save();
                Node file = root.getNode("Alfresco_E0_Training.pdf");
                Node content = file.getNode("jcr:content");
                String path = content.getPath();
                Binary bin = session.getNode(path).getProperty("jcr:data").getBinary();
                InputStream stream = bin.getStream();
                 File f=new File("C:\\Alfresco_E0_Training.pdf");
    
                  OutputStream out=new FileOutputStream(f);
                  byte buf[]=new byte[1024];
                  int len;
                  while((len=stream.read(buf))>0)
                  out.write(buf,0,len);
                  out.close();
                  stream.close();
                  System.out.println("\nFile is created...................................");
    
    
                System.out.println("done."); 
                System.out.println("::::::::::::::::::::Checking content of the node:::::::::::::::::::::::::");
                System.out.println("File Node Name : "+file.getName());
                System.out.println("File Node Identifier : "+file.getIdentifier());
                //System.out.println("File Node child : "+file.JCR_CHILD_NODE_DEFINITION);
                System.out.println("Content Node Name : "+content.getName());
                System.out.println("Content Node Identifier : "+content.getIdentifier());
                System.out.println("Content Node Content : "+content.getProperty("jcr:data"));
                System.out.println(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::");
            } 
    
            //output the repository content
            } 
        catch (IOException e){
            System.out.println("Exception: "+e);
        }
        finally { 
            session.logout(); 
            } 
            } 
    }
    

    Hope this helps

提交回复
热议问题