Search in sources :

Example 41 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class DefaultHandler method delete.

/**
     * @see DeleteHandler#delete(DeleteContext, DavResource)
     */
public boolean delete(DeleteContext deleteContext, DavResource member) throws DavException {
    try {
        String itemPath = member.getLocator().getRepositoryPath();
        Item item = deleteContext.getSession().getItem(itemPath);
        if (item instanceof Node) {
            ((Node) item).removeShare();
        } else {
            item.remove();
        }
        deleteContext.getSession().save();
        log.debug("default handler deleted {}", member.getResourcePath());
        return true;
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : Item(javax.jcr.Item) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 42 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class DirListingExportHandler method exportContent.

/**
     * @see IOHandler#exportContent(ExportContext, DavResource)
     */
public boolean exportContent(ExportContext context, DavResource resource) throws IOException {
    if (!canExport(context, resource)) {
        throw new IOException(getName() + ": Cannot export " + context.getExportRoot());
    }
    // properties (content length undefined)
    context.setModificationTime(new Date().getTime());
    context.setContentType("text/html", "UTF-8");
    context.setETag("");
    // data
    if (context.hasStream()) {
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(context.getOutputStream(), "utf8"));
        try {
            Item item = context.getExportRoot();
            Repository rep = item.getSession().getRepository();
            String repName = rep.getDescriptor(Repository.REP_NAME_DESC);
            String repURL = rep.getDescriptor(Repository.REP_VENDOR_URL_DESC);
            String repVersion = rep.getDescriptor(Repository.REP_VERSION_DESC);
            writer.print("<html><head><title>");
            writer.print(Text.encodeIllegalHTMLCharacters(repName));
            writer.print(" ");
            writer.print(Text.encodeIllegalHTMLCharacters(repVersion));
            writer.print(" ");
            writer.print(Text.encodeIllegalHTMLCharacters(resource.getResourcePath()));
            writer.print("</title></head>");
            writer.print("<body><h2>");
            writer.print(Text.encodeIllegalHTMLCharacters(resource.getResourcePath()));
            writer.print("</h2><ul>");
            writer.print("<li><a href=\"..\">..</a></li>");
            DavResourceIterator iter = resource.getMembers();
            while (iter.hasNext()) {
                DavResource child = iter.nextResource();
                String label = Text.getName(child.getResourcePath());
                writer.print("<li><a href=\"");
                writer.print(Text.encodeIllegalHTMLCharacters(child.getHref()));
                writer.print("\">");
                writer.print(Text.encodeIllegalHTMLCharacters(label));
                writer.print("</a></li>");
            }
            writer.print("</ul><hr size=\"1\"><em>Powered by <a href=\"");
            writer.print(Text.encodeIllegalHTMLCharacters(repURL));
            writer.print("\">");
            writer.print(Text.encodeIllegalHTMLCharacters(repName));
            writer.print("</a> version ");
            writer.print(Text.encodeIllegalHTMLCharacters(repVersion));
            writer.print("</em></body></html>");
        } catch (RepositoryException e) {
            // should not occur
            log.debug(e.getMessage());
        }
        writer.close();
    }
    return true;
}
Also used : DavResourceIterator(org.apache.jackrabbit.webdav.DavResourceIterator) Item(javax.jcr.Item) Repository(javax.jcr.Repository) DavResource(org.apache.jackrabbit.webdav.DavResource) OutputStreamWriter(java.io.OutputStreamWriter) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Example 43 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class ServerWorkspace method getVersionManager.

public RemoteVersionManager getVersionManager() throws RepositoryException, RemoteException {
    try {
        if (remoteVersionManager == null) {
            VersionManager versionManager = workspace.getVersionManager();
            remoteVersionManager = getFactory().getRemoteVersionManager(workspace.getSession(), versionManager);
        }
        return remoteVersionManager;
    } catch (RepositoryException ex) {
        throw getRepositoryException(ex);
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) RemoteVersionManager(org.apache.jackrabbit.rmi.remote.RemoteVersionManager) VersionManager(javax.jcr.version.VersionManager)

Example 44 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class AbstractValue method getBinary.

/**
     * Returns the binary representation of this value. The default
     * implementation uses the UTF-8 serialization of the string returned
     * by {@link #getString()}. Subclasses 
     */
public Binary getBinary() throws RepositoryException {
    try {
        final byte[] value = getString().getBytes("UTF-8");
        return new Binary() {

            public int read(byte[] b, long position) {
                if (position >= value.length) {
                    return -1;
                } else {
                    int p = (int) position;
                    int n = Math.min(b.length, value.length - p);
                    System.arraycopy(value, p, b, 0, n);
                    return n;
                }
            }

            public InputStream getStream() {
                return new ByteArrayInputStream(value);
            }

            public long getSize() {
                return value.length;
            }

            public void dispose() {
            }
        };
    } catch (UnsupportedEncodingException e) {
        throw new RepositoryException("UTF-8 is not supported", e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RepositoryException(javax.jcr.RepositoryException) Binary(javax.jcr.Binary)

Example 45 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class BinaryValue method getString.

public String getString() throws RepositoryException {
    try {
        InputStream stream = value.getStream();
        try {
            Reader reader = new InputStreamReader(stream, "UTF-8");
            StringBuilder builder = new StringBuilder();
            char[] buffer = new char[1024];
            int n = reader.read(buffer);
            while (n != -1) {
                builder.append(buffer, 0, n);
                n = reader.read(buffer);
            }
            return builder.toString();
        } finally {
            stream.close();
        }
    } catch (IOException e) {
        throw new RepositoryException("Unable to read the binary value", e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Aggregations

RepositoryException (javax.jcr.RepositoryException)1236 Node (javax.jcr.Node)289 Session (javax.jcr.Session)182 IOException (java.io.IOException)156 ArrayList (java.util.ArrayList)106 Name (org.apache.jackrabbit.spi.Name)94 DavException (org.apache.jackrabbit.webdav.DavException)90 Test (org.junit.Test)87 Value (javax.jcr.Value)80 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)76 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)72 Path (org.apache.jackrabbit.spi.Path)67 ItemNotFoundException (javax.jcr.ItemNotFoundException)65 PathNotFoundException (javax.jcr.PathNotFoundException)65 NodeId (org.apache.jackrabbit.core.id.NodeId)64 Property (javax.jcr.Property)61 HashMap (java.util.HashMap)53 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)53 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)52 InvalidItemStateException (javax.jcr.InvalidItemStateException)50