Search in sources :

Example 21 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 22 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 23 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 24 with PropInfo

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

the class CugImporterTest method testInvalidPropInfo.

@Test
public void testInvalidPropInfo() throws Exception {
    createCug(root, SUPPORTED_PATH, "principalName");
    Tree parent = root.getTree(SUPPORTED_PATH);
    PropInfo propInfo = new PropInfo(JcrConstants.JCR_PRIMARYTYPE, PropertyType.STRING, ImmutableList.of(new TextValue() {

        @Override
        public String getString() {
            return "principalName";
        }

        @Override
        public Value getValue(int targetType) throws RepositoryException {
            return getValueFactory(root).createValue("principalName", PropertyType.STRING);
        }

        @Override
        public void dispose() {
        }
    }));
    PropertyDefinition propDef = Mockito.mock(PropertyDefinition.class);
    assertFalse(importer.handlePropInfo(parent, propInfo, propDef));
}
Also used : TextValue(org.apache.jackrabbit.oak.spi.xml.TextValue) Tree(org.apache.jackrabbit.oak.api.Tree) PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) Test(org.junit.Test)

Example 25 with PropInfo

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

the class PrincipalPolicyImporterTest method testStartChildInfoWrongEffectivePathPropertyType.

@Test(expected = ConstraintViolationException.class)
public void testStartChildInfoWrongEffectivePathPropertyType() throws Exception {
    init(true, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
    User user = getTestSystemUser();
    Tree policyTree = createPolicyTree(user);
    importer.handlePropInfo(policyTree, mockPropInfo(user.getPrincipal()), mockPropertyDefinition(getJcrName(NT_REP_PRINCIPAL_POLICY)));
    List<PropInfo> propInfos = mockPropInfos(null, PrivilegeConstants.JCR_REMOVE_CHILD_NODES);
    // effective path with wrong type
    TextValue tx = when(mock(TextValue.class).getString()).thenReturn("/effective/path").getMock();
    PropInfo propInfo = mockPropInfo(getJcrName(REP_EFFECTIVE_PATH));
    when(propInfo.getTextValue()).thenReturn(tx);
    when(propInfo.getType()).thenReturn(PropertyType.STRING);
    propInfos.add(propInfo);
    importer.startChildInfo(mockNodeInfo("entry", getJcrName(NT_REP_PRINCIPAL_ENTRY)), propInfos);
}
Also used : User(org.apache.jackrabbit.api.security.user.User) TextValue(org.apache.jackrabbit.oak.spi.xml.TextValue) Tree(org.apache.jackrabbit.oak.api.Tree) MockUtility.mockTree(org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl.MockUtility.mockTree) PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo) Test(org.junit.Test)

Aggregations

PropInfo (org.apache.jackrabbit.oak.spi.xml.PropInfo)37 Test (org.junit.Test)26 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)15 Tree (org.apache.jackrabbit.oak.api.Tree)14 MockUtility.mockTree (org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl.MockUtility.mockTree)8 TextValue (org.apache.jackrabbit.oak.spi.xml.TextValue)8 ArrayList (java.util.ArrayList)5 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)5 RepositoryException (javax.jcr.RepositoryException)4 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)4 SAXException (org.xml.sax.SAXException)4 User (org.apache.jackrabbit.api.security.user.User)3 NodeInfo (org.apache.jackrabbit.oak.spi.xml.NodeInfo)3 ImmutableList (com.google.common.collect.ImmutableList)2 IOException (java.io.IOException)2 List (java.util.List)2 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Reader (java.io.Reader)1 Map (java.util.Map)1