jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nedim <nedim.se...@eu-softing.com>
Subject How to add nodes into jackrabbit repository?
Date Fri, 09 Apr 2010 12:02:00 GMT
Hi guys,

I have created a simple script that adding nodes to jackrabbit, the 
nodes came from two different sources MSSQL and MySQL database. The 
script has the task to check for modifications in the two databases and 
add, update or delete nodes if they are modified in database. i have a 
custom node type that i use.

Now my problem is that some times i get a bad node. the node have to 
look like this:

Title: *svn-book*
Summary: SVN book
Author: administrator
Creation date: 2010-03-09T00:00:00.000+01:00
Url frontend: /xxxSite/files/71/71BCE045-3648-47F3-ADCC-0BE981E5BDC4.pdf 
<http://test.ksoft.tv:8080/DenaroSite/files/71/71BCE045-3648-47F3-ADCC-0BE981E5BDC4.pdf>


Url backend: /Desk?nodeid=728 
<http://test.ksoft.tv:8080/CMSDesk?nodeid=728>
Type: Files
Extension: pdf
Tags: files, JR, test
Keywords: JR files test
Page title: JR files test
Page Description: JR files test

    * 728_documents.pdf
      Property
          o Mime type: application/pdf
          o Encoding: UTF-8
          o Data: 1671317
          o Last time: 2010-03-09T16:04:40.000+01:00

But i get this, without my node definition:

    * 728_documents.pdf
      Property
          o Mime type: application/pdf
          o Encoding: UTF-8
          o Data: 1671317
          o Last time: 2010-03-09T16:04:40.000+01:00


Code for update and delete:

String ID = res.getString("DocumentNodeID");
                String title = res.getString("NewsTitle");
                String textdata = "<html xml:lang=\"it-IT\" 
lang=\"it-IT\" dir=\"ltr\"><head><meta http-equiv=\"Content-Type\" 
content=\"text/html; charset=UTF-8\"/></head><body>";
                String subtitle = res.getString("NewsSummary");
                Date date = res.getDate("NewsReleaseDate");
                String author = res.getString("Author");
                textdata += res.getString("NewsText");
                textdata += "</body></html>";

                String pagetitle = res.getString("DocumentPageTitle");
                String pagekey = res.getString("DocumentPageKeyWords");
                String pagedesc =  res.getString("DocumentPageDescription");
                String tags = res.getString("DocumentTags");

                String url_path = res.getString("DocumentUrlPath");

                file_name =  ID + "_news.html";
                if (checkNodeExists(jsession, file_name))
                {
                    System.out.println("Update Kentico node: " + file_name);
                    System.out.println("Update fields: " + ID + " " + 
title + " " + subtitle + " " + date + " " + author);

                    File createTempFile = File.createTempFile(file_name, 
".html");
                   // System.out.println(createTempFile.getName());

                    FileOutputStream fos = new 
FileOutputStream(createTempFile);
                    BufferedOutputStream bos = new 
BufferedOutputStream(fos);
                    bos.write(textdata.getBytes());
                    bos.flush();

                    MimeTable mt = MimeTable.getDefaultTable();
                    String mimeType = 
mt.getContentTypeFor(createTempFile.getName());

                    if (mimeType == null)
                    {
                        mimeType = "application/octet-stream";
                    }
                    File f = new File(createTempFile.getPath());

                    String ext = 
f.getName().substring(f.getName().lastIndexOf(".")+1, f.getName().length());
                  
                    Node fileNode = root.getNode(file_name);

                    fileNode.setProperty("xx:title", title);
                    fileNode.setProperty("xx:summary", subtitle);
                    Calendar javadate = Calendar.getInstance();
                    javadate.setTime(date);
                    fileNode.setProperty("xx:date", javadate);
                    fileNode.setProperty("xx:author", author);
                    fileNode.setProperty("xxurl_frontend", url_path + 
".aspx");
                    fileNode.setProperty("xx:url_backend", 
"/Desk?nodeid=" + ID);
                    fileNode.setProperty("xx:type", "Files");
                    fileNode.setProperty("xx:extension", "html");

                    fileNode.setProperty("xx:tags", tags);
                    fileNode.setProperty("xx:keywords", pagekey);
                    fileNode.setProperty("xx:pagetitle", pagetitle);
                    fileNode.setProperty("xx:pagedescription", pagedesc);

                    Node resNode = fileNode.getNode("jcr:content");

                    resNode.setProperty("jcr:mimeType", mimeType);
                    resNode.setProperty("jcr:encoding", "UTF-8");
                    resNode.setProperty("jcr:data", new FileInputStream(f));
                    Calendar lastModified = Calendar.getInstance();
                    lastModified.setTimeInMillis(f.lastModified());
                    resNode.setProperty("jcr:lastModified", lastModified);
                    createTempFile.deleteOnExit();
                    jsession.save();

And for delete:

                        if (nodeType.equals("Files"))
                        {
                            System.out.println("Files delete check: " + 
rnode.getPath());
                            if(checkIfNodeExistsInDBfiles(sess, 
rnode.getPath()))
                            {
                                System.out.println("Skip: " + 
rnode.getPath() + " type: " + nodeType);
                            }
                            else
                            {
                                System.out.println("Delete: " + 
rnode.getPath() + " type: " + nodeType);
                                rnode.remove();
                                sess.save();
                                System.out.println("Session save (Files)");
                                flag = true;
                            }
                        }

If someone can help me please, is there a way with transactions or node 
lock to make a better way for adding and deleting nodes, am not very 
experience with jackrabbit so every suggestions is welcome, thanks.

SehaxX


Mime
View raw message