Search in sources :

Example 76 with PropertyDefinition

use of javax.jcr.nodetype.PropertyDefinition in project sling by apache.

the class MockPropertyDefGenerator method getSimplePropertyDef.

public PropertyDefinition getSimplePropertyDef(String name) {
    PropertyDefinition propertyDef = mock(PropertyDefinition.class);
    when(propertyDef.getOnParentVersion()).thenReturn(OnParentVersionAction.COPY);
    when(propertyDef.getName()).thenReturn(name);
    return propertyDef;
}
Also used : PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 77 with PropertyDefinition

use of javax.jcr.nodetype.PropertyDefinition in project sling by apache.

the class MockPropertyDefGenerator method getEqualPropertyDefinitions.

@SuppressWarnings("deprecation")
public PropertyDefinition[] getEqualPropertyDefinitions() throws ValueFormatException, RepositoryException {
    Value defaultValue1 = mock(Value.class);
    when(defaultValue1.getType()).thenReturn(PropertyType.BINARY);
    when(defaultValue1.getStream()).thenReturn(new ByteArrayInputStream("A content".getBytes()));
    Value defaultValue2 = mock(Value.class);
    when(defaultValue2.getType()).thenReturn(PropertyType.BINARY);
    when(defaultValue2.getStream()).thenReturn(new ByteArrayInputStream("An other content".getBytes()));
    PropertyDefinition binPropDef1 = this.getPropertyDef("binPropDef", PropertyType.BINARY, true, true, true, true, OnParentVersionAction.VERSION, new String[] { "[,1024]", "[,2048]" }, new Value[] { defaultValue1, defaultValue2 });
    PropertyDefinition binPropDef2 = this.getPropertyDef("binPropDef", PropertyType.BINARY, true, true, true, true, OnParentVersionAction.VERSION, new String[] { "[,1024]", "[,512]" }, new Value[] { defaultValue1, defaultValue2 });
    return new PropertyDefinition[] { binPropDef2, binPropDef1 };
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Value(javax.jcr.Value) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 78 with PropertyDefinition

use of javax.jcr.nodetype.PropertyDefinition in project sling by apache.

the class MockPropertyDefGenerator method getCompletePropertyDev.

private PropertyDefinition getCompletePropertyDev(String name, Integer type, String[] valueConstraints, String defaultValueString) throws ValueFormatException, RepositoryException {
    Value defaultValue = mock(Value.class);
    when(defaultValue.getString()).thenReturn(defaultValueString);
    PropertyDefinition propertyDef = getPropertyDef(name, type, valueConstraints, new Value[] { defaultValue });
    return propertyDef;
}
Also used : Value(javax.jcr.Value) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 79 with PropertyDefinition

use of javax.jcr.nodetype.PropertyDefinition in project sling by apache.

the class JcrNode method getPropertyType.

public int getPropertyType(String propertyName) {
    PropertyDefinition pd = getPropertyDefinition(propertyName);
    if (pd != null) {
        return pd.getRequiredType();
    }
    // otherwise use the SerializationManager to read the
    // underlying vault file and derive the propertyType from there
    GenericJcrRootFile u = properties.getUnderlying();
    if (u == null) {
        // no underlying properties file, that's not good
        Activator.getDefault().getPluginLogger().warn("No underlying properties file, cannot derive propertyType (" + propertyName + ") for " + this);
        return -1;
    }
    IFolder contentSyncRoot = ProjectUtil.getSyncDirectory(getProject());
    IFile file = (IFile) u.file;
    try (InputStream contents = file.getContents()) {
        String resourceLocation = file.getFullPath().makeRelativeTo(contentSyncRoot.getFullPath()).toPortableString();
        ResourceProxy resourceProxy = Activator.getDefault().getSerializationManager().readSerializationData(resourceLocation, contents);
        // resourceProxy could be containing a full tree
        // dive into the right position
        String rawValue = properties.getValue(propertyName);
        return PropertyTypeSupport.propertyTypeOfString(rawValue);
    } catch (Exception e) {
        Activator.getDefault().getPluginLogger().warn("Exception occurred during analyzing propertyType (" + propertyName + ") for " + this, e);
    }
    return -1;
}
Also used : IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) CoreException(org.eclipse.core.runtime.CoreException) XMLParseException(de.pdark.decentxml.XMLParseException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) RepositoryException(org.apache.sling.ide.transport.RepositoryException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IFolder(org.eclipse.core.resources.IFolder)

Example 80 with PropertyDefinition

use of javax.jcr.nodetype.PropertyDefinition in project sling by apache.

the class JcrNode method getPropertyDefinition.

public PropertyDefinition getPropertyDefinition(String propertyName) {
    NodeType nt0 = getNodeType();
    if (nt0 == null) {
        return null;
    }
    List<NodeType> nodeTypes = new LinkedList<>();
    nodeTypes.add(nt0);
    // add all supertypes
    nodeTypes.addAll(Arrays.asList(nt0.getSupertypes()));
    for (Iterator<NodeType> it = nodeTypes.iterator(); it.hasNext(); ) {
        NodeType nt = it.next();
        PropertyDefinition[] pds = nt.getPropertyDefinitions();
        for (int i = 0; i < pds.length; i++) {
            PropertyDefinition propertyDefinition = pds[i];
            if (propertyDefinition.getName().equals(propertyName)) {
                return propertyDefinition;
            }
        }
    }
    return null;
}
Also used : NodeType(javax.jcr.nodetype.NodeType) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) LinkedList(java.util.LinkedList)

Aggregations

PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)141 NodeType (javax.jcr.nodetype.NodeType)79 Value (javax.jcr.Value)70 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)61 Node (javax.jcr.Node)27 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)22 Property (javax.jcr.Property)20 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)15 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)14 RepositoryException (javax.jcr.RepositoryException)13 NodeDefinition (javax.jcr.nodetype.NodeDefinition)13 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)11 Test (org.junit.Test)11 InputStream (java.io.InputStream)5 Session (javax.jcr.Session)5 ValueFormatException (javax.jcr.ValueFormatException)5 PropertyDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 Name (org.apache.jackrabbit.spi.Name)4