javax.jcr.NamespaceException Java Examples
The following examples show how to use
javax.jcr.NamespaceException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JcrNamespaceHelper.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * Attempts to register a namespace * @param pfxHint prefix to use if possible * @param uri uri to register * @return the registered prefix * @throws RepositoryException if an error occurs */ @NotNull public String registerNamespace(@NotNull String pfxHint, @NotNull String uri) throws RepositoryException { int i = 0; String pfx = pfxHint; Throwable error = null; while (i < 1000) { try { session.getWorkspace().getNamespaceRegistry().registerNamespace(pfx, uri); track(tracker, "A", pfx + " -> " + uri); return pfx; } catch (NamespaceException e) { pfx = pfxHint + i++; error = e; } } throw new RepositoryException("Giving up automatic namespace registration after 1000 attempts.", error); }
Example #2
Source File: DocViewAnalyzer.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public String getPrefix(String uri) throws NamespaceException { try { return session.getNamespacePrefix(uri); } catch (RepositoryException e) { throw new NamespaceException(e); } }
Example #3
Source File: DocumentViewParserValidatorTest.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Test public void testDocViewDotContentXmlWithRootElementDifferentThanJcrRoot() throws ParserConfigurationException, SAXException, URISyntaxException, IOException, NamespaceException { try (InputStream input = this.getClass().getResourceAsStream("/simple-package/jcr_root/apps/child2/.content.xml")) { Collection<ValidationMessage> messages = validator.validateJcrData(input, Paths.get("apps", "child2", ".content.xml"), Paths.get(""), nodePathsAndLineNumbers); Assert.assertThat(messages, AnyValidationViolationMatcher.noValidationInCollection()); Map<String, DocViewProperty> properties = new HashMap<>(); properties.put(NameConstants.JCR_PRIMARYTYPE.toString(), new DocViewProperty(NameConstants.JCR_PRIMARYTYPE.toString(), new String[] { "sling:Folder" }, false, PropertyType.UNDEFINED)); DocViewNode node = new DocViewNode("{}child3", "child3", null, properties, null, "sling:Folder"); Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/child3", Paths.get("apps", "child2", ".content.xml"), Paths.get("")), true); properties = new HashMap<>(); properties.put(NameConstants.JCR_PRIMARYTYPE.toString(), new DocViewProperty(NameConstants.JCR_PRIMARYTYPE.toString(), new String[] { JcrConstants.NT_UNSTRUCTURED }, false, PropertyType.UNDEFINED)); properties.put("{}attribute1", new DocViewProperty("{}attribute1", new String[] { "value1" }, false, PropertyType.UNDEFINED)); node = new DocViewNode("{}somepath", "somepath", null, properties, null, JcrConstants.NT_UNSTRUCTURED); Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/child3/somepath", Paths.get("apps", "child2", ".content.xml"), Paths.get("")), false); // verify node names Map<String, Integer> expectedNodePathsAndLineNumber = new HashMap<>(); expectedNodePathsAndLineNumber.put("/apps/child3", 20); expectedNodePathsAndLineNumber.put("/apps/child3/somepath", 23); Assert.assertEquals(expectedNodePathsAndLineNumber, nodePathsAndLineNumbers); } }
Example #4
Source File: DocumentViewParserValidatorTest.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Test public void testDocViewWithRegularFileNameAndUndeclaredNamespacePrefixInFilename() throws ParserConfigurationException, SAXException, URISyntaxException, IOException, NamespaceException { try (InputStream input = this.getClass().getResourceAsStream("/simple-package/jcr_root/apps/child1.xml")) { Collection<ValidationMessage> messages = validator.validateJcrData(input, Paths.get("apps", "_cq_child1.xml"), Paths.get(""), nodePathsAndLineNumbers); ValidationExecutorTest.assertViolation(messages, new ValidationViolation(ValidationMessageSeverity.ERROR, "Invalid XML found: Given root node name 'cq:child1' (implicitly given via filename) cannot be resolved. The prefix used in the filename must be declared as XML namespace in the child docview XML as well!", Paths.get("apps", "_cq_child1.xml"), Paths.get(""), "/apps/cq:child1", 0,0, null)); } }
Example #5
Source File: DocumentViewParserValidatorTest.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Test public void testDocViewWithRegularFileName() throws ParserConfigurationException, SAXException, URISyntaxException, IOException, NamespaceException { try (InputStream input = this.getClass().getResourceAsStream("/simple-package/jcr_root/apps/child1.xml")) { Collection<ValidationMessage> messages = validator.validateJcrData(input, Paths.get("apps", "child1.xml"), Paths.get(""), nodePathsAndLineNumbers); Assert.assertThat(messages, AnyValidationViolationMatcher.noValidationInCollection()); Map<String, DocViewProperty> properties = new HashMap<>(); properties.put(NameConstants.JCR_PRIMARYTYPE.toString(), new DocViewProperty(NameConstants.JCR_PRIMARYTYPE.toString(), new String[] { "sling:Folder" }, false, PropertyType.UNDEFINED)); DocViewNode node = new DocViewNode("{}child1", "jcr:root", null, properties, null, "sling:Folder"); Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/child1", Paths.get("apps", "child1.xml"), Paths.get("")), true); properties = new HashMap<>(); properties.put(NameConstants.JCR_PRIMARYTYPE.toString(), new DocViewProperty(NameConstants.JCR_PRIMARYTYPE.toString(), new String[] { JcrConstants.NT_UNSTRUCTURED }, false, PropertyType.UNDEFINED)); properties.put("{}attribute1", new DocViewProperty("{}attribute1", new String[] { "value1" }, false, PropertyType.UNDEFINED)); node = new DocViewNode("{}somepath", "somepath", null, properties, null, JcrConstants.NT_UNSTRUCTURED); Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/child1/somepath", Paths.get("apps", "child1.xml"), Paths.get("")), false); // verify node names Map<String, Integer> expectedNodePathsAndLineNumber = new HashMap<>(); expectedNodePathsAndLineNumber.put("/apps/child1", 20); expectedNodePathsAndLineNumber.put("/apps/child1/somepath", 23); Assert.assertEquals(expectedNodePathsAndLineNumber, nodePathsAndLineNumbers); } }
Example #6
Source File: DocumentViewParserValidatorTest.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Test public void testDocViewDotContentXmlOnRootLevel() throws ParserConfigurationException, SAXException, URISyntaxException, IOException, NamespaceException { Mockito.when(docViewXmlValidator.validate(Mockito.any(), Mockito.any(), Mockito.anyBoolean())).thenReturn(Collections.singleton(new ValidationMessage(ValidationMessageSeverity.ERROR, "startDocView"))); try (InputStream input = this.getClass().getResourceAsStream("/simple-package/jcr_root/.content.xml")) { Collection<ValidationMessage> messages = validator.validateJcrData(input, Paths.get(".content.xml"), Paths.get(""), nodePathsAndLineNumbers); // filter ValidationExecutorTest.assertViolation(messages, new ValidationViolation("docviewid", ValidationMessageSeverity.ERROR, "startDocView", Paths.get(".content.xml"), Paths.get(""), "/", 6, 32, null )); // verify node names Map<String, Integer> expectedNodePathsAndLineNumber = new HashMap<>(); expectedNodePathsAndLineNumber.put("/", 6); Assert.assertEquals(expectedNodePathsAndLineNumber, nodePathsAndLineNumbers); Map<String, DocViewProperty> properties = new HashMap<>(); properties.put(NameConstants.JCR_PRIMARYTYPE.toString(), new DocViewProperty(NameConstants.JCR_PRIMARYTYPE.toString(), new String[] { "rep:root" }, false, PropertyType.UNDEFINED)); properties.put(NameConstants.JCR_MIXINTYPES.toString(), new DocViewProperty(NameConstants.JCR_MIXINTYPES.toString(), new String[] { "rep:AccessControllable" ,"rep:RepoAccessControllable" }, true, PropertyType.UNDEFINED)); properties.put(NAME_SLING_RESOURCE_TYPE.toString(), new DocViewProperty(NAME_SLING_RESOURCE_TYPE.toString(), new String[] { "sling:redirect" }, false, PropertyType.UNDEFINED)); properties.put(NAME_SLING_TARGET.toString(), new DocViewProperty(NAME_SLING_TARGET.toString(), new String[] { "/index.html" }, false, PropertyType.UNDEFINED)); DocViewNode node = new DocViewNode(NameConstants.JCR_ROOT.toString(), "jcr:root", null, properties, new String[] { "rep:AccessControllable" ,"rep:RepoAccessControllable" }, "rep:root"); Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/", Paths.get(".content.xml"), Paths.get("")), true); } }
Example #7
Source File: DocViewAnalyzer.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public String getURI(String prefix) throws NamespaceException { try { return session.getNamespaceURI(prefix); } catch (RepositoryException e) { throw new NamespaceException(e); } }
Example #8
Source File: DocViewSAXImporter.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public String getPrefix(String uri) throws NamespaceException { try { return session.getNamespacePrefix(uri); } catch (RepositoryException e) { throw new NamespaceException(e); } }
Example #9
Source File: DocumentViewXmlContentHandler.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Override public String getURI(String prefix) throws NamespaceException { if (prefix.isEmpty()) { return Name.NS_DEFAULT_URI; } return namespaceRegistry.get(prefix); }
Example #10
Source File: DocViewSAXImporter.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public String getURI(String prefix) throws NamespaceException { try { return session.getNamespaceURI(prefix); } catch (RepositoryException e) { throw new NamespaceException(e); } }
Example #11
Source File: DocViewNodeTest.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Test public void testEquals() throws NamespaceException { Map<String, DocViewProperty> properties1 = new HashMap<>(); properties1.put("property1", new DocViewProperty("property1", new String[] {"value1"}, false, PropertyType.STRING)); DocViewNode node1 = new DocViewNode("name", "label", "uuid1", properties1, new String[] { "mixin1", "mixin2" }, "primary"); DocViewNode node2 = new DocViewNode("name", "label", "uuid1", properties1, new String[] { "mixin1", "mixin2" }, "primary"); Assert.assertEquals(node1, node2); DocViewNode node3 = new DocViewNode("name", "label", "uuid1", properties1, new String[] { "mixin1", "mixin3" }, "primary"); Assert.assertNotEquals(node1, node3); }
Example #12
Source File: DocViewNode.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
public DocViewNode(String name, String label, Attributes attributes, NamePathResolver npResolver) throws NamespaceException { this.name = name; this.label = label; String uuid = null; String primary = null; String[] mixins = null; for (int i = 0; i < attributes.getLength(); i++) { // ignore non CDATA attributes if (!attributes.getType(i).equals("CDATA")) { continue; } Name pName = NameFactoryImpl.getInstance().create( attributes.getURI(i), ISO9075.decode(attributes.getLocalName(i))); DocViewProperty info = DocViewProperty.parse( npResolver.getJCRName(pName), attributes.getValue(i)); props.put(info.name, info); if (pName.equals(NameConstants.JCR_UUID)) { uuid = info.values[0]; } else if (pName.equals(NameConstants.JCR_PRIMARYTYPE)) { primary = info.values[0]; } else if (pName.equals(NameConstants.JCR_MIXINTYPES)) { mixins = info.values; } } this.uuid = uuid; this.mixins = mixins; this.primary = primary; }
Example #13
Source File: DefaultNodeTypeSet.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private void add(NamespaceMapping mapping) { for (Object o : mapping.getPrefixToURIMapping().keySet()) { try { String pfx = (String) o; String uri = mapping.getURI(pfx); nsMapping.setMapping(pfx, uri); } catch (NamespaceException e) { throw new IllegalStateException("Error while transferring mappings.", e); } } }
Example #14
Source File: DocViewSAXFormatter.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
protected DocViewSAXFormatter(Aggregate aggregate, XMLStreamWriter writer) throws RepositoryException { this.aggregate = aggregate; this.session = aggregate.getNode().getSession(); nsResolver = new SessionNamespaceResolver(session); itemNameComparator = new ItemNameComparator2(nsResolver); this.writer = writer; DefaultNamePathResolver npResolver = new DefaultNamePathResolver(nsResolver); // resolve the names of some well known properties // allowing for session-local prefix mappings try { jcrPrimaryType = npResolver.getJCRName(NameConstants.JCR_PRIMARYTYPE); jcrMixinTypes = npResolver.getJCRName(NameConstants.JCR_MIXINTYPES); jcrUUID = npResolver.getJCRName(NameConstants.JCR_UUID); jcrRoot = npResolver.getJCRName(NameConstants.JCR_ROOT); ntUnstructured = npResolver.getJCRName(NameConstants.NT_UNSTRUCTURED); } catch (NamespaceException e) { // should never get here... String msg = "internal error: failed to resolve namespace mappings"; throw new RepositoryException(msg, e); } useBinaryReferences = "true".equals(aggregate.getManager().getConfig().getProperty(VaultFsConfig.NAME_USE_BINARY_REFERENCES)); }
Example #15
Source File: DocumentViewXmlContentHandler.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
@Override public String getPrefix(String uri) throws NamespaceException { throw new UnsupportedOperationException("Only resolving from prefix to URI is supported, but not vice-versa"); }
Example #16
Source File: SessionFactoryUtils.java From mycollab with GNU Affero General Public License v3.0 | 4 votes |
/** * Jcr exception translator - it converts specific JSR-170 checked exceptions into unchecked Spring DA * exception. * @author Guillaume Bort <[email protected]> * @author Costin Leau * @author Sergio Bossa * @author Salvatore Incandela * @param ex * @return */ public static DataAccessException translateException(RepositoryException ex) { if (ex instanceof AccessDeniedException) { return new DataRetrievalFailureException("Access denied to this data", ex); } if (ex instanceof ConstraintViolationException) { return new DataIntegrityViolationException("Constraint has been violated", ex); } if (ex instanceof InvalidItemStateException) { return new ConcurrencyFailureException("Invalid item state", ex); } if (ex instanceof InvalidQueryException) { return new DataRetrievalFailureException("Invalid query", ex); } if (ex instanceof InvalidSerializedDataException) { return new DataRetrievalFailureException("Invalid serialized data", ex); } if (ex instanceof ItemExistsException) { return new DataIntegrityViolationException("An item already exists", ex); } if (ex instanceof ItemNotFoundException) { return new DataRetrievalFailureException("Item not found", ex); } if (ex instanceof LoginException) { return new DataAccessResourceFailureException("Bad login", ex); } if (ex instanceof LockException) { return new ConcurrencyFailureException("Item is locked", ex); } if (ex instanceof MergeException) { return new DataIntegrityViolationException("Merge failed", ex); } if (ex instanceof NamespaceException) { return new InvalidDataAccessApiUsageException("Namespace not registred", ex); } if (ex instanceof NoSuchNodeTypeException) { return new InvalidDataAccessApiUsageException("No such node type", ex); } if (ex instanceof NoSuchWorkspaceException) { return new DataAccessResourceFailureException("Workspace not found", ex); } if (ex instanceof PathNotFoundException) { return new DataRetrievalFailureException("Path not found", ex); } if (ex instanceof ReferentialIntegrityException) { return new DataIntegrityViolationException("Referential integrity violated", ex); } if (ex instanceof UnsupportedRepositoryOperationException) { return new InvalidDataAccessApiUsageException("Unsupported operation", ex); } if (ex instanceof ValueFormatException) { return new InvalidDataAccessApiUsageException("Incorrect value format", ex); } if (ex instanceof VersionException) { return new DataIntegrityViolationException("Invalid version graph operation", ex); } // fallback return new JcrSystemException(ex); }
Example #17
Source File: DocumentViewXmlContentHandler.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
private Name getExpandedName(String name) throws IllegalNameException, NamespaceException { return NameParser.parse(name, this, NameFactoryImpl.getInstance()); }
Example #18
Source File: DocumentViewParserValidatorTest.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
@Test public void testDocViewDotContentXml() throws ParserConfigurationException, SAXException, URISyntaxException, IOException, NamespaceException { Mockito.when(docViewXmlValidator.validate(Mockito.any(), Mockito.any(), Mockito.anyBoolean())).thenReturn(Collections.singleton(new ValidationMessage(ValidationMessageSeverity.ERROR, "startDocView"))); try (InputStream input = this.getClass().getResourceAsStream("/simple-package/jcr_root/apps/.content.xml")) { Collection<ValidationMessage> messages = validator.validateJcrData(input, Paths.get("apps", ".content.xml"), Paths.get(""), nodePathsAndLineNumbers); // filter ValidationExecutorTest.assertViolation(messages, new ValidationViolation("docviewid", ValidationMessageSeverity.ERROR, "startDocView", Paths.get("apps/.content.xml"), Paths.get(""), "/apps", 19, 35, null ), new ValidationViolation("docviewid", ValidationMessageSeverity.ERROR, "startDocView", Paths.get("apps/.content.xml"), Paths.get(""), "/apps/somepath", 21, 29, null), new ValidationViolation("docviewid", ValidationMessageSeverity.ERROR, "startDocView", Paths.get("apps/.content.xml"), Paths.get(""), "/apps/somepath/jc:content", 22, 54, null), new ValidationViolation("docviewid", ValidationMessageSeverity.ERROR, "startDocView", Paths.get("apps/.content.xml"), Paths.get(""), "/apps/0123_sample.jpg", 25, 29, null), new ValidationViolation("docviewid", ValidationMessageSeverity.ERROR, "startDocView", Paths.get("apps/.content.xml"), Paths.get(""), "/apps/01234_sample.jpg", 26, 55, null)); // verify node names Map<String, Integer> expectedNodePathsAndLineNumber = new HashMap<>(); expectedNodePathsAndLineNumber.put("/apps", 19); expectedNodePathsAndLineNumber.put("/apps/somepath", 21); expectedNodePathsAndLineNumber.put("/apps/somepath/jc:content", 22); expectedNodePathsAndLineNumber.put("/apps/01234_sample.jpg", 26); Assert.assertEquals(expectedNodePathsAndLineNumber, nodePathsAndLineNumbers); Map<String, DocViewProperty> properties = new HashMap<>(); properties.put(NameConstants.JCR_PRIMARYTYPE.toString(), new DocViewProperty(NameConstants.JCR_PRIMARYTYPE.toString(), new String[] { "sling:Folder" }, false, PropertyType.UNDEFINED)); DocViewNode node = new DocViewNode("{}apps", "jc:root", null, properties, null, "sling:Folder"); Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps", Paths.get("apps", ".content.xml"), Paths.get("")), true); properties = new HashMap<>(); properties.put(NameConstants.JCR_PRIMARYTYPE.toString(), new DocViewProperty(NameConstants.JCR_PRIMARYTYPE.toString(), new String[] { JcrConstants.NT_UNSTRUCTURED }, false, PropertyType.UNDEFINED)); properties.put("{}attribute1", new DocViewProperty("{}attribute1", new String[] { "value1" }, false, PropertyType.UNDEFINED)); node = new DocViewNode("{}somepath", "somepath", null, properties, null, JcrConstants.NT_UNSTRUCTURED); Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/somepath", Paths.get("apps", ".content.xml"), Paths.get("")), false); properties = new HashMap<>(); properties.put(NameConstants.JCR_PRIMARYTYPE.toString(), new DocViewProperty(NameConstants.JCR_PRIMARYTYPE.toString(), new String[] { JcrConstants.NT_UNSTRUCTURED }, false, PropertyType.UNDEFINED)); node = new DocViewNode("{http://www.jcp.org/jcr/1.0}content", "jc:content", null, properties, null, JcrConstants.NT_UNSTRUCTURED); Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/somepath/jc:content", Paths.get("apps", ".content.xml"), Paths.get("")), false); } }
Example #19
Source File: NamespaceRegistryWrapper.java From sling-whiteboard with Apache License 2.0 | 4 votes |
@Override public void registerNamespace(String prefix, String uri) throws NamespaceException, UnsupportedRepositoryOperationException, AccessDeniedException, RepositoryException { jcr.registerNamespace(prefix, uri); }
Example #20
Source File: DAVExRepositoryFactory.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
public int getDepth(Path path, PathResolver resolver) throws NamespaceException { String jcrPath = resolver.getJCRPath(path); Integer depth = depthMap.get(jcrPath); return depth == null ? defaultDepth : depth; }
Example #21
Source File: SessionImpl.java From jackalope with Apache License 2.0 | 4 votes |
@Override public String getNamespacePrefix(String uri) throws NamespaceException, RepositoryException { return null; }
Example #22
Source File: SessionImpl.java From jackalope with Apache License 2.0 | 4 votes |
@Override public String getNamespaceURI(String prefix) throws NamespaceException, RepositoryException { return null; }
Example #23
Source File: SessionImpl.java From jackalope with Apache License 2.0 | 4 votes |
@Override public void setNamespacePrefix(String prefix, String uri) throws NamespaceException, RepositoryException { }
Example #24
Source File: SessionWrapper.java From sling-whiteboard with Apache License 2.0 | 4 votes |
@Override public String getNamespacePrefix(String uri) throws NamespaceException, RepositoryException { return this.wrappedSession.getNamespacePrefix(uri); }
Example #25
Source File: SessionWrapper.java From sling-whiteboard with Apache License 2.0 | 4 votes |
@Override public String getNamespaceURI(String prefix) throws NamespaceException, RepositoryException { return this.wrappedSession.getNamespaceURI(prefix); }
Example #26
Source File: SessionWrapper.java From sling-whiteboard with Apache License 2.0 | 4 votes |
@Override public void setNamespacePrefix(String prefix, String uri) throws NamespaceException, RepositoryException { this.wrappedSession.setNamespacePrefix(prefix, uri); }
Example #27
Source File: PrivilegeManagerWrapper.java From sling-whiteboard with Apache License 2.0 | 4 votes |
@Override public Privilege registerPrivilege(String privilegeName, boolean isAbstract, String[] declaredAggregateNames) throws AccessDeniedException, NamespaceException, RepositoryException { return delegate.registerPrivilege(privilegeName, isAbstract, declaredAggregateNames); }
Example #28
Source File: NamespaceRegistryWrapper.java From sling-whiteboard with Apache License 2.0 | 4 votes |
@Override public String getPrefix(String uri) throws NamespaceException, RepositoryException { return jcr.getPrefix(uri); }
Example #29
Source File: NamespaceRegistryWrapper.java From sling-whiteboard with Apache License 2.0 | 4 votes |
@Override public String getURI(String prefix) throws NamespaceException, RepositoryException { return jcr.getURI(prefix); }
Example #30
Source File: NamespaceRegistryWrapper.java From sling-whiteboard with Apache License 2.0 | 4 votes |
@Override public void unregisterNamespace(String prefix) throws NamespaceException, UnsupportedRepositoryOperationException, AccessDeniedException, RepositoryException { jcr.unregisterNamespace(prefix); }