Skip to content

Commit

Permalink
[ignore] eXist FS ... work in progress
Browse files Browse the repository at this point in the history
svn path=/trunk/eXist/; revision=18251
  • Loading branch information
shabanovd committed Feb 7, 2013
1 parent 7b4d9a8 commit 427c41d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
64 changes: 60 additions & 4 deletions src/org/exist/util/io/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public static File createTempFile(String prefix, String suffix, File directory)

private Collection collection = null;
private DocumentImpl resource = null;

File file = null;

public Resource(XmldbURI uri) {
super(uri.toString());
Expand Down Expand Up @@ -374,7 +376,7 @@ public boolean _renameTo(File dest) {

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;

Expand Down Expand Up @@ -437,13 +439,16 @@ public boolean renameTo(File dest) {
}
}

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");
Expand All @@ -458,6 +463,57 @@ private File serialize(final DBBroker broker, final DocumentImpl doc) throws IOE
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 {

Expand Down Expand Up @@ -512,7 +568,7 @@ private void moveResource(DBBroker broker, Txn txn, DocumentImpl doc, Collection
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");
Expand Down
2 changes: 2 additions & 0 deletions src/org/exist/util/io/ResourceInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public ResourceInputStream(Resource file) throws FileNotFoundException {
public void close() throws IOException {
super.close();

resource.freeFile();

if (resource.isXML()) {
//XXX: cleanup tmp file
}
Expand Down
10 changes: 9 additions & 1 deletion src/org/exist/util/io/ResourceOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,25 @@
*/
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?
Expand Down
6 changes: 6 additions & 0 deletions src/org/exist/util/io/ResourceRandomAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@
*/
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?
Expand Down

0 comments on commit 427c41d

Please sign in to comment.