X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=org.argeo.eclipse.ui%2Fsrc%2Forg%2Fargeo%2Feclipse%2Fui%2Fjcr%2Futils%2FJcrFileProvider.java;h=472101f34fb453e90982a6ab62afffa53a51da02;hb=088c1b517a543e935d8ab65c3b2fd2d0269b551d;hp=3ca745dc4eb3b9dac4d2a48282cfd5287f51a07e;hpb=261af6b864de167e10eed1916f83035cca71d32f;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/JcrFileProvider.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/JcrFileProvider.java index 3ca745dc4..472101f34 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/JcrFileProvider.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/JcrFileProvider.java @@ -23,12 +23,12 @@ import javax.jcr.RepositoryException; import javax.jcr.nodetype.NodeType; import org.apache.commons.io.IOUtils; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.FileProvider; /** * Implements a FileProvider for UI purposes. Note that it might not be very - * reliable as long as we have not fixed login & multi repository issues that + * reliable as long as we have not fixed login and multi repository issues that * will be addressed in the next version. * * NOTE: id used here is the real id of the JCR Node, not the JCR Path @@ -47,52 +47,23 @@ public class JcrFileProvider implements FileProvider { * and thus have the ability to get the file node corresponding to a given * file ID * - * FIXME : this introduces some concurrences ISSUES. - * - * @param repositoryNode + * @param refNode */ public void setReferenceNode(Node refNode) { + // FIXME : this introduces some concurrency ISSUES. this.refNode = refNode; } - /** - * Must be set in order for the provider to be able to search the repository - * Provided object might be either JCR Nodes or UI RepositoryNode for the - * time being. - * - * @param repositoryNode - */ - // public void setRootNodes(Object[] rootNodes) { - // List tmpNodes = new ArrayList(); - // for (int i = 0; i < rootNodes.length; i++) { - // Object obj = rootNodes[i]; - // if (obj instanceof Node) { - // tmpNodes.add(obj); - // } else if (obj instanceof RepositoryRegister) { - // RepositoryRegister repositoryRegister = (RepositoryRegister) obj; - // Map repositories = repositoryRegister - // .getRepositories(); - // for (String name : repositories.keySet()) { - // // tmpNodes.add(new RepositoryNode(name, repositories - // // .get(name))); - // } - // - // } - // } - // this.rootNodes = tmpNodes.toArray(); - // } - public byte[] getByteArrayFileFromId(String fileId) { InputStream fis = null; byte[] ba = null; Node child = getFileNodeFromId(fileId); try { - fis = (InputStream) child.getProperty(Property.JCR_DATA) - .getBinary().getStream(); + fis = (InputStream) child.getProperty(Property.JCR_DATA).getBinary().getStream(); ba = IOUtils.toByteArray(fis); } catch (Exception e) { - throw new ArgeoException("Stream error while opening file", e); + throw new EclipseUiException("Stream error while opening file", e); } finally { IOUtils.closeQuietly(fis); } @@ -104,12 +75,10 @@ public class JcrFileProvider implements FileProvider { InputStream fis = null; Node child = getFileNodeFromId(fileId); - fis = (InputStream) child.getProperty(Property.JCR_DATA) - .getBinary().getStream(); + fis = (InputStream) child.getProperty(Property.JCR_DATA).getBinary().getStream(); return fis; } catch (RepositoryException re) { - throw new ArgeoException("Cannot get stream from file node for Id " - + fileId, re); + throw new EclipseUiException("Cannot get stream from file node for Id " + fileId, re); } } @@ -147,34 +116,29 @@ public class JcrFileProvider implements FileProvider { // Sanity checks if (result == null) - throw new ArgeoException("File node not found for ID" + fileId); + throw new EclipseUiException("File node not found for ID" + fileId); Node child = null; - + boolean isValid = true; - if (!result.isNodeType(NodeType.NT_FILE)) + if (!result.isNodeType(NodeType.NT_FILE)) // useless: mandatory child node - // || !result.hasNode(Property.JCR_CONTENT)) + // || !result.hasNode(Property.JCR_CONTENT)) isValid = false; else { child = result.getNode(Property.JCR_CONTENT); - if (!(child.isNodeType(NodeType.NT_RESOURCE) || child - .hasProperty(Property.JCR_DATA))) + if (!(child.isNodeType(NodeType.NT_RESOURCE) || child.hasProperty(Property.JCR_DATA))) isValid = false; } if (!isValid) - throw new ArgeoException( - "ERROR: In the current implemented model, '" - + NodeType.NT_FILE - + "' file node must have a child node named jcr:content " - + "that has a BINARY Property named jcr:data " - + "where the actual data is stored"); + throw new EclipseUiException("ERROR: In the current implemented model, '" + NodeType.NT_FILE + + "' file node must have a child node named jcr:content " + + "that has a BINARY Property named jcr:data " + "where the actual data is stored"); return child; } catch (RepositoryException re) { - throw new ArgeoException("Erreur while getting file node of ID " - + fileId, re); + throw new EclipseUiException("Erreur while getting file node of ID " + fileId, re); } } }