directorycontent.java

来自「web版的SVN客户端」· Java 代码 · 共 269 行

JAVA
269
字号
/*
 * Copyright (c) 2004, 2005 Polarion Software, All rights reserved.
 * Email: community@polarion.org
 *
 * This program and the accompanying materials are made available under the
 * terms of the Apache License, Version 2.0 (the "License"). You may not use
 * this file except in compliance with the License. Copy of the License is
 * located in the file LICENSE.txt in the project distribution. You may also
 * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 *
 * POLARION SOFTWARE MAKES NO REPRESENTATIONS OR WARRANTIES
 * ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESSED OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. POLARION SOFTWARE
 * SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT
 * OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 */
package org.polarion.svnwebclient.web.model.data.directory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

import org.polarion.svnwebclient.data.model.DataDirectoryElement;
import org.polarion.svnwebclient.data.model.DataRepositoryElement;
import org.polarion.svnwebclient.decorations.IIconDecoration;
import org.polarion.svnwebclient.decorations.IRevisionDecorator;
import org.polarion.svnwebclient.util.CommentUtil;
import org.polarion.svnwebclient.util.DateFormatter;
import org.polarion.svnwebclient.util.HtmlUtil;
import org.polarion.svnwebclient.util.NumberFormatter;
import org.polarion.svnwebclient.util.UrlGenerator;
import org.polarion.svnwebclient.util.UrlGeneratorFactory;
import org.polarion.svnwebclient.util.UrlUtil;
import org.polarion.svnwebclient.web.resource.Images;
import org.polarion.svnwebclient.web.resource.Links;
import org.polarion.svnwebclient.web.support.AbstractRequestHandler;
import org.polarion.svnwebclient.web.support.RequestParameters;
import org.polarion.svnwebclient.web.support.State;

/**
 * 
 * @author <A HREF="mailto:svnbrowser@polarion.org">Polarion Software </A>
 */
public class DirectoryContent {
    protected DataDirectoryElement directoryElement;
    protected AbstractRequestHandler requestHandler;
    protected long headRevision;
    protected String url;   
    protected IRevisionDecorator revisionDecorator;
    protected State state;
    protected Comparator comparator;
    
    public class Element {
        protected DataRepositoryElement repositoryElement;
        
        public Element(DataRepositoryElement repositoryElement) {
            this.repositoryElement = repositoryElement;
        }
        
        public String getImage() {
            if (this.repositoryElement.isDirectory()) {
                return Images.DIRECTORY;
            } else {
                return Images.FILE;                
            }
        }        
        
        public String getName() {
            return HtmlUtil.encode(this.repositoryElement.getName());
        }
        
        public String getContentUrl() {
            UrlGenerator urlGenerator;
            if (this.repositoryElement.isDirectory()) {
                urlGenerator = UrlGeneratorFactory.getUrlGenerator(Links.DIRECTORY_CONTENT, DirectoryContent.this.requestHandler.getLocation());
            } else {
                urlGenerator = UrlGeneratorFactory.getUrlGenerator(Links.FILE_CONTENT, DirectoryContent.this.requestHandler.getLocation());                
            }
            
            String url = DirectoryContent.this.url;
            if (url.length() != 0) {
                url += "/";
            }
            url += this.repositoryElement.getName();
            
            urlGenerator.addParameter(RequestParameters.URL, UrlUtil.encode(url));
            if (DirectoryContent.this.requestHandler.getCurrentRevision() != -1) {
                urlGenerator.addParameter(RequestParameters.CREV, Long.toString(DirectoryContent.this.requestHandler.getCurrentRevision()));
            }
            return urlGenerator.getUrl();
        }
        
        public String getDecoratedRevision() {
        	 String ret = null;        	 
             ret = NumberFormatter.format(this.repositoryElement.getRevision());
             return ret;        	        	
        }
                
        public String getRevision() {
        	return HtmlUtil.encode(Long.toString(this.repositoryElement.getRevision()));
        }
        
        public boolean isHeadRevision() {
            return DirectoryContent.this.headRevision == this.repositoryElement.getRevision();
        }
        
        public boolean isRevisionDecorated() {
            return DirectoryContent.this.revisionDecorator.isRevisionDecorated(this.getRevision(), DirectoryContent.this.state.getRequest());
        }
        
        public IIconDecoration getRevisionDecoration() {
            return DirectoryContent.this.revisionDecorator.getIconDecoration(this.getRevision(), DirectoryContent.this.state.getRequest());
        }
        
        public String getRevisionUrl() {
            UrlGenerator urlGenerator = UrlGeneratorFactory.getUrlGenerator(Links.REVISION, DirectoryContent.this.requestHandler.getLocation());
            String url = DirectoryContent.this.url;
            if (url.length() != 0) {
                url += "/";
            }
            url += this.repositoryElement.getName();
            
            urlGenerator.addParameter(RequestParameters.URL, UrlUtil.encode(url));            
            if (DirectoryContent.this.requestHandler.getCurrentRevision() != -1) {
                urlGenerator.addParameter(RequestParameters.CREV, Long.toString(DirectoryContent.this.requestHandler.getCurrentRevision()));
            }            
            urlGenerator.addParameter(RequestParameters.REV, this.getRevision());
            return urlGenerator.getUrl();            
        }
        
        public String getRevisionListUrl() {
            UrlGenerator urlGenerator = UrlGeneratorFactory.getUrlGenerator(Links.REVISION_LIST, DirectoryContent.this.requestHandler.getLocation());
            
            String url = DirectoryContent.this.url;
            if (url.length() != 0) {
                url += "/";
            }
            url += this.repositoryElement.getName();
            
            urlGenerator.addParameter(RequestParameters.URL, UrlUtil.encode(url));
            if (DirectoryContent.this.requestHandler.getCurrentRevision() != -1) {
                urlGenerator.addParameter(RequestParameters.CREV, Long.toString(DirectoryContent.this.requestHandler.getCurrentRevision()));
            }                        
            return urlGenerator.getUrl();
        }
        
        public String getDate() {
            return DateFormatter.format(this.repositoryElement.getDate());
        }
        
        public String getAuthor() {
            return HtmlUtil.encode(this.repositoryElement.getAuthor());
        }
        
        public String getFirstLine() {
        	return CommentUtil.getFirstLine(this.repositoryElement.getComment());
        }
        
        public boolean isMultiLineComment() {
        	return CommentUtil.isMultiLine(this.repositoryElement.getComment());
        } 
        
        public String getComment() {
            return HtmlUtil.encode(this.repositoryElement.getComment());
        }

        public String getTooltip() {
        	return CommentUtil.getTooltip(this.repositoryElement.getComment());
        }
        
        public String getSize() {
            String ret;
            if (this.repositoryElement.isDirectory()) {
                ret = "<DIR>";
            } else {
                ret = NumberFormatter.format(this.repositoryElement.getSize());
            }
            return HtmlUtil.encode(ret);
        }
        
        public String isDirectory() {
            if (this.repositoryElement.isDirectory()) {
                return "true";
            } else {
                return "false";                
            }
        }
        
        public boolean isRestricted() {
        	return this.repositoryElement.isRestricted();
        }
    }
    
    public DirectoryContent(DataDirectoryElement directoryElement, AbstractRequestHandler requestHandler, IRevisionDecorator revisionDecorator) {
        this.directoryElement = directoryElement;
        this.requestHandler = requestHandler;           
        this.revisionDecorator = revisionDecorator;     
    }
    
    public void setUrl(String url) {
    	this.url = url;
    }
    
    public void setState(State state) {
    	this.state = state;
    }
    
    public void setHeadRevision(long headRevision) {
    	this.headRevision = headRevision;
    }
    public void applySort(Comparator comparator) {
        this.comparator = comparator;
    }
    
    public String getAuthor() {
        return HtmlUtil.encode(this.directoryElement.getAuthor());
    }
    
    public String getComment() {
        return HtmlUtil.encode(this.directoryElement.getComment());
    }
    
    public String getTooltip() {
    	return CommentUtil.getTooltip(this.directoryElement.getComment());
    }
    
    public String getFirstLine() {
    	return CommentUtil.getFirstLine(this.directoryElement.getComment());
    }
    
    public boolean isMultiLineComment() {
    	return CommentUtil.isMultiLine(this.directoryElement.getComment());
    } 
    
    public String getDate() {
        return DateFormatter.format(this.directoryElement.getDate());
    }
    
    public String getRevision() {
        return Long.toString(this.directoryElement.getRevision());
    }
    
    public String getDecoratedRevision() {
        return NumberFormatter.format(this.directoryElement.getRevision());
    }
    
    public boolean isHeadRevision() {
        return this.headRevision == this.directoryElement.getRevision();
    }
    
    public String getChildCount() {
        return Integer.toString(this.directoryElement.getChildElements().size());
    }
    
    public List getChilds() {
        List ret = new ArrayList();
        List childElements = this.directoryElement.getChildElements();
        Collections.sort(childElements, this.comparator);        
        for (Iterator i = childElements.iterator(); i.hasNext(); ) {
            ret.add(new Element((DataRepositoryElement) i.next()));
        }
        return ret;
    }       
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?