本文整理汇总了Java中javax.jcr.ValueFactory类的典型用法代码示例。如果您正苦于以下问题:Java ValueFactory类的具体用法?Java ValueFactory怎么用?Java ValueFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ValueFactory类属于javax.jcr包,在下文中一共展示了ValueFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import javax.jcr.ValueFactory; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
super.setUp();
Session session = openSession();
Node node = session.getRootNode().addNode("home").addNode("test");
node.setProperty("content.approved", APPROVED);
node.setProperty("my.contents.property", CONTENT);
ValueFactory valFact = session.getValueFactory();
Value[] vals = new Value[] {valFact.createValue("value-1"), valFact.createValue("value-2")};
node.setProperty("my.multi.valued", vals);
identifier = node.getIdentifier();
session.save();
session.logout();
}
示例2: mapSerializedFieldToProperty
import javax.jcr.ValueFactory; //导入依赖的package包/类
private void mapSerializedFieldToProperty(Field field, Object obj, Node node, int depth, NodeFilter nodeFilter) throws IllegalAccessException, RepositoryException, IOException {
String propertyName = getSerializedPropertyName(field);
Object fieldValue = getObject(field, obj);
// make sure that this property is supposed to be updated
if (nodeFilter == null || nodeFilter.isIncluded(NodeFilter.PROPERTY_PREFIX + field.getName(), node, depth)) {
if (fieldValue != null) {
// serialize and store
//node.setProperty(propertyName, new ByteArrayInputStream(serialize(fieldValue)));
ValueFactory valueFactory = node.getSession().getValueFactory();
Binary binary = valueFactory.createBinary(new ByteArrayInputStream(serialize(fieldValue)));
node.setProperty(propertyName, binary);
} else {
// remove the value
node.setProperty(propertyName, (Value) null);
}
}
}
示例3: testMvRestrictions
import javax.jcr.ValueFactory; //导入依赖的package包/类
@Test
public void testMvRestrictions() throws Exception {
ValueFactory vf = getValueFactory();
Value[] vs = new Value[] {
vf.createValue(JcrConstants.NT_FILE, PropertyType.NAME),
vf.createValue(JcrConstants.NT_FOLDER, PropertyType.NAME)
};
Map<String, Value[]> mvRestrictions = Collections.singletonMap(REP_NT_NAMES, vs);
Map<String, Value> restrictions = Collections.singletonMap(REP_GLOB, vf.createValue("/.*"));
assertTrue(acl.addEntry(testPrincipal, testPrivileges, false, restrictions, mvRestrictions));
assertFalse(acl.addEntry(testPrincipal, testPrivileges, false, restrictions, mvRestrictions));
assertEquals(1, acl.getAccessControlEntries().length);
JackrabbitAccessControlEntry ace = (JackrabbitAccessControlEntry) acl.getAccessControlEntries()[0];
try {
ace.getRestriction(REP_NT_NAMES);
fail();
} catch (ValueFormatException e) {
// success
}
Value[] vvs = ace.getRestrictions(REP_NT_NAMES);
assertArrayEquals(vs, vvs);
}
示例4: before
import javax.jcr.ValueFactory; //导入依赖的package包/类
@Override
@Before
public void before() throws Exception {
super.before();
acMgr = getAccessControlManager(root);
testPrincipal = new Principal() {
public String getName() {
return "TestPrincipal";
}
};
ValueFactory valueFactory = new ValueFactoryImpl(root, namePathMapper);
globValue = valueFactory.createValue("*");
nameValue = valueFactory.createValue("nt:file", PropertyType.NAME);
nameValues = new Value[] {
valueFactory.createValue("nt:folder", PropertyType.NAME),
valueFactory.createValue("nt:file", PropertyType.NAME)
};
}
示例5: testAddPropertyToNode
import javax.jcr.ValueFactory; //导入依赖的package包/类
@Test
public void testAddPropertyToNode() throws IOException, RepositoryException {
List<String> propValues = new ArrayList<String>();
propValues.add("value1");
MockNode mockRootNode = new MockNode("/", "jcr:root");
Session mockSession = mock(Session.class);
mockRootNode.setSession(mockSession);
Node testNode = mockRootNode.addNode("/test", "hippo:document");
testNode.setProperty("hippostdpubwf:createdBy", "admin");
JcrProperty jcrProperty = new JcrProperty();
jcrProperty.setName("propname");
jcrProperty.setValues(propValues);
jcrProperty.setType("String");
jcrProperty.setMultiple(false);
final ValueFactory valueFactory = mock(ValueFactory.class);
when(mockRootNode.getSession().getValueFactory()).thenReturn(valueFactory);
when(valueFactory.createValue("value1", 1)).thenReturn(new MockValue("value1"));
JcrDataBindingHelper.addPropertyToNode(mockRootNode, jcrProperty);
assertTrue(mockRootNode.hasProperty("propname"));
}
示例6: mapSerializedFieldToProperty
import javax.jcr.ValueFactory; //导入依赖的package包/类
private void mapSerializedFieldToProperty(Field field, Object obj, Node node, int depth, NodeFilter nodeFilter) throws IllegalAccessException,
RepositoryException, IOException
{
String propertyName = getSerializedPropertyName(field);
Object fieldValue = field.get(obj);
// make sure that this property is supposed to be updated
if (nodeFilter == null || nodeFilter.isIncluded(NodeFilter.PROPERTY_PREFIX + field.getName(), node, depth))
{
if (fieldValue != null)
{
// serialize and store
// node.setProperty(propertyName, new ByteArrayInputStream(serialize(fieldValue)));
ValueFactory valueFactory = node.getSession().getValueFactory();
Binary binary = valueFactory.createBinary(new ByteArrayInputStream(serialize(fieldValue)));
node.setProperty(propertyName, binary);
}
else
{
// remove the value
node.setProperty(propertyName, (Value) null);
}
}
}
示例7: createValues
import javax.jcr.ValueFactory; //导入依赖的package包/类
/**
* @param factory
* the factory used to perform the conversion (cannot be <code>null</code>)
* @param values
* the values being converted to a JCR value holders (cannot be <code>null</code>)
* @param jcrPropType
* the JCR {@link PropertyType property type}
* @return the JCR value holders (never <code>null</code>)
* @throws Exception
* if an error occurs
*/
public static Value[] createValues( final ValueFactory factory,
final Object[] values,
final int jcrPropType ) throws Exception {
final List< Value > result = new ArrayList<>();
if ( ( values == null ) || ( values.length == 0 ) ) {
return NO_VALUES;
}
for ( final Object value : values ) {
result.add( createValue( factory, value, jcrPropType ) );
}
return result.toArray( new Value[ result.size() ] );
}
示例8: createOrUpdateIndex
import javax.jcr.ValueFactory; //导入依赖的package包/类
private void createOrUpdateIndex(Node indexNode, IndexDefinition def) throws RepositoryException {
ValueFactory valueFactory = indexNode.getSession().getValueFactory();
indexNode.setProperty(PN_TYPE, TYPE_PROPERTY);
indexNode.setProperty(PN_PROPERTY_NAMES,
new Value[] { valueFactory.createValue(def.propertyName, PropertyType.NAME) });
if (def.async) {
indexNode.setProperty(PN_ASYNC, PN_ASYNC);
} else if (indexNode.hasProperty(PN_ASYNC)) {
indexNode.getProperty(PN_ASYNC).remove();
}
if (def.unique) {
indexNode.setProperty(PN_UNIQUE, true);
} else if (indexNode.hasProperty(PN_UNIQUE)) {
indexNode.getProperty(PN_UNIQUE).remove();
}
if (def.declaringNodeTypes != null && def.declaringNodeTypes.length > 0) {
Value[] values = new Value[def.declaringNodeTypes.length];
for (int i = 0; i < def.declaringNodeTypes.length; i++) {
values[i] = valueFactory.createValue(def.declaringNodeTypes[0], PropertyType.NAME);
}
indexNode.setProperty(PN_DECLARING_NODE_TYPES, values);
} else if (indexNode.hasProperty(PN_DECLARING_NODE_TYPES)) {
indexNode.getProperty(PN_DECLARING_NODE_TYPES).remove();
}
}
示例9: getArtifactsByChecksum
import javax.jcr.ValueFactory; //导入依赖的package包/类
@Override
public List<ArtifactMetadata> getArtifactsByChecksum( String repositoryId, String checksum )
throws MetadataRepositoryException
{
List<ArtifactMetadata> artifacts;
String q = getArtifactQuery( repositoryId ) + " AND ([sha1] = $checksum OR [md5] = $checksum)";
try
{
Query query = getJcrSession().getWorkspace().getQueryManager().createQuery( q, Query.JCR_SQL2 );
ValueFactory valueFactory = getJcrSession().getValueFactory();
query.bindValue( "checksum", valueFactory.createValue( checksum ) );
QueryResult result = query.execute();
artifacts = new ArrayList<>();
for ( Node n : JcrUtils.getNodes( result ) )
{
artifacts.add( getArtifactFromNode( repositoryId, n ) );
}
}
catch ( RepositoryException e )
{
throw new MetadataRepositoryException( e.getMessage(), e );
}
return artifacts;
}
示例10: runJcrQuery
import javax.jcr.ValueFactory; //导入依赖的package包/类
private List<ArtifactMetadata> runJcrQuery( String repositoryId, String q, Map<String, String> bindings )
throws MetadataRepositoryException
{
List<ArtifactMetadata> artifacts;
if ( repositoryId != null )
{
q += " AND ISDESCENDANTNODE(artifact,'/" + getRepositoryContentPath( repositoryId ) + "')";
}
log.info( "Running JCR Query: {}", q );
try
{
Query query = getJcrSession().getWorkspace().getQueryManager().createQuery( q, Query.JCR_SQL2 );
ValueFactory valueFactory = getJcrSession().getValueFactory();
for ( Entry<String, String> entry : bindings.entrySet() )
{
query.bindValue( entry.getKey(), valueFactory.createValue( entry.getValue() ) );
}
long start = Calendar.getInstance().getTimeInMillis();
QueryResult result = query.execute();
long end = Calendar.getInstance().getTimeInMillis();
log.info( "JCR Query ran in {} milliseconds: {}", end - start , q );
artifacts = new ArrayList<>();
RowIterator rows = result.getRows();
while ( rows.hasNext() )
{
Row row = rows.nextRow();
Node node = row.getNode( "artifact" );
artifacts.add( getArtifactFromNode( repositoryId, node ) );
}
}
catch ( RepositoryException e )
{
throw new MetadataRepositoryException( e.getMessage(), e );
}
return artifacts;
}
示例11: setUp
import javax.jcr.ValueFactory; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
super.setUp();
Session session = openSession();
ValueFactory valFact = session.getValueFactory();
multiValued = new Value[]{valFact.createValue("value-1"),
valFact.createValue("value-2")};
session.logout();
}
示例12: PermissionActionHelper
import javax.jcr.ValueFactory; //导入依赖的package包/类
public PermissionActionHelper(final ValueFactory valueFactory, final String path, final String glob,
final List<String> permissions) {
this.valueFactory = valueFactory;
this.path = path;
this.glob = glob;
this.permissions = permissions;
}
示例13: saveScript
import javax.jcr.ValueFactory; //导入依赖的package包/类
private Script saveScript(ResourceResolver resolver, final String fileName, final InputStream input,
final boolean overwrite) {
Script result = null;
final Session session = resolver.adaptTo(Session.class);
final ValueFactory valueFactory;
try {
valueFactory = session.getValueFactory();
final Binary binary = valueFactory.createBinary(input);
final Node saveNode = session.getNode(getSavePath());
final Node fileNode, contentNode;
if (overwrite && saveNode.hasNode(fileName)) {
fileNode = saveNode.getNode(fileName);
contentNode = fileNode.getNode(JcrConstants.JCR_CONTENT);
} else {
fileNode = saveNode.addNode(generateFileName(fileName, saveNode), JcrConstants.NT_FILE);
contentNode = fileNode.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
}
contentNode.setProperty(JcrConstants.JCR_DATA, binary);
contentNode.setProperty(JcrConstants.JCR_ENCODING, SCRIPT_ENCODING.name());
JcrUtils.setLastModified(contentNode, Calendar.getInstance());
session.save();
result = scriptFinder.find(fileNode.getPath(), resolver);
} catch (RepositoryException e) {
LOG.error(e.getMessage(), e);
}
return result;
}
示例14: createGroups
import javax.jcr.ValueFactory; //导入依赖的package包/类
/**
* Create user groups for authors and testers.
*
* @param bundleContext The bundle context provided by the component.
*/
private void createGroups(BundleContext bundleContext){
ServiceReference SlingRepositoryFactoryReference = bundleContext.getServiceReference(SlingRepository.class.getName());
SlingRepository repository = (SlingRepository)bundleContext.getService(SlingRepositoryFactoryReference);
Session session = null;
if (repository != null) {
try {
session = repository.loginAdministrative(null);
if (session != null && session instanceof JackrabbitSession) {
UserManager userManager = ((JackrabbitSession)session).getUserManager();
ValueFactory valueFactory = session.getValueFactory();
Authorizable authors = userManager.getAuthorizable(PublickConstants.GROUP_ID_AUTHORS);
if (authors == null) {
authors = userManager.createGroup(PublickConstants.GROUP_ID_AUTHORS);
authors.setProperty(GROUP_DISPLAY_NAME, valueFactory.createValue(PublickConstants.GROUP_DISPLAY_AUTHORS));
}
Authorizable testers = userManager.getAuthorizable(PublickConstants.GROUP_ID_TESTERS);
if (testers == null) {
testers = userManager.createGroup(PublickConstants.GROUP_ID_TESTERS);
testers.setProperty(GROUP_DISPLAY_NAME, valueFactory.createValue(PublickConstants.GROUP_DISPLAY_TESTERS));
}
}
} catch (RepositoryException e) {
LOGGER.error("Could not get session", e);
} finally {
if (session != null && session.isLive()) {
session.logout();
session = null;
}
}
}
}
示例15: getValueFactory
import javax.jcr.ValueFactory; //导入依赖的package包/类
/**
* @see org.springframework.extensions.jcr.JcrOperations#getValueFactory()
*/
@Override
public ValueFactory getValueFactory() {
return execute(new JcrCallback<ValueFactory>() {
/**
* @see JcrCallback#doInJcr(javax.jcr.Session)
*/
@Override
public ValueFactory doInJcr(Session session) throws RepositoryException {
return session.getValueFactory();
}
}, true);
}