Skip to content
Snippets Groups Projects
Commit 427c41d3 authored by Dmitriy Shabanov's avatar Dmitriy Shabanov
Browse files

[ignore] eXist FS ... work in progress

svn path=/trunk/eXist/; revision=18251
parent 7b4d9a84
Branches
Tags eXist-2.0
No related merge requests found
......@@ -108,6 +108,8 @@ public class Resource extends File {
private Collection collection = null;
private DocumentImpl resource = null;
File file = null;
public Resource(XmldbURI uri) {
super(uri.toString());
......@@ -374,7 +376,7 @@ public class Resource extends File {
public boolean renameTo(File dest) {
System.out.println("rename from "+uri+" to "+dest.getPath());
// System.out.println("rename from "+uri+" to "+dest.getPath());
XmldbURI destinationPath = ((Resource)dest).uri;
......@@ -437,13 +439,16 @@ public class Resource extends File {
}
}
private File serialize(final DBBroker broker, final DocumentImpl doc) throws IOException {
private synchronized File serialize(final DBBroker broker, final DocumentImpl doc) throws IOException {
if (file != null)
throw new IOException(doc.getFileURI().toString()+" locked.");
try {
Serializer serializer = broker.getSerializer();
serializer.setUser(broker.getSubject());
serializer.setProperties(XML_OUTPUT_PROPERTIES);
File file = File.createTempFile("eXist", ".xml");
file = File.createTempFile("eXist-resource-", ".xml");
file.deleteOnExit();
Writer w = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
......@@ -458,6 +463,57 @@ public class Resource extends File {
throw new IOException(e);
}
}
protected void freeFile() throws IOException {
if (isXML()) {
if (file == null)
throw new IOException();
file.delete();
file = null;
}
}
protected synchronized void uploadTmpFile() throws IOException {
if (file == null)
throw new IOException();
DBBroker broker = null;
BrokerPool db = null;
TransactionManager tm = null;
Txn txn = null;
try {
try {
db = BrokerPool.getInstance();
broker = db.get(null);
} catch (EXistException e) {
throw new IOException(e);
}
tm = db.getTransactionManager();
txn = tm.beginTransaction();
FileInputSource is = new FileInputSource(file);
IndexInfo info = collection.validateXMLResource(txn, broker, uri.lastSegment(), is);
// info.getDocument().getMetadata().setMimeType(mimeType.getName());
is = new FileInputSource(file);
collection.store(txn, broker, info, is, false);
tm.commit(txn);
} catch ( Exception e ) {
e.printStackTrace();
if (txn != null) tm.abort(txn);
} finally {
if (db != null)
db.release( broker );
}
}
private void moveResource(DBBroker broker, Txn txn, DocumentImpl doc, Collection source, Collection destination, XmldbURI newName) throws PermissionDeniedException, LockException, IOException, SAXException, EXistException {
......@@ -512,7 +568,7 @@ public class Resource extends File {
File tempFile = null;
FileInputStream is = null;
try {
tempFile = File.createTempFile("eXist", ".xml");
tempFile = File.createTempFile("eXist-resource-", ".xml");
tempFile.deleteOnExit();
Writer w = new OutputStreamWriter(new FileOutputStream(tempFile), "UTF-8");
......
......@@ -42,6 +42,8 @@ public class ResourceInputStream extends FileInputStream {
public void close() throws IOException {
super.close();
resource.freeFile();
if (resource.isXML()) {
//XXX: cleanup tmp file
}
......
......@@ -31,17 +31,25 @@ import java.io.IOException;
*/
public class ResourceOutputStream extends FileOutputStream {
private Resource resource;
public ResourceOutputStream(Resource file) throws FileNotFoundException {
super(file.getFile());
resource = file;
}
public ResourceOutputStream(Resource file, boolean append) throws FileNotFoundException {
super(file.getFile(), append);
resource = file;
}
public void close() throws IOException {
super.close();
resource.freeFile();
//XXX: xml upload back to db
//XXX: locking?
......
......@@ -31,13 +31,19 @@ import java.io.RandomAccessFile;
*/
public class ResourceRandomAccess extends RandomAccessFile {
private Resource resource;
public ResourceRandomAccess(Resource resource, String mode) throws FileNotFoundException {
super(resource.getFile(), mode);
this.resource = resource;
}
public void close() throws IOException {
super.close();
resource.freeFile();
//XXX: xml upload back to db
//XXX: locking?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment