+ } else
+
+ return super.adapt(clss);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <C extends Closeable> C open(Class<C> clss) throws IOException, IllegalArgumentException {
+ if (InputStream.class.isAssignableFrom(clss)) {
+ Node node = getJcrNode();
+ if (Jcr.isNodeType(node, NodeType.NT_FILE)) {
+ try {
+ return (C) JcrUtils.getFileAsStream(node);
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot open " + jcrPath + " in workspace " + jcrWorkspace, e);
+ }
+ }
+ }
+ return super.open(clss);
+ }
+
+ @Override
+ public ProvidedSession getSession() {
+ return session;
+ }
+
+ @Override
+ public ContentProvider getProvider() {
+ return provider;
+ }
+
+ @Override
+ public String getSessionLocalId() {
+ try {
+ return getJcrNode().getIdentifier();
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot get identifier for " + getJcrNode(), e);
+ }
+ }
+
+ /*
+ * STATIC UTLITIES
+ */
+ public static Content nodeToContent(Node node) {
+ if (node == null)
+ return null;
+ try {
+ ProvidedSession contentSession = (ProvidedSession) node.getSession()
+ .getAttribute(ProvidedSession.class.getName());
+ if (contentSession == null)
+ throw new IllegalArgumentException(
+ "Cannot adapt " + node + " to content, because it was not loaded from a content session");
+ return contentSession.get(CmsConstants.SYS_WORKSPACE + node.getPath());
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot adapt " + node + " to a content", e);
+ }
+ }
+