java/code/src/com/redhat/rhn/frontend/configuration/tags/ConfigFileTag.java | 162 +------- java/code/src/com/redhat/rhn/frontend/configuration/tags/test/ConfigFileTagTest.java | 195 ---------- java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml | 2 java/code/src/com/redhat/rhn/frontend/taglibs/IconTag.java | 3 java/code/webapp/WEB-INF/pages/configuration/sdc/viewmodifyfileslocal.jsp | 6 5 files changed, 38 insertions(+), 330 deletions(-)
New commits: commit c7cd1f2a3dad4fc2fe62e7caabddb0ae93a4d455 Author: Tomas Kasparek tkasparek@redhat.com Date: Tue Dec 17 10:11:19 2013 +0100
rework logic of ConfigFileTag so it uses icons instead of gifs and cool stuff
diff --git a/java/code/src/com/redhat/rhn/frontend/configuration/tags/ConfigFileTag.java b/java/code/src/com/redhat/rhn/frontend/configuration/tags/ConfigFileTag.java index 2dc8c7c..2207c16 100644 --- a/java/code/src/com/redhat/rhn/frontend/configuration/tags/ConfigFileTag.java +++ b/java/code/src/com/redhat/rhn/frontend/configuration/tags/ConfigFileTag.java @@ -14,13 +14,14 @@ */ package com.redhat.rhn.frontend.configuration.tags;
-import com.redhat.rhn.domain.config.ConfigFileType; +import java.io.IOException; + +import com.redhat.rhn.frontend.taglibs.IconTag;
import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.log4j.Logger;
import javax.servlet.jsp.JspException; +import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.BodyTagSupport; import javax.servlet.jsp.tagext.TagSupport;
@@ -36,26 +37,9 @@ public class ConfigFileTag extends TagSupport { */ private static final long serialVersionUID = 1582063245840138731L;
- private static final Logger LOG = Logger.getLogger(ConfigFileTag.class); - - public static final String DIR_ALT_KEY = "config.common.dirAlt"; - public static final String FILE_ALT_KEY = "config.common.fileAlt"; - public static final String SYMLINK_ALT_KEY = "config.common.symlinkAlt"; - - - public static final String DIR_LIST_ICON = "/img/rhn-listicon-cfg_folder.gif"; - public static final String FILE_LIST_ICON = "/img/rhn-listicon-cfg_file.gif"; - public static final String SYMLINK_LIST_ICON = "/img/rhn-listicon-cfg_symlink.gif"; - - - public static final String DIR_HEADER_ICON = "/img/folder-config.png"; - public static final String FILE_HEADER_ICON = "/img/file-config.png"; - public static final String SYMLINK_HEADER_ICON = "/img/link-config.png"; - - public static final String FILE_URL = "/rhn/configuration/file/FileDetails.do"; public static final String FILE_COMPARE_URL = - "/rhn/configuration/file/CompareRevision.do"; + "/rhn/configuration/file/CompareRevision.do";
/** * <cfg:file id="" value="" type="file|dir" revision="" nolink=""> @@ -71,9 +55,10 @@ public class ConfigFileTag extends TagSupport { */ @Override public int doEndTag() throws JspException { + StringBuilder result = new StringBuilder(); if (nolink || id == null) { - writeIcon(); - ConfigTagHelper.write(StringEscapeUtils.escapeXml(path), pageContext); + result.append(writeIcon()); + result.append(StringEscapeUtils.escapeXml(path)); } else { String url; @@ -84,9 +69,16 @@ public class ConfigFileTag extends TagSupport { url = makeConfigFileUrl(id); }
- ConfigTagHelper.write("<a href="" + url + "">", pageContext); - writeIcon(); - ConfigTagHelper.write(StringEscapeUtils.escapeXml(path) + "</a>", pageContext); + result.append("<a href="" + url + "">"); + result.append(writeIcon()); + result.append(StringEscapeUtils.escapeXml(path) + "</a>"); + } + JspWriter writer = pageContext.getOut(); + try { + writer.write(result.toString()); + } + catch (IOException e) { + throw new JspException(e); } return BodyTagSupport.SKIP_BODY; } @@ -104,7 +96,6 @@ public class ConfigFileTag extends TagSupport { super.release(); }
- /** * @param val the id to set */ @@ -113,7 +104,6 @@ public class ConfigFileTag extends TagSupport { this.id = val; }
- /** * @param isNoLink the nolink to set */ @@ -121,7 +111,6 @@ public class ConfigFileTag extends TagSupport { this.nolink = Boolean.TRUE.toString().equalsIgnoreCase(isNoLink); }
- /** * @param tp the type to set */ @@ -129,7 +118,6 @@ public class ConfigFileTag extends TagSupport { this.type = tp; }
- /** * @param value the value to set */ @@ -144,44 +132,23 @@ public class ConfigFileTag extends TagSupport { this.revisionId = rev; }
- private void writeIcon() throws JspException { - if (checkType()) { - if ("dir".equalsIgnoreCase(type) || - "directory".equalsIgnoreCase(type) || - "folder".equalsIgnoreCase(type)) { - ConfigTagHelper.writeIcon(DIR_LIST_ICON, DIR_ALT_KEY, pageContext); - } - else if ("symlink".equalsIgnoreCase(type)) { - ConfigTagHelper.writeIcon(SYMLINK_LIST_ICON, SYMLINK_ALT_KEY, pageContext); - } - else { - ConfigTagHelper.writeIcon(FILE_LIST_ICON, - FILE_ALT_KEY, pageContext); - } - } - else { - ConfigTagHelper.writeErrorIcon(pageContext); - } - } - - /** - * Checks to see if no invalid values are specified - */ - private boolean checkType() { - if ((StringUtils.isBlank(id) && StringUtils.isBlank(path)) || - (StringUtils.isBlank(type))) { - return false; + private String writeIcon() throws JspException { + IconTag i = new IconTag(); + i.setParent(getParent()); + i.setPageContext(pageContext); + if ("dir".equalsIgnoreCase(type) || "directory".equalsIgnoreCase(type) || + "folder".equalsIgnoreCase(type)) { + i.setType("file-directory"); } - try { - ConfigFileType.lookup(type); - return true; + else if ("symlink".equalsIgnoreCase(type)) { + i.setType("file-symlink"); } - catch (IllegalArgumentException ie) { - String message = String.format("Error encoountered when " + - "handling -> %s - %s", id, path); - LOG.warn(message + "\n" + ie.toString(), ie); - return false; + else { + i.setType("file-file"); } + String result = i.renderStartTag(); + i.release(); + return result; }
/** @@ -228,69 +195,4 @@ public class ConfigFileTag extends TagSupport { return FILE_COMPARE_URL + "?cfid=" + fileId; }
- /** - * Returns the Header icon image path for given config file type (file|dir) - * This method is public static because - * EL functions defined in a TLD file, - * need to be public static methods.. - * - * @param type (file|dir) - * @return the image path - */ - public static final String getHeaderIconFor(String type) { - - if ("dir".equalsIgnoreCase(type) || - "directory".equalsIgnoreCase(type) || - "folder".equalsIgnoreCase(type)) { - return DIR_HEADER_ICON; - } - else if ("symlink".equalsIgnoreCase(type) || - "link".equalsIgnoreCase(type)) { - return SYMLINK_HEADER_ICON; - } - return FILE_HEADER_ICON; - } - - /** - * Returns the Header icon image path for given config file type (file|dir|symlink) - * This method is public static because - * EL functions defined in a TLD file, - * need to be public static methods.. - * - * @param type (file|dir) - * @return the image path - */ - public static final String getListIconFor(String type) { - - if ("dir".equalsIgnoreCase(type) || - "directory".equalsIgnoreCase(type) || - "folder".equalsIgnoreCase(type)) { - return DIR_LIST_ICON; - } - else if ("symlink".equalsIgnoreCase(type)) { - return SYMLINK_LIST_ICON; - } - return FILE_LIST_ICON; - } - - - /** - * Returns the Header alt key for a given config file type (file|dir|symlink) - * This method is public static because - * EL functions defined in a TLD file, - * need to be public static methods.. - * @param type (file|dir) - * @return the alt key - */ - public static final String getAltKeyFor(String type) { - if ("dir".equalsIgnoreCase(type) || - "directory".equalsIgnoreCase(type) || - "folder".equalsIgnoreCase(type)) { - return DIR_ALT_KEY; - } - else if ("symlink".equalsIgnoreCase(type)) { - return SYMLINK_ALT_KEY; - } - return FILE_ALT_KEY; - } } diff --git a/java/code/src/com/redhat/rhn/frontend/configuration/tags/test/ConfigFileTagTest.java b/java/code/src/com/redhat/rhn/frontend/configuration/tags/test/ConfigFileTagTest.java deleted file mode 100644 index 32cfe9c..0000000 --- a/java/code/src/com/redhat/rhn/frontend/configuration/tags/test/ConfigFileTagTest.java +++ /dev/null @@ -1,195 +0,0 @@ -/** - * Copyright (c) 2009--2010 Red Hat, Inc. - * - * This software is licensed to you under the GNU General Public License, - * version 2 (GPLv2). There is NO WARRANTY for this software, express or - * implied, including the implied warranties of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 - * along with this software; if not, see - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. - * - * Red Hat trademarks are not licensed under GPLv2. No permission is - * granted to use or replicate Red Hat trademarks that are incorporated - * in this software or its documentation. - */ -package com.redhat.rhn.frontend.configuration.tags.test; - -import com.redhat.rhn.common.localization.LocalizationService; -import com.redhat.rhn.domain.config.ConfigFileType; -import com.redhat.rhn.frontend.configuration.tags.ConfigFileTag; -import com.redhat.rhn.frontend.configuration.tags.ConfigTagHelper; -import com.redhat.rhn.testing.RhnBaseTestCase; -import com.redhat.rhn.testing.RhnMockHttpServletRequest; -import com.redhat.rhn.testing.RhnMockJspWriter; -import com.redhat.rhn.testing.TagTestUtils; - -import com.mockobjects.helpers.TagTestHelper; - -import java.net.URL; - -import javax.servlet.jsp.tagext.Tag; - - -/** - * ConfigFileTagTest - * @version $Rev$ - */ -public class ConfigFileTagTest extends RhnBaseTestCase { - /** - * Called once per test method. - * @throws Exception if an error occurs during setup. - */ - protected void setUp() throws Exception { - super.setUp(); - ConfigFileTag tag = new ConfigFileTag(); - RhnMockHttpServletRequest request = new RhnMockHttpServletRequest(); - TagTestHelper tth = TagTestUtils.setupTagTest(tag, - new URL("http://localhost"), - request); - tag.setPageContext(tth.getPageContext()); - } - - /** Test tag output for files - */ - public void testFile() throws Exception { - - String alt = ConfigFileTag.FILE_ALT_KEY; - String imgName = ConfigFileTag.FILE_LIST_ICON; - - execTest(0, "bar", - ConfigFileType.file().getLabel(), - false, alt, imgName); - } - - /** Test tag output for files - */ - public void testDirs() throws Exception { - - String alt = ConfigFileTag.DIR_ALT_KEY; - String imgName = ConfigFileTag.DIR_LIST_ICON; - - execTest(0, "bar", - ConfigFileType.dir().getLabel(), - false, alt, imgName); - execTest(0, "bar", "dir", false, alt, imgName); - execTest(0, "bar", "directory", false, alt, imgName); - execTest(0, "bar", "folder", false, alt, imgName); - execTest(-2, "bar", "folder", false, alt, imgName); - execTest(0, "bar", - ConfigFileType.dir().getLabel(), - true, alt, imgName, 2); - } - public void testFailure() throws Exception { - - ConfigFileTag tag = new ConfigFileTag(); - RhnMockHttpServletRequest request = new RhnMockHttpServletRequest(); - TagTestHelper tth = TagTestUtils.setupTagTest(tag, - new URL("http://localhost"), - request); - tag.setPageContext(tth.getPageContext()); - tag.setId(String.valueOf(1)); - tag.setPath("FOO"); - - String type = "FAILURE"; - tag.setType(type); - - // ok let's test the tag - tth.assertDoStartTag(Tag.SKIP_BODY); - tth.assertDoEndTag(Tag.SKIP_BODY); - RhnMockJspWriter rout = (RhnMockJspWriter) tth.getPageContext().getOut(); - assertTrue(rout.toString(). - indexOf(ConfigTagHelper.CONFIG_ERROR_ALT_TEXT) > -1); - assertTrue(rout.toString(). - indexOf(ConfigTagHelper.CONFIG_ERROR_IMG) > -1); - } - - - public void execTest(int id, String name, - String type, boolean nolink, - String altKey, String imgName) throws Exception { - execTest(id, name, type, nolink, altKey, imgName, -1); - } - public void execTest(int id, String name, - String type, boolean nolink, - String altKey, String imgName, - int revisionId) throws Exception { - ConfigFileTag tag = new ConfigFileTag(); - RhnMockHttpServletRequest request = new RhnMockHttpServletRequest(); - TagTestHelper tth = TagTestUtils.setupTagTest(tag, - new URL("http://localhost"), - request); - tag.setPageContext(tth.getPageContext()); - if (id >= 0) { - tag.setId(String.valueOf(id)); - } - - tag.setPath(name); - tag.setType(type); - tag.setNolink(String.valueOf(nolink)); - if (revisionId >= 0) { - tag.setRevisionId(String.valueOf(revisionId)); - } - - // ok let's test the tag - tth.assertDoStartTag(Tag.SKIP_BODY); - tth.assertDoEndTag(Tag.SKIP_BODY); - - RhnMockJspWriter rout = (RhnMockJspWriter) tth.getPageContext().getOut(); - - assertTrue(rout.toString().indexOf(name) > -1); - assertFalse(rout.toString().indexOf("alt =""") > -1); - LocalizationService service = LocalizationService.getInstance(); - String alt = service.getMessage(altKey); - assertTrue(rout.toString().indexOf(alt) > -1); - assertTrue(rout.toString().indexOf(imgName) > -1); - if (!nolink && id >= 0) { - String url = "<a href="" + ConfigFileTag.FILE_URL + "?cfid=" + id; - assertTrue(rout.toString().startsWith(url)); - if (revisionId >= 0) { - url = "<a href="" + ConfigFileTag.FILE_URL + - "?ccid=" + id + "&crid=" + revisionId; - assertTrue(rout.toString().startsWith(url)); - } - } - else { - assertFalse(rout.toString().startsWith("<a href")); - } - - } - - public void testFunctions() { - checkFunctions(ConfigFileTag.DIR_HEADER_ICON, - ConfigFileTag.DIR_ALT_KEY, - "dir"); - //also checking case sensititvity - checkFunctions(ConfigFileTag.DIR_HEADER_ICON, - ConfigFileTag.DIR_ALT_KEY, - "dirECtory"); - checkFunctions(ConfigFileTag.DIR_HEADER_ICON, - ConfigFileTag.DIR_ALT_KEY, - "folder"); - - checkFunctions(ConfigFileTag.FILE_HEADER_ICON, - ConfigFileTag.FILE_ALT_KEY, - "file"); - - String url = ConfigFileTag.makeConfigFileRevisionUrl("" + 1, "" + 2); - assertTrue(url.indexOf("crid=2") > -1); - assertTrue(url.indexOf("cfid=1") > -1); - assertTrue(url.startsWith(ConfigFileTag.FILE_URL)); - - url = ConfigFileTag.makeConfigFileUrl("" + 1); - assertTrue(url.indexOf("cfid=1") > -1); - assertTrue(url.startsWith(ConfigFileTag.FILE_URL)); - - - url = ConfigFileTag.makeFileCompareUrl("" + 1); - assertTrue(url.indexOf("cfid=1") > -1); - assertTrue(url.startsWith(ConfigFileTag.FILE_COMPARE_URL)); - } - - private void checkFunctions(String icon, String altKey, String type) { - assertEquals(altKey, ConfigFileTag.getAltKeyFor(type)); - assertEquals(icon, ConfigFileTag.getHeaderIconFor(type)); - } -} diff --git a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml index c88ef07..e559ec6 100644 --- a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml +++ b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml @@ -14457,7 +14457,7 @@ any of these revisions. Are you sure you want to do this?</source> <source>Overridden By</source> </trans-unit> <trans-unit id="sdc.config.file_list.revision_from"> - <source><a href="{0}"><img src ="{1}" alt="{2}"/>Revision {3}</a> from {4}</source> + <source><a href="{0}">Revision {1}</a> from {2}</source> </trans-unit> <trans-unit id="sdc.config.file_list.revision"> <source><a href="{0}">Revision {1}</a></source> diff --git a/java/code/src/com/redhat/rhn/frontend/taglibs/IconTag.java b/java/code/src/com/redhat/rhn/frontend/taglibs/IconTag.java index fd39531..4e4b3cc 100644 --- a/java/code/src/com/redhat/rhn/frontend/taglibs/IconTag.java +++ b/java/code/src/com/redhat/rhn/frontend/taglibs/IconTag.java @@ -49,6 +49,9 @@ public class IconTag extends TagSupport { icons.put("event-type-package", "fa spacewalk-icon-packages"); icons.put("event-type-preferences", "fa fa-cog"); icons.put("event-type-system", "fa fa-desktop"); + icons.put("file-directory", "fa fa-folder-open-o"); + icons.put("file-file", "fa fa-file-text-o"); + icons.put("file-symlink", "fa spacewalk-icon-listicon-cfg-symlink"); icons.put("header-action", "fa fa-clock-o"); icons.put("header-activation-key", "fa fa-key"); icons.put("header-channel", "fa spacewalk-icon-software-channels"); diff --git a/java/code/webapp/WEB-INF/pages/configuration/sdc/viewmodifyfileslocal.jsp b/java/code/webapp/WEB-INF/pages/configuration/sdc/viewmodifyfileslocal.jsp index 4c289fd..4b7127d 100644 --- a/java/code/webapp/WEB-INF/pages/configuration/sdc/viewmodifyfileslocal.jsp +++ b/java/code/webapp/WEB-INF/pages/configuration/sdc/viewmodifyfileslocal.jsp @@ -57,10 +57,8 @@ </c:set> <bean:message key="sdc.config.file_list.revision_from" arg0 = "${cfg:fileRevisionUrl(current.configFileId, current.configRevisionId)}" - arg1 = "${cfg:fileListIcon(current.configFileType)}" - arg2 = "${rhn:localize(cfg:fileAlt(current.configFileType))}" - arg3 = "${current.configRevision}" - arg4 = "${channelDisplay}" + arg1 = "${current.configRevision}" + arg2 = "${channelDisplay}" /> </c:when> <c:otherwise>
spacewalk-commits@lists.fedorahosted.org