Re: Trouble in saving excel file to jackrabbit node

2012-01-10 Thread Alexander Klimetschek
On 09.01.12 15:07, Libin Joseph libin.efe...@gmail.com wrote:
I am trying to save an excel file that a user uploads using a
web browser, but i am getting an error *javax.jcr.pathnotfoundexception

Which method throws?

Node folder = session.getRootNode();
Node upld=folder.getNode(Traffic Software)
.getNode(Client Node).getNode(Bookings);

Maybe here? Then the path /Traffic Software/Client Node/Bookings might
not exist in your repo.

Node file = upld.addNode(fileName, nt:file);
Node resNode = file.addNode (jcr:content, nt:resource);
file.addMixin(JcrConstants.MIX_VERSIONABLE);
Node fileContent = file.getNode(jcr:content);

Note that fileContent is the same as resNode here, so you don't have to
fetch it again.

fileContent.setProperty(jcr:data, fileStream);
session.save();

Cheers,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel






Trouble in saving excel file to jackrabbit node

2012-01-09 Thread Libin Joseph
Hello everyone,

I am pretty new with Jackrabbit, so kindly excuse me if something does not
make sense. I am trying to save an excel file that a user uploads using a
web browser, but i am getting an error *javax.jcr.pathnotfoundexception
*
When I try the class alone to upload the file from a specific location in
the disk it works.
When I try to upload the file from the browser to a disk , it still works.

But when I combine both of them together it does not work. I really
appreciate if someone could help me. I have attached the servlet code below
for the reference



public class FileUp extends HttpServlet
{
private static final long serialVersionUID = 1L;
public String Client;
String clientName=;
public static String grid_version=success;

public FileUp()
{
super();

}

/**
 * @see HttpServlet#doGet(HttpServletRequest request,
HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
// TODO Auto-generated method stub
}

/**
 * @see HttpServlet#doPost(HttpServletRequest request,
HttpServletResponse response)
 */
 protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
// TODO Auto-generated method stub
 System.out.println(Hello);
boolean isMultipart =
ServletFileUpload.isMultipartContent(request);
if(!isMultipart)
{

}
else
{
//Vector v = new Vector();
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new
ServletFileUpload(factory);
List items = null;
try
  {
items = upload.parseRequest(request);
System.out.println(items);
  }

catch (FileUploadException e)
  {
e.printStackTrace();
  }
Iterator itr = items.iterator();
while (itr.hasNext()) {
FileItem item = (FileItem) itr.next();
if (item.isFormField())
{
String fieldName = item.getFieldName();
String value = item.getString();
//v.add(value);
System.out.println(Form value +value);
}
else
{
try
{
//String itemName
=request.getParameter(frmpnlNewFormpanel);
String itemName = item.getName();
System.out.println(this is Item
name+itemName);
File  savedFile = new
File(E:\\16_nov\\TrafficSoftware\\repository\\workspaces\\eFerns new
traffic\\+itemName);
item.write(savedFile);
System.out.println(You file has been
saved at the loaction:+savedFile.getName());
System.out.println(itemName);
/*---saving cods to jack---*/

Repository masterRepository = new
TransientRepository();
 Session session =
masterRepository.login(new SimpleCredentials(username,
password.toCharArray()));

   try
{


Node root =
session.getRootNode();

/*---saving cods to
jack---*/
String fileName =
traffic.xlsx;
InputStream fileStream =
new
FileInputStream(E:\\16_nov\\TrafficSoftware\\repository\\workspaces\\eFerns
new traffic\\traffic.xlsx);

 Node folder =
session.getRootNode();
 Node
upld=folder.getNode(Traffic Software).getNode(Client
Node).getNode(Bookings);
 Node file =
upld.addNode(fileName, nt:file);
 Node resNode =
file.addNode (jcr:content, nt:resource);

 file.addMixin(JcrConstants.MIX_VERSIONABLE);
 Node fileContent =
file.getNode(jcr:content);

 fileContent.setProperty(jcr:data, fileStream);
 session.save();