use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class Serializer method serialize.
/**
* Serializes the specified <code>PropertyState</code> object to the given
* binary <code>stream</code>. Binary values are stored in the specified
* <code>BLOBStore</code>.
*
* @param state <code>state</code> to serialize
* @param stream the stream where the <code>state</code> should be
* serialized to
* @param blobStore handler for BLOB data
* @throws Exception if an error occurs during the serialization
* @see #deserialize(PropertyState, InputStream,BLOBStore)
*/
public static void serialize(PropertyState state, OutputStream stream, BLOBStore blobStore) throws Exception {
DataOutputStream out = new DataOutputStream(stream);
// type
out.writeInt(state.getType());
// multiValued
out.writeBoolean(state.isMultiValued());
// definitionId
out.writeUTF("");
// modCount
out.writeShort(state.getModCount());
// values
InternalValue[] values = state.getValues();
// count
out.writeInt(values.length);
for (int i = 0; i < values.length; i++) {
InternalValue val = values[i];
if (state.getType() == 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
// value
out.writeUTF(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 {
IOUtils.closeQuietly(in);
}
}
val.discard();
} else {
/**
* because writeUTF(String) has a size limit of 65k,
* Strings are serialized as <length><byte[]>
*/
//out.writeUTF(val.toString()); // value
byte[] bytes = val.toString().getBytes(ENCODING);
// lenght of byte[]
out.writeInt(bytes.length);
// byte[]
out.write(bytes);
}
}
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class Entry method readEntries.
static List<Entry> readEntries(NodeImpl aclNode, String path) throws RepositoryException {
if (aclNode == null || !NT_REP_ACL.equals(aclNode.getPrimaryNodeTypeName())) {
throw new IllegalArgumentException("Node must be of type 'rep:ACL'");
}
SessionImpl sImpl = (SessionImpl) aclNode.getSession();
PrincipalManager principalMgr = sImpl.getPrincipalManager();
PrivilegeManagerImpl privilegeMgr = (PrivilegeManagerImpl) ((JackrabbitWorkspace) sImpl.getWorkspace()).getPrivilegeManager();
NodeId nodeId = aclNode.getParentId();
List<Entry> entries = new ArrayList<Entry>();
// load the entries:
NodeIterator itr = aclNode.getNodes();
while (itr.hasNext()) {
NodeImpl aceNode = (NodeImpl) itr.nextNode();
try {
String principalName = aceNode.getProperty(P_PRINCIPAL_NAME).getString();
boolean isGroupEntry = false;
Principal princ = principalMgr.getPrincipal(principalName);
if (princ != null) {
isGroupEntry = (princ instanceof Group);
}
InternalValue[] privValues = aceNode.getProperty(P_PRIVILEGES).internalGetValues();
Name[] privNames = new Name[privValues.length];
for (int i = 0; i < privValues.length; i++) {
privNames[i] = privValues[i].getName();
}
Value globValue = null;
if (aceNode.hasProperty(P_GLOB)) {
globValue = aceNode.getProperty(P_GLOB).getValue();
}
boolean isAllow = NT_REP_GRANT_ACE.equals(aceNode.getPrimaryNodeTypeName());
Entry ace = new Entry(nodeId, principalName, isGroupEntry, privilegeMgr.getBits(privNames), isAllow, path, globValue);
entries.add(ace);
} catch (RepositoryException e) {
log.debug("Failed to build ACE from content. {}", e.getMessage());
}
}
return entries;
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class WorkspaceImporter method processProperty.
protected void processProperty(NodeState node, PropInfo pInfo) throws RepositoryException {
PropertyState prop;
QPropertyDefinition def;
Name name = pInfo.getName();
int type = pInfo.getType();
if (node.hasPropertyName(name)) {
// a property with that name already exists...
PropertyId idExisting = new PropertyId(node.getNodeId(), name);
prop = (PropertyState) itemOps.getItemState(idExisting);
def = itemOps.findApplicablePropertyDefinition(prop.getName(), prop.getType(), prop.isMultiValued(), node);
if (def.isProtected()) {
// skip protected property
log.debug("skipping protected property " + itemOps.safeGetJCRPath(idExisting));
return;
}
if (!def.isAutoCreated() || (prop.getType() != type && type != PropertyType.UNDEFINED) || def.isMultiple() != prop.isMultiValued()) {
throw new ItemExistsException(itemOps.safeGetJCRPath(prop.getPropertyId()));
}
} else {
// there's no property with that name,
// find applicable definition
def = pInfo.getApplicablePropertyDef(itemOps.getEffectiveNodeType(node));
if (def.isProtected()) {
// skip protected property
log.debug("skipping protected property " + name);
return;
}
// create new property
prop = itemOps.createPropertyState(node, name, type, def);
}
// check multi-valued characteristic
TextValue[] values = pInfo.getTextValues();
if (values.length != 1 && !def.isMultiple()) {
throw new ConstraintViolationException(itemOps.safeGetJCRPath(prop.getPropertyId()) + " is not multi-valued");
}
// convert serialized values to InternalValue objects
int targetType = pInfo.getTargetType(def);
InternalValue[] iva = new InternalValue[values.length];
for (int i = 0; i < values.length; i++) {
iva[i] = values[i].getInternalValue(targetType);
}
// set values
prop.setValues(iva);
// make sure property is valid according to its definition
itemOps.validate(prop);
if (prop.getType() == PropertyType.REFERENCE || prop.getType() == PropertyType.WEAKREFERENCE) {
// store reference for later resolution
refTracker.processedReference(prop);
}
// store property
itemOps.store(prop);
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class WorkspaceImporter method end.
/**
* {@inheritDoc}
*/
public void end() throws RepositoryException {
if (aborted) {
// the import has been aborted, get outta here...
return;
}
boolean succeeded = false;
try {
// check sanity of workspace/session first
wsp.sanityCheck();
/**
* adjust references that refer to uuids which have been mapped to
* newly generated uuids on import
*/
Iterator<Object> iter = refTracker.getProcessedReferences();
while (iter.hasNext()) {
PropertyState prop = (PropertyState) iter.next();
// being paranoid...
if (prop.getType() != PropertyType.REFERENCE && prop.getType() != PropertyType.WEAKREFERENCE) {
continue;
}
boolean modified = false;
InternalValue[] values = prop.getValues();
InternalValue[] newVals = new InternalValue[values.length];
for (int i = 0; i < values.length; i++) {
NodeId adjusted = refTracker.getMappedId(values[i].getNodeId());
if (adjusted != null) {
newVals[i] = InternalValue.create(adjusted, prop.getType() != PropertyType.REFERENCE);
modified = true;
} else {
// reference doesn't need adjusting, just copy old value
newVals[i] = values[i];
}
}
if (modified) {
prop.setValues(newVals);
itemOps.store(prop);
}
}
refTracker.clear();
// make sure import target is valid according to its definition
itemOps.validate(importTarget);
// finally store the state of the import target
// (the parent of the imported subtree)
itemOps.store(importTarget);
succeeded = true;
} finally {
if (!succeeded) {
// update operation failed, cancel all modifications
aborted = true;
itemOps.cancel();
}
}
if (!aborted) {
// finish update
itemOps.update();
}
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class VersionManagerImplConfig method internalCreateConfiguration.
/**
* Creates a new configuration node.
* <p>
* The nt:confguration is stored within the nt:configurations storage using
* the nodeid of the configuration root (rootId) as path.
*
* @param rootId the id of the configuration root node
* @param configId the id of the configuration node
* @param baseLine id of the baseline version or <code>null</code>
* @return the node id of the created configuration
* @throws RepositoryException if an error occurs
*/
private NodeId internalCreateConfiguration(NodeId rootId, NodeId configId, NodeId baseLine) throws RepositoryException {
NodeStateEx configRoot = internalGetConfigRoot();
NodeStateEx configParent = InternalVersionManagerBase.getParentNode(configRoot, rootId.toString(), NameConstants.REP_CONFIGURATIONS);
Name name = InternalVersionManagerBase.getName(rootId.toString());
if (configId == null) {
configId = context.getNodeIdFactory().newNodeId();
}
NodeStateEx config = configParent.addNode(name, NameConstants.NT_CONFIGURATION, configId, true);
Set<Name> mix = new HashSet<Name>();
mix.add(NameConstants.REP_VERSION_REFERENCE);
config.setMixins(mix);
config.setPropertyValue(NameConstants.JCR_ROOT, InternalValue.create(rootId));
// init mix:versionable flags
VersionHistoryInfo vh = vMgr.getVersionHistory(session, config.getState(), null);
// and set the base version and history to the config
InternalValue historyId = InternalValue.create(vh.getVersionHistoryId());
InternalValue versionId = InternalValue.create(baseLine == null ? vh.getRootVersionId() : baseLine);
config.setPropertyValue(NameConstants.JCR_BASEVERSION, versionId);
config.setPropertyValue(NameConstants.JCR_VERSIONHISTORY, historyId);
config.setPropertyValue(NameConstants.JCR_ISCHECKEDOUT, InternalValue.create(true));
config.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, new InternalValue[] { versionId });
configParent.store();
return configId;
}
Aggregations