use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class PropertyValueOperand method getPropertyState.
/**
* Returns the property state for the given score node or <code>null</code>
* if none exists.
*
* @param sn the current score node.
* @param context the evaluation context.
* @return the property state or <code>null</code>.
* @throws RepositoryException if an error occurs while reading.
*/
public final PropertyState getPropertyState(ScoreNode sn, EvaluationContext context) throws RepositoryException {
ItemStateManager ism = context.getItemStateManager();
PropertyId propId = new PropertyId(sn.getNodeId(), operand.getPropertyQName());
try {
return (PropertyState) ism.getItemState(propId);
} catch (NoSuchItemStateException e) {
return null;
} catch (ItemStateException e) {
throw new RepositoryException(e);
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class XMLPersistenceManager method exists.
/**
* {@inheritDoc}
*/
public synchronized boolean exists(NodeId id) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
try {
String nodeFilePath = buildNodeFilePath(id);
FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath);
return nodeFile.exists();
} catch (FileSystemException fse) {
String msg = "failed to check existence of item state: " + id;
log.debug(msg);
throw new ItemStateException(msg, fse);
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class XMLPersistenceManager method store.
/**
* {@inheritDoc}
*/
protected void store(PropertyState state) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
String propFilePath = buildPropFilePath(state.getPropertyId());
FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath);
try {
propFile.makeParentDirs();
OutputStream os = propFile.getOutputStream();
// write property state to xml file
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 typeName;
int type = state.getType();
try {
typeName = PropertyType.nameFromValue(type);
} catch (IllegalArgumentException iae) {
// should never be getting here
throw new ItemStateException("unexpected property-type ordinal: " + type, iae);
}
writer.write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n");
writer.write("<" + PROPERTY_ELEMENT + " " + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(state.getName().toString()) + "\" " + PARENTUUID_ATTRIBUTE + "=\"" + state.getParentId() + "\" " + MULTIVALUED_ATTRIBUTE + "=\"" + Boolean.toString(state.isMultiValued()) + "\" " + MODCOUNT_ATTRIBUTE + "=\"" + state.getModCount() + "\" " + TYPE_ATTRIBUTE + "=\"" + typeName + "\">\n");
// values
writer.write("\t<" + VALUES_ELEMENT + ">\n");
InternalValue[] values = state.getValues();
if (values != null) {
for (int i = 0; i < values.length; i++) {
writer.write("\t\t<" + VALUE_ELEMENT + ">");
InternalValue val = values[i];
if (val != null) {
if (type == PropertyType.BINARY) {
// special handling required for binary value:
// put binary value in BLOB store
InputStream in = val.getStream();
String blobId = blobStore.createId(state.getPropertyId(), i);
try {
blobStore.put(blobId, in, val.getLength());
} finally {
IOUtils.closeQuietly(in);
}
// store id of BLOB as property value
writer.write(blobId);
// in BLOB store and discard old value instance (e.g. temp file)
if (blobStore instanceof ResourceBasedBLOBStore) {
// optimization: if the BLOB store is resource-based
// retrieve the resource directly rather than having
// to read the BLOB from an input stream
FileSystemResource fsRes = ((ResourceBasedBLOBStore) blobStore).getResource(blobId);
values[i] = InternalValue.create(fsRes);
} else {
in = blobStore.get(blobId);
try {
values[i] = InternalValue.create(in);
} finally {
try {
in.close();
} catch (IOException e) {
// ignore
}
}
}
val.discard();
} else {
writer.write(Text.encodeIllegalXMLCharacters(val.toString()));
}
}
writer.write("</" + VALUE_ELEMENT + ">\n");
}
}
writer.write("\t</" + VALUES_ELEMENT + ">\n");
writer.write("</" + PROPERTY_ELEMENT + ">\n");
} finally {
writer.close();
}
} catch (Exception e) {
String msg = "failed to store property state: " + state.getParentId() + "/" + state.getName();
log.debug(msg);
throw new ItemStateException(msg, e);
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class XMLPersistenceManager method load.
/**
* {@inheritDoc}
*/
public synchronized NodeState load(NodeId id) throws NoSuchItemStateException, ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
Exception e = null;
String nodeFilePath = buildNodeFilePath(id);
try {
if (!itemStateFS.isFile(nodeFilePath)) {
throw new NoSuchItemStateException(id.toString());
}
InputStream in = itemStateFS.getInputStream(nodeFilePath);
try {
DOMWalker walker = new DOMWalker(in);
String ntName = walker.getAttribute(NODETYPE_ATTRIBUTE);
NodeState state = createNew(id);
state.setNodeTypeName(factory.create(ntName));
readState(walker, state);
return state;
} finally {
in.close();
}
} catch (IOException ioe) {
e = ioe;
// fall through
} catch (FileSystemException fse) {
e = fse;
// fall through
}
String msg = "failed to read node state: " + id;
log.debug(msg);
throw new ItemStateException(msg, e);
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class XMLPersistenceManager 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);
}
}
Aggregations