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.wc.xml;
 
 import java.io.File;
 
This is an implementation of the ISVNStatusHandler interface that writes XML formatted status information to a specified ContentHandler.

Author(s):
TMate Software Ltd.
Version:
1.1.0
 
 public class SVNXMLStatusHandler extends AbstractXMLHandler implements ISVNStatusHandler {
     
     private static final String AGAINST_TAG = "against";
     private static final String TARGET_TAG = "target";
     public static final String EXPIRES_TAG = "expires";
     public static final String CREATED_TAG = "created";
     public static final String COMMENT_TAG = "comment";
     public static final String OWNER_TAG = "owner";
     public static final String TOKEN_TAG = "token";
     public static final String DATE_TAG = "date";
     public static final String AUTHOR_TAG = "author";
     public static final String REVISION_ATTR = "revision";
     public static final String SWITCHED_ATTR = "switched";
     public static final String COPIED_ATTR = "copied";
     public static final String WC_LOCKED_ATTR = "wc-locked";
     public static final String PROPS_ATTR = "props";
     public static final String ITEM_ATTR = "item";
     public static final String PATH_ATTR = "path";
     public static final String REMOTE_STATUS_TAG = "repos-status";
     public static final String LOCK_TAG = "lock";
     public static final String COMMIT_TAG = "commit";
     public static final String WC_STATUS_TAG = "wc-status";
     public static final String ENTRY_TAG = "entry";
     public static final String STATUS_TAG = "status";
 
     private static final String TRUE = "true";
 
     private File myTargetPath;
    
    
Creates a new status handler.

Parameters:
saxHandler a ContentHandler to form an XML tree
 
     public SVNXMLStatusHandler(ContentHandler saxHandler) {
         this(saxHandlernull);
     }    

    
Creates a new status handler.

Parameters:
saxHandler a ContentHandler to form an XML tree
log a debug logger
 
     public SVNXMLStatusHandler(ContentHandler saxHandlerISVNDebugLog log) {
         super(saxHandlerlog);
     }    
    
    
Begins an XML tree with the target path for which the status is run.

Parameters:
path a WC target path
 
     public void startTarget(File path) {
         try {
              = path;
             addAttribute(path.getPath());
             openTag();
         } catch (SAXException e) {
             getDebugLog().error(e);
        }
    }
    public void handleStatus(SVNStatus statusthrows SVNException {
        try {
            sendToHandler(status);
        } catch (SAXException th) {
            getDebugLog().error(th);
            SVNErrorMessage err = SVNErrorMessage.create(.th.getLocalizedMessage());
            SVNErrorManager.error(errth);
        }
    }
    
    
Closes the formatted XML with the revision against which the status is run.

Parameters:
revision a revision against which the status is run
    public void endTarget(long revision) {
        try {
             = null;
            if (revision >= 0) {
                addAttribute(revision + "");
                openTag();
                closeTag();
            }
            closeTag();
        } catch (SAXException e) {
            getDebugLog().error(e);
        }
    }
    
    private void sendToHandler(SVNStatus statusthrows SAXException {
        addAttribute(getRelativePath(status.getFile()));
        openTag();
        addAttribute(status.getContentsStatus().toString());
        if (status.isLocked()) {
            addAttribute();
        }
        if (status.isCopied()) {
            addAttribute();
        }
        if (status.isSwitched()) {
            addAttribute();
        }
        if (!status.isCopied() && status.getRevision() != null && status.getRevision().getNumber() >= 0) {
            addAttribute(status.getRevision().toString());
        }
        openTag();
        if (status.getCommittedRevision() != null && status.getCommittedRevision().getNumber() >= 0) {
            addAttribute(status.getCommittedRevision().toString());
            openTag();
            addTag(status.getAuthor());
            if (status.getCommittedDate() != null) {
                addTag(, SVNTimeUtil.formatDate(status.getCommittedDate()));
            }
            closeTag();
        }
        if (status.getLocalLock() != null) {
            openTag();
            addTag(status.getLocalLock().getID());
            addTag(status.getLocalLock().getOwner());
            addTag(status.getLocalLock().getComment());
            addTag(, SVNTimeUtil.formatDate(status.getLocalLock().getCreationDate()));
            closeTag();
        }
        closeTag();
        
                status.getRemoteLock() != null) {
            addAttribute(status.getRemotePropertiesStatus().toString());
            addAttribute(status.getRemoteContentsStatus().toString());
            openTag();
            if (status.getRemoteLock() != null) {
                openTag();
                addTag(status.getRemoteLock().getID());
                addTag(status.getRemoteLock().getOwner());
                addTag(status.getRemoteLock().getComment());
                addTag(, SVNTimeUtil.formatDate(status.getRemoteLock().getCreationDate()));
                if (status.getRemoteLock().getExpirationDate() != null) {
                    addTag(, SVNTimeUtil.formatDate(status.getRemoteLock().getExpirationDate()));
                }
                closeTag();
            }
            closeTag();
        }
        closeTag();
    }
    
    protected String getRelativePath(File path) {
        String fullPath = path.getAbsoluteFile().getAbsolutePath(); 
        if ( == null) {
            return fullPath
        }
        StringBuffer relativePath = new StringBuffer();
        // collect path till target is met, then prepend target.
        char pathSeparator = .;
        boolean targetMeet = false;
        if (!path.getAbsoluteFile().equals(.getAbsoluteFile())) {
            do {
                if (relativePath.length() > 0) {
                    relativePath.insert(0, pathSeparator);
                }
                relativePath = relativePath.insert(0, path.getName());
                path = path.getParentFile();
                if (path != null) {
                    targetMeet = path.getAbsoluteFile().equals(.getAbsoluteFile());
                }
            } while(path !=null && !targetMeet);
        } else {
            return .getPath();
        }
        if (path != null) {
            if (relativePath.length() > 0) {
                relativePath.insert(0, pathSeparator);
            }
            relativePath = relativePath.insert(0, .getPath());
        } else {
            return fullPath;
        }
        return relativePath.toString();
    }
    
    protected String getTargetPath() {
        return getRelativePath();        
    }
    
    protected String getHeaderName() {
        return ;
    }
New to GrepCode? Check out our FAQ X