Search in sources :

Example 6 with PropInfo

use of org.apache.jackrabbit.oak.spi.xml.PropInfo in project jackrabbit-oak by apache.

the class AccessControlImporter method startChildInfo.

@Override
public void startChildInfo(@Nonnull NodeInfo childInfo, @Nonnull List<PropInfo> propInfos) throws RepositoryException {
    checkInitialized();
    String ntName = childInfo.getPrimaryTypeName();
    if (NT_REP_GRANT_ACE.equals(ntName) || NT_REP_DENY_ACE.equals(ntName)) {
        if (entry != null) {
            throw new ConstraintViolationException("Invalid child node sequence: ACEs may not be nested.");
        }
        entry = new MutableEntry(NT_REP_GRANT_ACE.equals(ntName));
        for (PropInfo prop : propInfos) {
            String name = prop.getName();
            if (REP_PRINCIPAL_NAME.equals(name)) {
                entry.setPrincipal(prop.getTextValue());
            } else if (REP_PRIVILEGES.equals(name)) {
                entry.setPrivilegeNames(prop.getTextValues());
            } else {
                entry.addRestriction(prop);
            }
        }
        childStatus = CHILD_STATUS_ACE;
    } else if (NT_REP_RESTRICTIONS.equals(ntName)) {
        if (entry == null) {
            throw new ConstraintViolationException("Invalid child node sequence: Restriction must be associated with an ACE");
        }
        entry.addRestrictions(propInfos);
        childStatus = CHILD_STATUS_RESTRICTION;
    } else {
        throw new ConstraintViolationException("Invalid child node with type " + ntName);
    }
}
Also used : ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo)

Example 7 with PropInfo

use of org.apache.jackrabbit.oak.spi.xml.PropInfo in project jackrabbit-oak by apache.

the class DocViewImportHandler method processCharacters.

/**
     * Translates character data reported by the
     * {@code {@link #characters(char[], int, int)}} &
     * {@code {@link #ignorableWhitespace(char[], int, int)}} SAX events
     * into a  {@code jcr:xmltext} child node with one
     * {@code jcr:xmlcharacters} property.
     *
     * @throws SAXException if an error occurs
     * @see #appendCharacters(char[], int, int)
     */
private void processCharacters() throws SAXException {
    try {
        if (textHandler != null && textHandler.length() > 0) {
            // there is character data that needs to be added to
            // the current node
            // check for pure whitespace character data
            Reader reader = textHandler.reader();
            try {
                int ch;
                while ((ch = reader.read()) != -1) {
                    if (ch > 0x20) {
                        break;
                    }
                }
                if (ch == -1) {
                    // the character data consists of pure whitespace, ignore
                    log.debug("ignoring pure whitespace character data...");
                    // reset handler
                    textHandler.dispose();
                    textHandler = null;
                    return;
                }
            } finally {
                reader.close();
            }
            NodeInfo node = new NodeInfo(getJcrName(NamespaceRegistry.NAMESPACE_JCR, "xmltext"), null, null, null);
            ArrayList<PropInfo> props = new ArrayList<PropInfo>();
            props.add(new PropInfo(getJcrName(NamespaceRegistry.NAMESPACE_JCR, "xmlcharacters"), PropertyType.STRING, textHandler));
            // call Importer
            importer.startNode(node, props);
            importer.endNode(node);
            // reset handler
            textHandler.dispose();
            textHandler = null;
        }
    } catch (IOException ioe) {
        String msg = "internal error while processing internal buffer data";
        log.error(msg, ioe);
        throw new SAXException(msg, ioe);
    } catch (RepositoryException re) {
        throw new SAXException(re);
    }
}
Also used : NodeInfo(org.apache.jackrabbit.oak.spi.xml.NodeInfo) ArrayList(java.util.ArrayList) Reader(java.io.Reader) PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 8 with PropInfo

use of org.apache.jackrabbit.oak.spi.xml.PropInfo in project jackrabbit-oak by apache.

the class SysViewImportHandler method processNode.

private void processNode(ImportState state, boolean start, boolean end) throws SAXException {
    if (!start && !end) {
        return;
    }
    String id = state.uuid;
    NodeInfo node = new NodeInfo(state.nodeName, state.nodeTypeName, state.mixinNames, id);
    // call Importer
    try {
        if (start) {
            importer.startNode(node, state.props);
            // dispose temporary property values
            for (PropInfo pi : state.props) {
                pi.dispose();
            }
        }
        if (end) {
            importer.endNode(node);
        }
    } catch (RepositoryException re) {
        throw new SAXException(re);
    }
}
Also used : NodeInfo(org.apache.jackrabbit.oak.spi.xml.NodeInfo) PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo) RepositoryException(javax.jcr.RepositoryException) SAXException(org.xml.sax.SAXException)

Example 9 with PropInfo

use of org.apache.jackrabbit.oak.spi.xml.PropInfo in project jackrabbit-oak by apache.

the class SysViewImportHandler method endElement.

@Override
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
    // check element name
    ImportState state = stack.peek();
    if (namespaceURI.equals(NamespaceConstants.NAMESPACE_SV) && "node".equals(localName)) {
        // sv:node element
        if (!state.started) {
            // need to start & end current node
            processNode(state, true, true);
            state.started = true;
        } else {
            // need to end current node
            processNode(state, false, true);
        }
        // pop current state from stack
        stack.pop();
    } else if (namespaceURI.equals(NamespaceConstants.NAMESPACE_SV) && "property".equals(localName)) {
        // have been collected and create node as necessary primaryType
        if (isSystemProperty("primaryType")) {
            BufferedStringValue val = currentPropValues.get(0);
            String s = null;
            try {
                s = val.retrieve();
                state.nodeTypeName = new NameInfo(s).getRepoQualifiedName();
            } catch (IOException e) {
                throw new SAXException(new InvalidSerializedDataException("illegal node type name: " + s, e));
            } catch (RepositoryException e) {
                throw new SAXException(new InvalidSerializedDataException("illegal node type name: " + s, e));
            }
        } else if (isSystemProperty("mixinTypes")) {
            if (state.mixinNames == null) {
                state.mixinNames = new ArrayList<String>(currentPropValues.size());
            }
            for (BufferedStringValue val : currentPropValues) {
                String s = null;
                try {
                    s = val.retrieve();
                    state.mixinNames.add(new NameInfo(s).getRepoQualifiedName());
                } catch (IOException ioe) {
                    throw new SAXException("error while retrieving value", ioe);
                } catch (RepositoryException e) {
                    throw new SAXException(new InvalidSerializedDataException("illegal mixin type name: " + s, e));
                }
            }
        } else if (isSystemProperty("uuid")) {
            BufferedStringValue val = currentPropValues.get(0);
            try {
                state.uuid = val.retrieve();
            } catch (IOException ioe) {
                throw new SAXException("error while retrieving value", ioe);
            }
        } else {
            if (currentPropMultipleStatus == PropInfo.MultipleStatus.UNKNOWN && currentPropValues.size() != 1) {
                currentPropMultipleStatus = PropInfo.MultipleStatus.MULTIPLE;
            }
            PropInfo prop = new PropInfo(currentPropName == null ? null : currentPropName.getRepoQualifiedName(), currentPropType, currentPropValues, currentPropMultipleStatus);
            state.props.add(prop);
        }
        // reset temp fields
        currentPropValues.clear();
    } else if (namespaceURI.equals(NamespaceConstants.NAMESPACE_SV) && "value".equals(localName)) {
        // sv:value element
        currentPropValues.add(currentPropValue);
        // reset temp fields
        currentPropValue = null;
    } else {
        throw new SAXException(new InvalidSerializedDataException("invalid element in system view xml document: " + localName));
    }
}
Also used : InvalidSerializedDataException(javax.jcr.InvalidSerializedDataException) RepositoryException(javax.jcr.RepositoryException) PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 10 with PropInfo

use of org.apache.jackrabbit.oak.spi.xml.PropInfo in project jackrabbit-oak by apache.

the class AccessControlImporterBaseTest method testImportWithRestrictionNodeInfo.

@Test
public void testImportWithRestrictionNodeInfo() throws Exception {
    // single value restriction
    PropInfo globInfo = new PropInfo(REP_GLOB, PropertyType.STRING, createTextValue("/*"));
    // mv restriction
    PropInfo ntNamesInfo = new PropInfo(REP_NT_NAMES, PropertyType.NAME, createTextValues(NodeTypeConstants.NT_OAK_RESOURCE, NodeTypeConstants.NT_OAK_RESOURCE));
    // mv restriction with singular value
    PropInfo itemNamesInfo = new PropInfo(REP_ITEM_NAMES, PropertyType.NAME, createTextValue("itemName"));
    init();
    importer.start(aclTree);
    importer.startChildInfo(aceInfo, ImmutableList.of(principalInfo, privInfo));
    importer.startChildInfo(restrInfo, ImmutableList.of(globInfo, ntNamesInfo, itemNamesInfo));
    importer.endChildInfo();
    importer.endChildInfo();
    importer.end(aclTree);
    assertImport(aclTree, principalName);
}
Also used : PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

PropInfo (org.apache.jackrabbit.oak.spi.xml.PropInfo)15 Test (org.junit.Test)8 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)5 RepositoryException (javax.jcr.RepositoryException)4 SAXException (org.xml.sax.SAXException)4 Tree (org.apache.jackrabbit.oak.api.Tree)3 NodeInfo (org.apache.jackrabbit.oak.spi.xml.NodeInfo)3 TextValue (org.apache.jackrabbit.oak.spi.xml.TextValue)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Reader (java.io.Reader)1 InvalidSerializedDataException (javax.jcr.InvalidSerializedDataException)1 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)1 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)1 AccessControlManager (javax.jcr.security.AccessControlManager)1 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)1