I need some simple java code (running in a simple JSP) to connect to a Jackrabbit JCR server to set jcr:mimetype properties for files based on file extension. It should connect to the server and loop over all files matching a specific file extension and if the mimetype does not match what it should be then set the property to the mimetype I've defined. Should display a status for each matching file, whether the mimetype was already set properly or had to be set. Simple. Only needs to do one file extension at a time. I need this script because my application was not setting mimetype for docx files. See project details for existing code sample.
## Deliverables
Current code for adding and updating files looks something like this...
<pre>
String fullpath = relPath(path+"/"+filename);
Node file;
Node resource;
if([login to view URL](fullpath))
{
file = [login to view URL](fullpath);
resource = [login to view URL]("jcr:content");
[login to view URL]();
}
else
{
file = [login to view URL](fullpath, "nt:file");
resource = [login to view URL]("jcr:content", "nt:resource");
[login to view URL]("mix:versionable");
}
String mime = [login to view URL](filename);
if(mime == null)
{
if ([login to view URL](".docx")) {
mime = "application/[login to view URL]";
} else {
mime = "application/octet-stream";
}
}
if(encoding != null)
{
[login to view URL]("jcr:encoding", encoding);
}
[login to view URL]("jcr:data", fileContents);
[login to view URL]("jcr:mimeType", mime);
[login to view URL]("jcr:lastModified", [login to view URL]());
</pre>