コード例 #1
0
 protected void startElement(DAVElement parent, DAVElement element, Attributes attrs)
     throws SVNException {
   if (element == FILE_REVISION) {
     myPath = attrs.getValue("path");
     myRevision = Long.parseLong(attrs.getValue("rev"));
   } else if (element == REVISION_PROPERTY
       || element == SET_PROPERTY
       || element == DELETE_PROPERTY) {
     myPropertyName = attrs.getValue("name");
     myPropertyEncoding = attrs.getValue("encoding");
   }
   if (element == TX_DELTA) {
     // handle file revision with props.
     if (myPath != null && myFileRevisionsHandler != null) {
       if (myProperties == null) {
         myProperties = Collections.EMPTY_MAP;
       }
       if (myPropertiesDelta == null) {
         myPropertiesDelta = Collections.EMPTY_MAP;
       }
       SVNFileRevision revision =
           new SVNFileRevision(myPath, myRevision, myProperties, myPropertiesDelta);
       myFileRevisionsHandler.openRevision(revision);
       myProperties = null;
       myPropertiesDelta = null;
       myPath = null;
       myFileRevisionsHandler.applyTextDelta(myPath, null);
     }
     setDeltaProcessing(true);
   }
 }
コード例 #2
0
 protected void endElement(DAVElement parent, DAVElement element, StringBuffer cdata)
     throws SVNException {
   if (element == FILE_REVISION) {
     if (myPath != null && myFileRevisionsHandler != null) {
       // handle file revision if was not handled yet (no tx delta).
       if (myProperties == null) {
         myProperties = Collections.EMPTY_MAP;
       }
       if (myPropertiesDelta == null) {
         myPropertiesDelta = Collections.EMPTY_MAP;
       }
       SVNFileRevision revision =
           new SVNFileRevision(myPath, myRevision, myProperties, myPropertiesDelta);
       myFileRevisionsHandler.openRevision(revision);
     }
     // handle close revision with props?
     if (myFileRevisionsHandler != null) {
       myFileRevisionsHandler.closeRevision(myPath);
     }
     myPath = null;
     myProperties = null;
     myPropertiesDelta = null;
     myPropertyEncoding = null;
     myPropertyName = null;
   } else if (element == TX_DELTA) {
     setDeltaProcessing(false);
     myCount++;
   } else if (element == REVISION_PROPERTY) {
     if (myProperties == null) {
       myProperties = new HashMap();
     }
     myProperties.put(myPropertyName, cdata != null ? cdata.toString() : "");
     myPropertyName = null;
   } else if (element == SET_PROPERTY) {
     if (myPropertiesDelta == null) {
       myPropertiesDelta = new HashMap();
     }
     if (myPropertyName != null) {
       String value;
       if ("base64".equals(myPropertyEncoding)) {
         byte[] bytes = allocateBuffer(cdata.length());
         int length =
             SVNBase64.base64ToByteArray(new StringBuffer(cdata.toString().trim()), bytes);
         try {
           value = new String(bytes, 0, length, "UTF-8");
         } catch (UnsupportedEncodingException e) {
           value = new String(bytes, 0, length);
         }
       } else {
         value = cdata.toString();
       }
       myPropertiesDelta.put(myPropertyName, value);
     }
     myPropertyName = null;
     myPropertyEncoding = null;
   } else if (element == DELETE_PROPERTY) {
     if (myPropertiesDelta == null) {
       myPropertiesDelta = new HashMap();
     }
     if (myPropertyName != null) {
       myPropertiesDelta.put(myPropertyName, null);
     }
     myPropertyEncoding = null;
     myPropertyName = null;
   }
 }
コード例 #3
0
 public int getFileRevisions(
     String path, long sRevision, long eRevision, ISVNFileRevisionHandler handler)
     throws SVNException {
   Long srev = getRevisionObject(sRevision);
   Long erev = getRevisionObject(eRevision);
   int count = 0;
   SVNDeltaReader deltaReader = new SVNDeltaReader();
   try {
     openConnection();
     Object[] buffer = new Object[] {"get-file-revs", getRepositoryPath(path), srev, erev};
     write("(w(s(n)(n)))", buffer);
     authenticate();
     buffer = new Object[5];
     while (true) {
       SVNFileRevision fileRevision = null;
       boolean skipDelta = false;
       try {
         buffer = read("(SN(*P)(*Z)?S", buffer, false);
         if (buffer[4] != null && ((String) buffer[4]).length() == 0) {
           buffer[4] = null;
           skipDelta = true;
         } else {
           read(")", null, false);
         }
         count++;
       } catch (SVNException e) {
         read("x", buffer, true);
         read("[()]", buffer, true);
         return count;
       }
       String name = null;
       if (handler != null) {
         name = (String) buffer[0];
         long revision = SVNReader.getLong(buffer, 1);
         Map properties = SVNReader.getMap(buffer, 2);
         Map propertiesDelta = SVNReader.getMap(buffer, 3);
         if (name != null) {
           fileRevision = new SVNFileRevision(name, revision, properties, propertiesDelta);
         }
         buffer[2] = null;
         buffer[3] = null;
       }
       if (handler != null && fileRevision != null) {
         handler.openRevision(fileRevision);
       }
       if (skipDelta) {
         if (handler != null) {
           handler.closeRevision(name == null ? path : name);
         }
         continue;
       }
       boolean windowRead = false;
       while (true) {
         byte[] line = (byte[]) read("?W?B", buffer, true)[1];
         if (line == null) {
           // may be failure
           read("[]", buffer, true);
           break;
         } else if (line.length == 0) {
           // empty line, delta end.
           break;
         }
         // apply delta here.
         if (!windowRead) {
           if (handler != null) {
             handler.applyTextDelta(name == null ? path : name, null);
             windowRead = true;
           }
         }
         deltaReader.nextWindow(line, 0, line.length, name == null ? path : name, handler);
       }
       deltaReader.reset(name == null ? path : name, handler);
       if (windowRead) {
         handler.textDeltaEnd(name == null ? path : name);
       }
       if (handler != null) {
         handler.closeRevision(name == null ? path : name);
       }
     }
   } catch (SVNException e) {
     closeSession();
     handleUnsupportedCommand(e, "'get-file-revs' not implemented");
   } finally {
     closeConnection();
   }
   return -1;
 }