@Override public Session login() { return new MockSession(this); }
@Override public Property getProperty(final String absPath) throws RepositoryException { Item item = getItem(absPath); if (item instanceof Property) { return (Property)item; } else { throw new PathNotFoundException(String.format("No property found at: %s.", absPath)); } }
@Override public boolean nodeExists(final String absPath) throws RepositoryException { try { getNode(absPath); return true; } catch (PathNotFoundException ex) { return false; } }
@Override public Property setProperty(final String name, final Value value) throws RepositoryException { Property property = new MockProperty(getPath() + "/" + name, getSession()); property.setValue(value); getMockedSession().addItem(property); return property; }
@Override public PropertyIterator getProperties(final String namePattern) throws RepositoryException { final Pattern pattern = Pattern.compile(namePattern); RangeIterator items = getMockedSession().listChildren(getPath(), new ItemFilter() { @Override public boolean accept(final Item item) throws RepositoryException { return (item instanceof Property) && pattern.matcher(item.getName()).matches(); } }); return new PropertyIteratorAdapter(items, items.getSize()); }
@Override public String getNamespacePrefix(final String uri) throws RepositoryException { return getWorkspace().getNamespaceRegistry().getPrefix(uri); }
@Override public boolean propertyExists(final String absPath) throws RepositoryException { try { getProperty(absPath); return true; } catch (PathNotFoundException ex) { return false; } }
@Override public void removeItem(final String absPath) { removeItemWithChildren(absPath); }
@Override public Node getNodeByUUID(final String uuid) throws RepositoryException { return getNodeByIdentifier(uuid); }
@Override public Property setProperty(final String name, final String value) throws RepositoryException { Property property = new MockProperty(getPath() + "/" + name, getSession()); property.setValue(value); getMockedSession().addItem(property); return property; }
@Override public NodeIterator getNodes(final String namePattern) throws RepositoryException { final Pattern pattern = Pattern.compile(namePattern); RangeIterator items = getMockedSession().listChildren(getPath(), new ItemFilter() { @Override public boolean accept(final Item item) throws RepositoryException { return (item instanceof Node) && pattern.matcher(item.getName()).matches(); } }); return new NodeIteratorAdapter(items, items.getSize()); }
@Override public String[] getNamespacePrefixes() throws RepositoryException { return getWorkspace().getNamespaceRegistry().getPrefixes(); }
@Override public Property setProperty(final String name, final Calendar value) throws RepositoryException { Property property = new MockProperty(getPath() + "/" + name, getSession()); property.setValue(value); getMockedSession().addItem(property); return property; }
@Override public NodeIterator getNodes() throws RepositoryException { RangeIterator items = getMockedSession().listChildren(getPath(), new ItemFilter() { @Override public boolean accept(final Item item) { return item instanceof Node; } }); return new NodeIteratorAdapter(items, items.getSize()); }
@Override public String getNamespaceURI(final String prefix) throws RepositoryException { return getWorkspace().getNamespaceRegistry().getURI(prefix); }
@Override public Node getNode(final String absPath) throws RepositoryException { Item item = getItem(absPath); if (item instanceof Node) { return (Node)item; } else { throw new PathNotFoundException(String.format("No node found at: %s.", absPath)); } }
@Override public Property setProperty(final String name, final boolean value) throws RepositoryException { Property property = new MockProperty(getPath() + "/" + name, getSession()); property.setValue(value); getMockedSession().addItem(property); return property; }
@Override public PropertyIterator getProperties() throws RepositoryException { RangeIterator items = getMockedSession().listChildren(getPath(), new ItemFilter() { @Override public boolean accept(final Item item) { return item instanceof Property; } }); return new PropertyIteratorAdapter(items, items.getSize()); }
@Override public void setNamespacePrefix(final String prefix, final String uri) throws RepositoryException { getWorkspace().getNamespaceRegistry().registerNamespace(prefix, uri); }
@Override public Property setProperty(final String name, final String[] values) throws RepositoryException { Property property = new MockProperty(getPath() + "/" + name, getSession()); property.setValue(values); getMockedSession().addItem(property); return property; }