jp_
jp_

Reputation: 238

Java version control

I am using docx4j to load, manipulate and save Word files. Everything works perfectly but there is one thing i don't know how to implement it. What I want is something like a version control - that means if you save a document it shall be possible to recover a earlier version of this document (e.g. by saving only the delta). Maybe you can describe it that is should be something like SVN or Git where you can go back to an earlier version of your files. The problem is that i do not know any possibility to realize that. So I hope that anyone of you can help me. It would be fine if anyone at least know a package or something else that can do this with files in general and not especially with the docx Files. Thanks for your help!

Edit: I am sorry that my question was imprecise. This was my first post here, in future i will improve ;)

Upvotes: 0

Views: 4353

Answers (5)

Benjamin Cox
Benjamin Cox

Reputation: 6120

This can be a tricky thing to implement yourself, so I wouldn't recommend it.

I don't know much about your environment, but if you are able to use an off-the-shelf versioning repository, you'll save yourself much grief. You can try to use Git or SVN directly, which may be the simplest solution for your use case.

Since you're talking about MS Office files, however, you may be implementing some form of enterprise document management tool. In this case, the JCR specification is designed to provide access to files in a repository, with versioning and other metadata features. Here's the specification.

The Apache Jackrabbit project provides an open source implementation of this spec, as does the developers version of Alfresco.

Picking the right solution will really depend on what your users are trying to do with these files, what your deployment environment looks like (don't try to host Git on Windows, k?), and how custom your current codebase is (standard Servlet container? Java EE? home-rolled?).

Good luck!

Upvotes: 0

tbraun89
tbraun89

Reputation: 2234

I think you should use Git for this, I found a Java API called JavaGit, so you can have easy access the repository. With Git you can have a local repository where you can commit files and switch versions. If you need it you could also push and pull the data to a remote location.

Better use JGit like Gian said!

Upvotes: 0

Peter Butkovic
Peter Butkovic

Reputation: 12149

If you'd like some pure java implementatoin for document versioning, maybe you could go for: Jackrabbit

Similar questions have been already asked before. The 1.st answer (marked as correct one) on this question goes for Jackrabbit as well: Using a version control system as a data backend

Upvotes: 1

Gian
Gian

Reputation: 13955

JGit is a Java implementation of Git that will work with few dependencies. Similar libraries exist for SVN and CVS. Home-brewing a version control system is almost certainly a terrible idea, given the existence of good-quality solutions!

Upvotes: 6

Adam Sznajder
Adam Sznajder

Reputation: 9206

The simplest possible way would be to use tools diff and patch. They were used as a core of CVS. I assume that you would like to run your application in Windows where they are not preinstalled. I don't know whether it would be easy / comfortable to use windows versions of this tools but you can always try to write similiar functionality on your own. Here you can find very good tutorial about finding differences between files and patching them: http://tuts.pinehead.tv/2012/09/18/introduction-using-diff-and-patch/ When you know the functionality it's quite easy to write something similiar on your own.

Upvotes: 0

Related Questions