⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 revisiondecorator.java

📁 web版的SVN客户端
💻 JAVA
字号:
/* * 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.decorations.impl;import java.util.Collection;import java.util.Collections;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import javax.servlet.http.HttpServletRequest;import org.apache.log4j.Logger;import org.polarion.svncommons.commentscache.CommentsCache;import org.polarion.svncommons.commentscache.CommentsCacheException;import org.polarion.svncommons.commentscache.Utils;import org.polarion.svnwebclient.authorization.UserCredentials;import org.polarion.svnwebclient.authorization.impl.CredentialsManager;import org.polarion.svnwebclient.configuration.ConfigurationProvider;import org.polarion.svnwebclient.decorations.IIconDecoration;import org.polarion.svnwebclient.decorations.IRevisionDecorator;import com.polarion.core.util.MeasureTime;import com.polarion.mcore.webobject.IWebDataObject;import com.polarion.portal.utils.formatter.FormatterTool;import com.polarion.subterra.base.SubterraURI;import com.polarion.usdp.core.model.constants.WorkItemConstants;import com.polarion.xray.core.tracker.LinkedRevisionsManager;import com.polarion.xray.web.announce.LinkHelper;/** *  *  * @author <A HREF="mailto:svnbrowser@polarion.org">Polarion Software </A> */public class RevisionDecorator implements IRevisionDecorator {        private static Logger log = Logger.getLogger(RevisionDecorator.class);        private static final String CACHE_KEY = RevisionDecorator.class.getName();    /* @see org.polarion.svnwebclient.decorations.IRevisionDecorator#getSectionTitle() */    public String getSectionTitle() {        return "Linked Work Items";    }    /* @see org.polarion.svnwebclient.decorations.IRevisionDecorator#getSectionContent(java.lang.String) */    public String getSectionContent(String revision, HttpServletRequest request) {        Collection wis = getCachedWIs(revision, request).wis;        StringBuffer sb = new StringBuffer();        for (Iterator iter = wis.iterator(); iter.hasNext();) {            IWebDataObject wi = (IWebDataObject) iter.next();            sb.append(getHTMLLabel(wi));            if(iter.hasNext()) {                sb.append("<br>");            }        }                return sb.toString();    }    /* @see org.polarion.svnwebclient.decorations.IRevisionDecorator#isRevisionDecorated(java.lang.String) */    public boolean isRevisionDecorated(String revision, HttpServletRequest request) {        Collection wis = getCachedWIs(revision, request).wis;                return wis.size() > 0;    }    /**     * @param revision     * @param request     * @return     */    private CachedItem getCachedWIs(String revision, HttpServletRequest request) {        MeasureTime mt = new MeasureTime();        boolean searched = false;                Map cache = (Map) request.getAttribute(CACHE_KEY);        if(cache == null) {            cache = new HashMap();            request.setAttribute(CACHE_KEY, cache);        }        CachedItem item = (CachedItem) cache.get(revision);        if(item == null) {            searched = true;            try {                String msg = getRevisionMessage(request, revision);                Collection wis = LinkedRevisionsManager.getInstance().getLinkedWIs(revision, msg);                item = new CachedItem(wis, msg);                cache.put(revision, item);            } catch (Exception e) {                log.error("Unable to get WIs", e);                return new CachedItem(Collections.EMPTY_LIST, "");            }        }                if(log.isDebugEnabled()) {            log.debug("Get cached WIs (revision: "+revision+", found: "+item.wis.size()+"): "+mt+ (searched ? "(search)" : ""));        }                return item;    }        private static class CachedItem {        public final Collection wis;        public final String revMessage;                public CachedItem(Collection wis, String revMessage) {            this.wis = wis;            this.revMessage = revMessage;        }    }    /* @see org.polarion.svnwebclient.decorations.IRevisionDecorator#getIconDecoration(java.lang.String) */    public IIconDecoration getIconDecoration(String revision, HttpServletRequest request) {        CachedItem item = getCachedWIs(revision, request);        if(item.wis.size() > 0) {            return new IconDecoration(revision, item);        }        return null;    }        private static CredentialsManager cm = new CredentialsManager();    private String getRevisionMessage(HttpServletRequest request, String revNum) {        UserCredentials creds = cm.getCredentialsFromRequest(request);        if(creds != null) {            String url = ConfigurationProvider.getInstance().getRepositoryUrl();            String userName = creds.getUsername();            String password = creds.getPassword();            long revision = Long.parseLong(revNum);            try {                return CommentsCache.getInstance(Utils.getID(url, userName, password), userName, password).getComment(revision);            } catch (CommentsCacheException e) {                log.error("Unable to get revision message. Returning empty.", e);                return null;            }        }        log.error("Unable to get user credentials. Returning empty revision message.");        return null;    }        private static class IconDecoration implements IIconDecoration {                private final String revision;        private final Collection wis;        private final String revMsg;                private String toolTip = null;        private String iconLink = null;                public IconDecoration(String revision, CachedItem item) {            this.revision = revision;            this.wis = item.wis;            this.revMsg = item.revMessage;        }        /* @see org.polarion.svnwebclient.decorations.IIconDecoration#getIconURL() */        public String getIconURL() {            return "/polarion/images/polarion/repository/workitem.gif ";        }        /* @see org.polarion.svnwebclient.decorations.IIconDecoration#getIconTooltip() */        public String getIconTooltip() {            if(toolTip != null) {                return toolTip;            }                        StringBuffer sb = new StringBuffer();            for (Iterator iter = wis.iterator(); iter.hasNext();) {                IWebDataObject wi = (IWebDataObject) iter.next();                if(wi != null) {                    sb.append(wi.getLabel());                } else {                    sb.append("N/A");                }                if(iter.hasNext()) {                    sb.append(" and ");                }            }                        toolTip = sb.toString();            return toolTip;        }        /* @see org.polarion.svnwebclient.decorations.IIconDecoration#getIconLink() */        public String getIconLink() {            if(iconLink != null) {                return iconLink;            }                        try {                iconLink = LinkHelper.getInstance().getLink(null, LinkedRevisionsManager.getInstance().getLinkedWIsQuery(revision, revMsg))+"&layout=clear";                return iconLink;            } catch (Exception e) {                log.error("Unable to get WIs query", e);                return null;            }        }            }        public String getHTMLLabel(IWebDataObject wi) {        SubterraURI wiURI = wi.getSubterraURI();        String wiStr = FormatterTool.getInstance().formatHTML(wiURI) ;                String iconURL = FormatterTool.getInstance().getImageURL(wiURI);        if (iconURL!=null && !iconURL.trim().equals("")) {            iconURL = "/polarion/"+iconURL;  // Change the relative path to absolute one            wiStr = "<img align=\"absmiddle\" src=\""+iconURL+"\" border=\"0\"/> " + wiStr;        }        if (wi!=null && wi.getValue(WorkItemConstants.TITLE)!=null) {            String title = (String) wi.getValue(WorkItemConstants.TITLE).getValue();            if (title!=null && !title.trim().equals("")) {                wiStr = wiStr + " - " + FormatterTool.getInstance().escape(title);            }        }                String previewLink = LinkHelper.getInstance().getPreviewLink(wi);        if (previewLink!=null && !previewLink.trim().equals("")) {            wiStr = "<a href=\""+previewLink+"&layout=clear\" target=\"working_area\">"+wiStr+"</a>";        }                return wiStr;    }    }

⌨️ 快捷键说明

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