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);
}
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations