use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.
the class ObjectPersistenceManager method destroy.
/**
* {@inheritDoc}
*/
protected void destroy(NodeReferences refs) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
String refsFilePath = buildNodeReferencesFilePath(refs.getTargetId());
FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath);
try {
if (refsFile.exists()) {
// delete resource and prune empty parent folders
refsFile.delete(true);
}
} catch (FileSystemException fse) {
String msg = "failed to delete " + refs;
log.debug(msg);
throw new ItemStateException(msg, fse);
}
}
use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.
the class InMemBundlePersistenceManager method loadContents.
/**
* Reads the content of the hash maps from the file system
*
* @throws Exception if an error occurs
*/
public synchronized void loadContents() throws Exception {
// read item states
FileSystemResource fsRes = new FileSystemResource(wspFS, BUNDLE_FILE_PATH);
if (!fsRes.exists()) {
return;
}
BufferedInputStream bis = new BufferedInputStream(fsRes.getInputStream());
DataInputStream in = new DataInputStream(bis);
try {
// number of entries
int n = in.readInt();
while (n-- > 0) {
// id
String s = in.readUTF();
NodeId id = NodeId.valueOf(s);
// data length
int length = in.readInt();
byte[] data = new byte[length];
// data
in.readFully(data);
// store in map
bundleStore.put(id, data);
}
} finally {
in.close();
}
// read references
fsRes = new FileSystemResource(wspFS, REFS_FILE_PATH);
bis = new BufferedInputStream(fsRes.getInputStream());
in = new DataInputStream(bis);
try {
// number of entries
int n = in.readInt();
while (n-- > 0) {
// target id
String s = in.readUTF();
NodeId id = NodeId.valueOf(s);
// data length
int length = in.readInt();
byte[] data = new byte[length];
// data
in.readFully(data);
// store in map
refsStore.put(id, data);
}
} finally {
in.close();
}
if (!useFileBlobStore) {
// read blobs
fsRes = new FileSystemResource(wspFS, BLOBS_FILE_PATH);
bis = new BufferedInputStream(fsRes.getInputStream());
in = new DataInputStream(bis);
try {
// number of entries
int n = in.readInt();
while (n-- > 0) {
// id
String id = in.readUTF();
// data length
int length = in.readInt();
byte[] data = new byte[length];
// data
in.readFully(data);
// store in map
blobs.put(id, data);
}
} finally {
in.close();
}
}
}
use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.
the class XMLPersistenceManager method destroy.
/**
* {@inheritDoc}
*/
protected void destroy(PropertyState state) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
// delete binary values (stored as files)
InternalValue[] values = state.getValues();
if (values != null) {
for (int i = 0; i < values.length; i++) {
InternalValue val = values[i];
if (val != null) {
val.deleteBinaryResource();
}
}
}
// delete property file
String propFilePath = buildPropFilePath(state.getPropertyId());
FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath);
try {
if (propFile.exists()) {
// delete resource and prune empty parent folders
propFile.delete(true);
}
} catch (FileSystemException fse) {
String msg = "failed to delete property state: " + state.getParentId() + "/" + state.getName();
log.debug(msg);
throw new ItemStateException(msg, fse);
}
}
use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.
the class XMLPersistenceManager method store.
/**
* {@inheritDoc}
*/
protected void store(NodeState state) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
NodeId id = state.getNodeId();
String nodeFilePath = buildNodeFilePath(id);
FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath);
try {
nodeFile.makeParentDirs();
OutputStream os = nodeFile.getOutputStream();
Writer writer = null;
try {
String encoding = DEFAULT_ENCODING;
try {
writer = new BufferedWriter(new OutputStreamWriter(os, encoding));
} catch (UnsupportedEncodingException e) {
// should never get here!
OutputStreamWriter osw = new OutputStreamWriter(os);
encoding = osw.getEncoding();
writer = new BufferedWriter(osw);
}
String parentId = (state.getParentId() == null) ? "" : state.getParentId().toString();
String encodedNodeType = Text.encodeIllegalXMLCharacters(state.getNodeTypeName().toString());
writer.write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n");
writer.write("<" + NODE_ELEMENT + " " + UUID_ATTRIBUTE + "=\"" + id + "\" " + PARENTUUID_ATTRIBUTE + "=\"" + parentId + "\" " + MODCOUNT_ATTRIBUTE + "=\"" + state.getModCount() + "\" " + NODETYPE_ATTRIBUTE + "=\"" + encodedNodeType + "\">\n");
// mixin types
writer.write("\t<" + MIXINTYPES_ELEMENT + ">\n");
for (Name mixin : state.getMixinTypeNames()) {
writer.write("\t\t<" + MIXINTYPE_ELEMENT + " " + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(mixin.toString()) + "\"/>\n");
}
writer.write("\t</" + MIXINTYPES_ELEMENT + ">\n");
// properties
writer.write("\t<" + PROPERTIES_ELEMENT + ">\n");
for (Name propName : state.getPropertyNames()) {
writer.write("\t\t<" + PROPERTY_ELEMENT + " " + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(propName.toString()) + "\">\n");
// @todo serialize type, definition id and values
writer.write("\t\t</" + PROPERTY_ELEMENT + ">\n");
}
writer.write("\t</" + PROPERTIES_ELEMENT + ">\n");
// child nodes
writer.write("\t<" + NODES_ELEMENT + ">\n");
for (ChildNodeEntry entry : state.getChildNodeEntries()) {
writer.write("\t\t<" + NODE_ELEMENT + " " + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(entry.getName().toString()) + "\" " + UUID_ATTRIBUTE + "=\"" + entry.getId() + "\">\n");
writer.write("\t\t</" + NODE_ELEMENT + ">\n");
}
writer.write("\t</" + NODES_ELEMENT + ">\n");
writer.write("</" + NODE_ELEMENT + ">\n");
} finally {
writer.close();
}
} catch (Exception e) {
String msg = "failed to write node state: " + id;
log.debug(msg);
throw new ItemStateException(msg, e);
}
}
use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.
the class XMLPersistenceManager method store.
/**
* {@inheritDoc}
*/
protected void store(NodeReferences refs) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
String refsFilePath = buildNodeReferencesFilePath(refs.getTargetId());
FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath);
try {
refsFile.makeParentDirs();
OutputStream os = refsFile.getOutputStream();
BufferedWriter writer = null;
try {
String encoding = DEFAULT_ENCODING;
try {
writer = new BufferedWriter(new OutputStreamWriter(os, encoding));
} catch (UnsupportedEncodingException e) {
// should never get here!
OutputStreamWriter osw = new OutputStreamWriter(os);
encoding = osw.getEncoding();
writer = new BufferedWriter(osw);
}
writer.write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n");
writer.write("<" + NODEREFERENCES_ELEMENT + " " + TARGETID_ATTRIBUTE + "=\"" + refs.getTargetId() + "\">\n");
// write references (i.e. the id's of the REFERENCE properties)
for (PropertyId propId : refs.getReferences()) {
writer.write("\t<" + NODEREFERENCE_ELEMENT + " " + PROPERTYID_ATTRIBUTE + "=\"" + propId + "\"/>\n");
}
writer.write("</" + NODEREFERENCES_ELEMENT + ">\n");
} finally {
writer.close();
}
} catch (Exception e) {
String msg = "failed to store " + refs;
log.debug(msg);
throw new ItemStateException(msg, e);
}
}
Aggregations