From: Wolfgang M. M. <wol...@us...> - 2004-08-12 16:08:58
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/xmldb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11926/src/org/exist/xmldb Modified Files: RemoteCollection.java LocalBinaryResource.java Log Message: Added getContentLength() method to XMLDB resource implementations. Index: LocalBinaryResource.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/LocalBinaryResource.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** LocalBinaryResource.java 3 Aug 2004 15:25:58 -0000 1.4 --- LocalBinaryResource.java 12 Aug 2004 16:08:49 -0000 1.5 *************** *** 193,196 **** --- 193,216 ---- } + /* (non-Javadoc) + * @see org.exist.xmldb.EXistResource#getContentLength() + */ + public int getContentLength() throws XMLDBException { + DBBroker broker = null; + try { + broker = pool.get(user); + DocumentImpl document = getDocument(broker, false); + if (!document.getPermissions().validate(user, Permission.READ)) + throw new XMLDBException(ErrorCodes.PERMISSION_DENIED, + "permission denied to read resource"); + return document.getContentLength(); + } catch (EXistException e) { + throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, e.getMessage(), + e); + } finally { + pool.release(broker); + } + } + protected DocumentImpl getDocument(DBBroker broker, boolean lock) throws XMLDBException { DocumentImpl document = null; Index: RemoteCollection.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/RemoteCollection.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** RemoteCollection.java 7 Aug 2004 14:55:59 -0000 1.15 --- RemoteCollection.java 12 Aug 2004 16:08:49 -0000 1.16 *************** *** 290,354 **** throw new XMLDBException(ErrorCodes.INVALID_COLLECTION, "an io error occurred", ioe); } - Permission perm; String docName = (String) hash.get("name"); int p; if ((p = docName.lastIndexOf('/')) > -1) docName = docName.substring(p + 1); ! DocumentProxy proxy = new DocumentProxy(docName); ! perm = new Permission( (String) hash.get("owner"), (String) hash.get("group"), ((Integer) hash.get("permissions")).intValue()); ! proxy.setPermissions(perm); ! proxy.setType((String)hash.get("type")); ! if(proxy.getType() == null || proxy.getType().equals("XMLResource")) { ! RemoteXMLResource r = new RemoteXMLResource(this, -1, -1, proxy.getName(), null); ! r.setPermissions(proxy.getPermissions()); return r; } else { ! RemoteBinaryResource r = new RemoteBinaryResource(this, proxy.getName()); ! r.setPermissions(proxy.getPermissions()); return r; } } - private List readResources() throws XMLDBException { - List resources = new ArrayList(); - Vector params = new Vector(); - params.addElement(getPath()); - Hashtable collection; - try { - collection = (Hashtable) rpcClient.execute("getCollectionDesc", params); - } catch (XmlRpcException xre) { - throw new XMLDBException(ErrorCodes.VENDOR_ERROR, xre.getMessage(), xre); - } catch (IOException ioe) { - throw new XMLDBException(ErrorCodes.INVALID_COLLECTION, "an io error occurred", ioe); - } - Vector documents = (Vector) collection.get("documents"); - String docName; - String childName; - Hashtable hash; - DocumentProxy proxy; - Permission perm; - int p, dsize = documents.size(); - for (int i = 0; i < dsize; i++) { - hash = (Hashtable) documents.elementAt(i); - docName = (String) hash.get("name"); - if ((p = docName.lastIndexOf('/')) > -1) - docName = docName.substring(p + 1); - proxy = new DocumentProxy(docName); - perm = - new Permission( - (String) hash.get("owner"), - (String) hash.get("group"), - ((Integer) hash.get("permissions")).intValue()); - proxy.setPermissions(perm); - proxy.setType((String)hash.get("type")); - resources.add(proxy); - } - return resources; - } - private void readCollection() throws XMLDBException { childCollections = new HashMap(); --- 290,317 ---- throw new XMLDBException(ErrorCodes.INVALID_COLLECTION, "an io error occurred", ioe); } String docName = (String) hash.get("name"); int p; if ((p = docName.lastIndexOf('/')) > -1) docName = docName.substring(p + 1); ! Permission perm = new Permission( (String) hash.get("owner"), (String) hash.get("group"), ((Integer) hash.get("permissions")).intValue()); ! String type = (String)hash.get("type"); ! int contentLen = ((Integer)hash.get("content-length")).intValue(); ! if(type == null || type.equals("XMLResource")) { ! RemoteXMLResource r = new RemoteXMLResource(this, -1, -1, docName, null); ! r.setPermissions(perm); ! r.setContentLength(contentLen); return r; } else { ! RemoteBinaryResource r = new RemoteBinaryResource(this, docName); ! r.setContentLength(contentLen); ! r.setPermissions(perm); return r; } } private void readCollection() throws XMLDBException { childCollections = new HashMap(); |