use of javax.jcr.Binary in project jackrabbit by apache.
the class PathTest method testGetBinary.
public void testGetBinary() throws RepositoryException, IOException {
Binary binary = prop.getBinary();
byte[] bytes = new byte[(int) binary.getSize()];
binary.read(bytes, 0);
binary.dispose();
assertEquals(prop.getString(), new String(bytes, "UTF-8"));
}
use of javax.jcr.Binary in project jackrabbit by apache.
the class PathTest method testGetBinaryFromValue.
public void testGetBinaryFromValue() throws RepositoryException, IOException {
Value v = superuser.getValueFactory().createValue("/a/b/c", PropertyType.PATH);
Binary binary = v.getBinary();
byte[] bytes = new byte[(int) binary.getSize()];
binary.read(bytes, 0);
binary.dispose();
assertEquals(prop.getString(), new String(bytes, "UTF-8"));
}
use of javax.jcr.Binary in project jackrabbit by apache.
the class ReferenceBinaryTest method testReferenceBinaryExchangeWithSharedRepository.
public void testReferenceBinaryExchangeWithSharedRepository() throws Exception {
Session firstSession = superuser;
// create a binary
Binary b = vf.createBinary(new RandomInputStream(1, STREAM_LENGTH));
ReferenceBinary referenceBinary = null;
if (b instanceof ReferenceBinary) {
referenceBinary = (ReferenceBinary) b;
}
assertNotNull(referenceBinary);
assertNotNull(referenceBinary.getReference());
// in the current test the message is exchanged via repository which is shared as well
// put the reference message value in a property on a node
String newNode = "sample_" + System.nanoTime();
firstSession.getRootNode().addNode(newNode).setProperty("reference", referenceBinary.getReference());
// save the first session
firstSession.save();
// get a second session over the same repository / ds
Session secondSession = getHelper().getRepository().login(new SimpleCredentials("admin", "admin".toCharArray()));
// read the binary referenced by the referencing binary
String reference = secondSession.getRootNode().getNode(newNode).getProperty("reference").getString();
ReferenceBinary ref = new SimpleReferenceBinary(reference);
assertEquals(b, secondSession.getValueFactory().createValue(ref).getBinary());
}
use of javax.jcr.Binary in project jackrabbit by apache.
the class RepositoryCopierTest method verifyTargetRepository.
private void verifyTargetRepository(File target) throws Exception {
RepositoryImpl repository = RepositoryImpl.create(RepositoryConfig.create(target));
try {
Session session = repository.login(CREDENTIALS);
try {
assertEquals("http://www.example.org/", session.getNamespaceURI("test"));
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
assertTrue(manager.hasNodeType("test:unstructured"));
NodeType type = manager.getNodeType("test:unstructured");
assertFalse(type.isMixin());
assertTrue(type.isNodeType("nt:unstructured"));
assertTrue(session.nodeExists("/properties"));
Node properties = session.getNode("/properties");
assertEquals(PropertyType.BOOLEAN, properties.getProperty("boolean").getType());
assertEquals(true, properties.getProperty("boolean").getBoolean());
assertEquals(PropertyType.BINARY, properties.getProperty("binary").getType());
Binary binary = properties.getProperty("binary").getBinary();
try {
InputStream stream = binary.getStream();
try {
for (int i = 0; i < BINARY.length; i++) {
assertEquals(BINARY[i], (byte) stream.read());
}
assertEquals(-1, stream.read());
} finally {
stream.close();
}
} finally {
binary.dispose();
}
assertEquals(PropertyType.DATE, properties.getProperty("date").getType());
assertEquals(DATE.getTimeInMillis(), properties.getProperty("date").getDate().getTimeInMillis());
assertEquals(PropertyType.DECIMAL, properties.getProperty("decimal").getType());
assertEquals(new BigDecimal(123), properties.getProperty("decimal").getDecimal());
assertEquals(PropertyType.DOUBLE, properties.getProperty("double").getType());
assertEquals(Math.PI, properties.getProperty("double").getDouble());
assertEquals(PropertyType.LONG, properties.getProperty("long").getType());
assertEquals(9876543210L, properties.getProperty("long").getLong());
assertEquals(PropertyType.REFERENCE, properties.getProperty("reference").getType());
assertEquals(identifier, properties.getProperty("reference").getString());
assertEquals("/referenceable", properties.getProperty("reference").getNode().getPath());
assertEquals(PropertyType.STRING, properties.getProperty("string").getType());
assertEquals("test", properties.getProperty("string").getString());
assertEquals(PropertyType.STRING, properties.getProperty("multiple").getType());
Value[] values = properties.getProperty("multiple").getValues();
assertEquals(3, values.length);
assertEquals("a", values[0].getString());
assertEquals("b", values[1].getString());
assertEquals("c", values[2].getString());
} finally {
session.logout();
}
} finally {
repository.shutdown();
}
}
use of javax.jcr.Binary in project vorto by eclipse.
the class ModelSequencerOld method execute.
@Override
public boolean execute(Property inputProperty, Node outputNode, Context context) throws Exception {
Binary binaryValue = inputProperty.getBinary();
CheckArg.isNotNull(binaryValue, "binary");
ModelInfo modelResource = null;
try {
IModelParser parser = ModelParserFactory.instance().getParser(outputNode.getPath());
modelResource = parser.parse(binaryValue.getStream());
outputNode.setProperty("vorto:description", modelResource.getDescription() != null ? modelResource.getDescription() : "");
outputNode.setProperty("vorto:type", modelResource.getType().name());
outputNode.setProperty("vorto:displayname", modelResource.getDisplayName());
outputNode.setProperty("vorto:version", modelResource.getId().getVersion());
outputNode.setProperty("vorto:namespace", modelResource.getId().getNamespace());
outputNode.setProperty("vorto:name", modelResource.getId().getName());
if (outputNode.hasProperty("vorto:references")) {
// first remove any previous references of the node.
outputNode.getProperty("vorto:references").remove();
outputNode.getSession().save();
}
ModelReferencesHelper referencesHelper = new ModelReferencesHelper(modelResource.getReferences());
if (referencesHelper.hasReferences()) {
List<Value> references = new ArrayList<Value>();
for (ModelId modelId : referencesHelper.getReferences()) {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node referencedFolder = outputNode.getSession().getNode(modelIdHelper.getFullPath());
Node reference = referencedFolder.getNodes().nextNode();
references.add(context.valueFactory().createValue(reference));
}
outputNode.setProperty("vorto:references", references.toArray(new Value[references.size()]));
}
} catch (Throwable couldNotParse) {
outputNode.setProperty("vorto:description", "Erronous Model !!!!");
outputNode.setProperty("vorto:type", ModelType.create(outputNode.getPath()).name());
outputNode.setProperty("vorto:displayname", "");
outputNode.setProperty("vorto:version", "1.0.0");
outputNode.setProperty("vorto:namespace", "erronous");
outputNode.setProperty("vorto:name", outputNode.getName());
}
return true;
}
Aggregations