use of javax.jcr.Property in project jackrabbit by apache.
the class MandatoryItemTest method testRemoval.
public void testRemoval() throws NotExecutableException, RepositoryException {
Node n;
Node childN = null;
Property childP = null;
try {
n = testRootNode.addNode(nodeName1, testNodeType);
if (childNodeDef != null) {
childN = n.addNode(childNodeDef.getName(), childNodeDef.getDefaultPrimaryType().getName());
}
if (childPropDef != null) {
// TODO: check if definition defines default values
childP = n.setProperty(childPropDef.getName(), "any value");
}
testRootNode.save();
} catch (RepositoryException e) {
throw new NotExecutableException();
}
// remove the mandatory items ((must succeed))
if (childN != null) {
childN.remove();
}
if (childP != null) {
childP.remove();
}
// ... however, saving must not be allowed.
try {
testRootNode.save();
fail("removing mandatory child items without re-adding them must fail.");
} catch (ConstraintViolationException e) {
// success.
}
// re-add the mandatory items
if (childNodeDef != null) {
childN = n.addNode(childNodeDef.getName(), childNodeDef.getDefaultPrimaryType().getName());
}
if (childPropDef != null) {
// TODO: check if definition defines default values
childP = n.setProperty(childPropDef.getName(), "any value");
}
// save must succeed now.
testRootNode.save();
}
use of javax.jcr.Property in project jackrabbit by apache.
the class ClearWorkspace method execute.
/**
* {@inheritDoc}
*/
public boolean execute(Context ctx) throws Exception {
Session s = CommandHelper.getSession(ctx);
if (log.isDebugEnabled()) {
log.debug("removing all content from workspace " + s.getWorkspace().getName());
}
// Set current node to root
CommandHelper.setCurrentNode(ctx, s.getRootNode());
NodeIterator iter = s.getRootNode().getNodes();
while (iter.hasNext()) {
Node n = (Node) iter.next();
if (!n.getName().equals(JcrConstants.JCR_SYSTEM)) {
n.remove();
}
}
PropertyIterator pIter = s.getRootNode().getProperties();
while (pIter.hasNext()) {
Property p = pIter.nextProperty();
if (!p.getName().equals(JcrConstants.JCR_PRIMARYTYPE)) {
p.remove();
}
}
return false;
}
use of javax.jcr.Property in project jackrabbit by apache.
the class AbstractLsItems method execute.
/**
* {@inheritDoc}
*/
public final boolean execute(Context ctx) throws Exception {
int nodes = 0;
int properties = 0;
// header
int[] width = new int[] { nameWidth, typeWidth, longWidth, longWidth, longWidth };
String[] header = new String[] { bundle.getString("word.name"), bundle.getString("word.type"), bundle.getString("word.node"), bundle.getString("word.new"), bundle.getString("word.modified") };
// print header
PrintHelper.printRow(ctx, width, header);
// print separator
PrintHelper.printSeparatorRow(ctx, width, '-');
// nodes
Iterator iter = getItems(ctx);
int index = 0;
int maxItems = getMaxItems(ctx);
// Print nodes
while (iter.hasNext() && index < maxItems) {
Item i = (Item) iter.next();
String type = null;
// Show name or path
String name = null;
if (this.isPath()) {
name = i.getPath();
} else {
name = i.getName();
}
if (i.isNode()) {
nodes++;
// name
Node n = (Node) i;
if (!isPath() && n.getIndex() > 1) {
name = n.getName() + "[" + n.getIndex() + "]";
}
// type
type = n.getPrimaryNodeType().getName();
} else {
properties++;
type = PropertyType.nameFromValue(((Property) i).getType());
}
PrintHelper.printRow(ctx, width, new String[] { name, type, Boolean.toString(i.isNode()), Boolean.valueOf(i.isNew()).toString(), Boolean.valueOf(i.isModified()).toString() });
index++;
}
// Footer
printFooter(ctx, iter);
return false;
}
use of javax.jcr.Property in project jackrabbit by apache.
the class AbstractLsProperties method execute.
/**
* {@inheritDoc}
*/
public final boolean execute(Context ctx) throws Exception {
int[] width = new int[] { 30, longWidth, longWidth, LENGTH_LENGTH, 18 };
String[] header = new String[] { bundle.getString("word.name"), bundle.getString("word.multiple"), bundle.getString("word.type"), bundle.getString("word.length"), bundle.getString("word.preview") };
PrintHelper.printRow(ctx, width, header);
PrintHelper.printSeparatorRow(ctx, width, '-');
int index = 0;
Iterator iter = getProperties(ctx);
int maxItems = getMaxItems(ctx);
while (iter.hasNext() && index < maxItems) {
Property p = (Property) iter.next();
long length = 0;
if (p.getDefinition().isMultiple()) {
long[] lengths = p.getLengths();
for (int i = 0; i < lengths.length; i++) {
length += lengths[i];
}
} else {
length = p.getLength();
}
String multiple = Boolean.toString(p.getDefinition().isMultiple());
if (p.getDefinition().isMultiple()) {
multiple += "[" + p.getValues().length + "]";
}
Collection row = new ArrayList();
row.add(p.getName());
row.add(multiple);
row.add(PropertyType.nameFromValue(p.getType()));
row.add(Long.toString(length));
// preview
if (p.getDefinition().isMultiple()) {
row.add(this.getMultiplePreview(p));
} else {
row.add(this.getPreview(p));
}
PrintHelper.printRow(ctx, width, row);
index++;
}
CommandHelper.getOutput(ctx).println();
// Write footer
printFooter(ctx, iter);
return false;
}
use of javax.jcr.Property in project jackrabbit-oak by apache.
the class ReadDeepTreeTest method createDeepTree.
protected void createDeepTree() throws Exception {
Node rn = adminSession.getRootNode();
allPaths.clear();
String testNodeName = getTestNodeName();
long start = System.currentTimeMillis();
if (!rn.hasNode(testNodeName)) {
testRoot = adminSession.getRootNode().addNode(testNodeName, "nt:unstructured");
InputStream in = getClass().getClassLoader().getResourceAsStream(getImportFileName());
adminSession.importXML(testRoot.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
adminSession.save();
} else {
testRoot = rn.getNode(testNodeName);
}
System.out.println("Import deep tree: " + (System.currentTimeMillis() - start));
ItemVisitor v = new TraversingItemVisitor.Default() {
@Override
protected void entering(Node node, int i) throws RepositoryException {
visitingNode(node, i);
super.entering(node, i);
}
@Override
protected void entering(Property prop, int i) throws RepositoryException {
visitingProperty(prop, i);
super.entering(prop, i);
}
};
v.visit(testRoot);
System.out.println("All paths: " + allPaths.size());
}
Aggregations