Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * ====================================================================
   * Copyright (c) 2004-2006 TMate Software Ltd.  All rights reserved.
   *
   * This software is licensed as described in the file COPYING, which
   * you should have received as part of this distribution.  The terms
   * are also available at http://svnkit.com/license.html
   * If newer versions of this license are posted there, you may use a
   * newer version instead, at your option.
  * ====================================================================
  */
 
 package org.tmatesoft.svn.core.internal.io.dav.handlers;
 
 

Author(s):
TMate Software Ltd.
Version:
1.1.0
 
 public class DAVEditorHandler extends BasicDAVDeltaHandler {
 
     public static StringBuffer generateEditorRequest(final DAVConnection connectionStringBuffer bufferfinal String url
             long targetRevisionString targetString dstPathboolean recurse,
             boolean ignoreAncestryboolean resourceWalk
             boolean fetchContentsISVNReporterBaton reporterBatonthrows SVNException {
 		buffer = buffer == null ? new StringBuffer() : buffer;
         buffer.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
         buffer.append("<S:update-report send-all=\"true\" xmlns:S=\"svn:\">\n");
         buffer.append("<S:src-path>");
         buffer.append(SVNEncodingUtil.xmlEncodeCDATA(url));
         buffer.append("</S:src-path>\n");
         if (targetRevision >= 0) {
             buffer.append("<S:target-revision>");
             buffer.append(targetRevision);
             buffer.append("</S:target-revision>\n");
         }
         if (target != null) {
             buffer.append("<S:update-target>");
             buffer.append(SVNEncodingUtil.xmlEncodeCDATA(target));
             buffer.append("</S:update-target>\n");
         }
         if (dstPath != null) {
             buffer.append("<S:dst-path>");
             buffer.append(SVNEncodingUtil.xmlEncodeCDATA(dstPath));
             buffer.append("</S:dst-path>\n");
         }
         if (!recurse) {
             buffer.append("<S:recursive>no</S:recursive>\n");
         }
         if (ignoreAncestry) {
             buffer.append("<S:ignore-ancestry>yes</S:ignore-ancestry>\n");
         }
         if (resourceWalk) { 
             buffer.append("<S:resource-walk>yes</S:resource-walk>\n");
         }
         if (!fetchContents) {
             buffer.append("<S:text-deltas>no</S:text-deltas>\n");
         }
         final StringBuffer report = buffer;
         reporterBaton.report(new ISVNReporter() {
             public void setPath(String pathString locktokenlong revisionboolean startEmpty) {
                 report.append("<S:entry rev=\"");
                 report.append(revision);
                 report.append("\" ");
                 if (locktoken != null) {
                     report.append("lock-token=\"");
                     report.append(locktoken);
                     report.append("\" ");
                 }
                 if (startEmpty) {
                     report.append("start-empty=\"true\" ");
                 }
                 report.append(">");
                 report.append(SVNEncodingUtil.xmlEncodeCDATA(path));
                 report.append("</S:entry>\n");
             }
 
             public void deletePath(String path) {
                report.append("<S:missing>");
                report.append(SVNEncodingUtil.xmlEncodeCDATA(path));
                report.append("</S:missing>\n");
            }
            public void linkPath(SVNURL urlString pathString locktokenlong revisionboolean startEmptythrows SVNException {
                report.append("<S:entry rev=\"");
                report.append(revision);
                report.append("\" ");
                if (locktoken != null) {
                    report.append("lock-token=\"");
                    report.append(locktoken);
                    report.append("\" ");
                }
                if (startEmpty) {
                    report.append("start-empty=\"true\" ");
                }
                String linkedPath = url.getURIEncodedPath();
                DAVBaselineInfo info = DAVUtil.getBaselineInfo(connectionnulllinkedPathrevisionfalsefalsenull);
                String switchUrl = SVNEncodingUtil.uriDecode(info.baselinePath);
                report.append("linkpath=\"");
                // switched path relative to connection root.
                report.append(SVNEncodingUtil.xmlEncodeAttr(switchUrl));
                report.append("\" ");
                report.append(">");
                report.append(SVNEncodingUtil.xmlEncodeCDATA(path));
                report.append("</S:entry>\n");
            }
            public void finishReport() {
            }
            public void abortReport() throws SVNException {
                SVNErrorManager.cancel("report aborted");
            }
        });
        buffer.append("</S:update-report>");
        return buffer;
	}
    
    protected static final DAVElement TARGET_REVISION = DAVElement.getElement(."target-revision");
    protected static final DAVElement UPDATE_REPORT = DAVElement.getElement(."update-report");
    protected static final DAVElement RESOURCE = DAVElement.getElement(."resource");
    protected static final DAVElement OPEN_DIRECTORY = DAVElement.getElement(."open-directory");
    protected static final DAVElement ADD_DIRECTORY = DAVElement.getElement(."add-directory");
    protected static final DAVElement ABSENT_DIRECTORY = DAVElement.getElement(."absent-directory");
    protected static final DAVElement OPEN_FILE = DAVElement.getElement(."open-file");
    protected static final DAVElement ADD_FILE = DAVElement.getElement(."add-file");
    protected static final DAVElement ABSENT_FILE = DAVElement.getElement(."absent-file");
    protected static final DAVElement DELETE_ENTRY = DAVElement.getElement(."delete-entry");
    protected static final DAVElement FETCH_PROPS = DAVElement.getElement(."fetch-props");
    protected static final DAVElement SET_PROP = DAVElement.getElement(."set-prop");
    protected static final DAVElement REMOVE_PROP = DAVElement.getElement(."remove-prop");
    protected static final DAVElement FETCH_FILE = DAVElement.getElement(."fetch-file");
    
    protected static final String REVISION_ATTR = "rev";
    protected static final String NAME_ATTR = "name";
    protected static final String ENCODING_ATTR = "encoding";
    protected static final String COPYFROM_REV_ATTR = "copyfrom-rev";
    protected static final String COPYFROM_PATH_ATTR = "copyfrom-path";
    protected static final String SEND_ALL_ATTR = "send-all";
    protected ISVNEditor myEditor;
    protected String myPath;
    protected String myPropertyName;
    protected boolean myIsFetchContent;
    protected boolean myIsDirectory;
    private String myChecksum;
    private String myEncoding;
    public DAVEditorHandler(ISVNEditor editorboolean fetchContent) {
         = fetchContent
         = editor;
	}
	protected void startElement(DAVElement parentDAVElement elementAttributes attrsthrows SVNException {
        if (element == ) {
            String receiveAll = attrs.getValue();
            if (receiveAll == null || !Boolean.valueOf(receiveAll).booleanValue()) {
                SVNErrorMessage err = SVNErrorMessage.create(."'update' response format used by the server is not supported");
                SVNErrorManager.error(err);
            }
        } else if (element == ) {
            long revision = Long.parseLong(attrs.getValue());
            .targetRevision(revision);
        } else if (element == ) {
            String name = attrs.getValue();
            .absentDir(SVNPathUtil.append(name));
        } else if (element == ) {
            String name = attrs.getValue();
            .absentFile(SVNPathUtil.append(name));
        } else if (element == ) {            
            long revision = Long.parseLong(attrs.getValue());
             = true;
            if ( == null) {
                 = "";
                .openRoot(revision);
            } else {
                String name = attrs.getValue();
                 = SVNPathUtil.append(name);
                .openDir(revision);
            }
        } else if (element == ) {
             = true;
            String name = attrs.getValue();
            String copyFromPath = attrs.getValue();
            long copyFromRev = -1;
            if (copyFromPath != null) {
                copyFromRev = Long.parseLong(attrs.getValue());
            }
             = SVNPathUtil.append(name);
            .addDir(copyFromPathcopyFromRev);
        } else if (element == ) {
             = false;
            long revision = Long.parseLong(attrs.getValue());
            String name = attrs.getValue();
             = SVNPathUtil.append(name);
            .openFile(revision);
        } else if (element == ) {
             = false;
            String name = attrs.getValue();
             = SVNPathUtil.append(name);
            String copyFromPath = attrs.getValue();
            long copyFromRev = -1;
            if (copyFromPath != null) {
                copyFromRev = Long.parseLong(attrs.getValue());
            }
            .addFile(copyFromPathcopyFromRev);
        } else if (element == ) {
            String name = attrs.getValue();
            .deleteEntry(SVNPathUtil.append(name), -1);
        } else if (element == ) {
             = attrs.getValue();
             = attrs.getValue();
        } else if (element == ) { 
            String name = attrs.getValue();
            if () {
                .changeDirProperty(namenull);
            } else {
                .changeFileProperty(namenull);
            }            
        } else if (element ==  || element ==  || element == ) {
            SVNErrorMessage err = SVNErrorMessage.create(."'update' response format used by the server is not supported; element ''{0}'' was not expected"element.toString());
            SVNErrorManager.error(err);
        } else if (element == ) {
            if () {
                setDeltaProcessing(true);
            }
            .applyTextDelta();
        }
	}
    
	protected void endElement(DAVElement parentDAVElement elementStringBuffer cdatathrows SVNException {
        if (element ==  || element == ) {
            .closeDir();
            if ("".equals()) {
                .closeEdit();
            }
             = null;
             = SVNPathUtil.removeTail();
        } else if (element ==  || element == ) {
            .closeFile();
             = null;
             = SVNPathUtil.removeTail();
        } else if (element == .) {        
             = cdata.toString();
        } else if (element == . || 
                element == . || 
                element == . || 
                element ==  ||
                element == .) {
            if ( == null) {
                 = computeWCPropertyName(element);
            }
            String value = cdata.toString();
            if ("base64".equals()) {
                byte[] buffer = allocateBuffer(cdata.length());
                int length = SVNBase64.base64ToByteArray(new StringBuffer(cdata.toString().trim()), buffer);
                try {
                    value = new String(buffer, 0, length"UTF-8");
                } catch (UnsupportedEncodingException e) {
                    value = new String(buffer, 0, length);
                }                
            }
            if () {
                .changeDirProperty(value);
            } else {
                .changeFileProperty(value);
            }
             = null;
             = null;
        } else if (element ==  && ) {
            setDeltaProcessing(false);
        }
	}
    protected String getCurrentPath() {
        return ;
    }
    
    protected ISVNDeltaConsumer getDeltaConsumer() {
        return ;
    }
    
    private static String computeWCPropertyName(DAVElement element) {
        if (element == .) {
            return .;
        }
        return . + element.getName();
    }
New to GrepCode? Check out our FAQ X