Coverage Report - net.fckeditor.tags.CheckTag
 
Classes in this File Line Coverage Branch Coverage Complexity
CheckTag
0%
0/30
0%
0/14
0
 
 1  
 /*
 2  
  * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 3  
  * Copyright (C) 2004-2009 Frederico Caldeira Knabben
 4  
  * 
 5  
  * == BEGIN LICENSE ==
 6  
  * 
 7  
  * Licensed under the terms of any of the following licenses at your
 8  
  * choice:
 9  
  * 
 10  
  *  - GNU General Public License Version 2 or later (the "GPL")
 11  
  *    http://www.gnu.org/licenses/gpl.html
 12  
  * 
 13  
  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 14  
  *    http://www.gnu.org/licenses/lgpl.html
 15  
  * 
 16  
  *  - Mozilla Public License Version 1.1 or later (the "MPL")
 17  
  *    http://www.mozilla.org/MPL/MPL-1.1.html
 18  
  * 
 19  
  * == END LICENSE ==
 20  
  */
 21  
 package net.fckeditor.tags;
 22  
 
 23  
 import java.io.IOException;
 24  
 import java.util.HashSet;
 25  
 import java.util.Set;
 26  
 
 27  
 import javax.servlet.http.HttpServletRequest;
 28  
 import javax.servlet.jsp.JspException;
 29  
 import javax.servlet.jsp.JspTagException;
 30  
 import javax.servlet.jsp.JspWriter;
 31  
 import javax.servlet.jsp.tagext.TagSupport;
 32  
 
 33  
 import net.fckeditor.handlers.PropertiesLoader;
 34  
 import net.fckeditor.handlers.RequestCycleHandler;
 35  
 import net.fckeditor.tool.Compatibility;
 36  
 
 37  
 /**
 38  
  * This tag displays information about browser and user capabilities. There are
 39  
  * tree available commands (CompatibleBrowser, FileBrowsing, FileUpload) which
 40  
  * respond an English message.<br />
 41  
  * <strong>Hint</strong>: The message string cannot be localized at the moment.
 42  
  * 
 43  
  * @version $Id: CheckTag.java 3840 2009-07-08 20:29:46Z mosipov $
 44  
  */
 45  0
 public class CheckTag extends TagSupport {
 46  
 
 47  
         private static final long serialVersionUID = -6834095891675681686L;
 48  
 
 49  
         private static final String FILE_UPLOAD = "FileUpload";
 50  
         private static final String FILE_BROWSING = "FileBrowsing";
 51  
         private static final String COMPATIBLE_BROWSER = "CompatibleBrowser";
 52  
         private static final String PROPERTY_MESSAGE_FILE_BROWSING_DISABLED = "message.enabled_tag.connector.file_browsing.disabled";
 53  
         private static final String PROPERTY_MESSAGE_FILE_BROWSING_ENABLED = "message.enabled_tag.connector.file_browsing.enabled";
 54  
         private static final String PROPERTY_MESSAGE_FILE_UPLOAD_DISABLED = "message.enabled_tag.connector.file_upload.disalbed";
 55  
         private static final String PROPERTY_MESSAGE_FILE_UPLOAD_ENABLED = "message.enabled_tag.connector.file_upload.enabled";
 56  
         private static final String PROPERTY_MESSAGE_NOT_COMPATIBLE_BROWSER = "message.enabled_tag.compatible_browser.no";
 57  
         private static final String PROPERTY_MESSAGE_COMPATIBLE_BROWSER = "message.enabled_tag.compatible_browser.yes";
 58  0
         private static Set<String> commands = new HashSet<String>(3);
 59  
 
 60  
         static {
 61  0
                 commands.add(FILE_UPLOAD);
 62  0
                 commands.add(FILE_BROWSING);
 63  0
                 commands.add(COMPATIBLE_BROWSER);
 64  0
         }
 65  
 
 66  
         private String command;
 67  
 
 68  
         /**
 69  
          * Sets the desired command.
 70  
          * @param command
 71  
          * @throws JspTagException
 72  
          */
 73  
         public void setCommand(String command) throws JspTagException {
 74  0
                 if (!commands.contains(command))
 75  0
                         throw new JspTagException("You have to provide one of the following commands: "
 76  
                                 + commands);
 77  0
                 this.command = command;
 78  0
         }
 79  
 
 80  
         @Override
 81  
         public int doStartTag() throws JspException {
 82  0
                 JspWriter out = pageContext.getOut();
 83  
 
 84  0
                 HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
 85  0
                 String response = null;
 86  
 
 87  0
                 if (command.equals(FILE_UPLOAD)) {
 88  0
                         if (RequestCycleHandler.isEnabledForFileUpload(request))
 89  0
                                 response = PropertiesLoader
 90  
                                         .getProperty(CheckTag.PROPERTY_MESSAGE_FILE_UPLOAD_ENABLED);
 91  
                         else
 92  0
                                 response = PropertiesLoader
 93  
                                         .getProperty(CheckTag.PROPERTY_MESSAGE_FILE_UPLOAD_DISABLED);
 94  
                 }
 95  
 
 96  0
                 if (command.equals(FILE_BROWSING)) {
 97  0
                         if (RequestCycleHandler.isEnabledForFileBrowsing(request))
 98  0
                                 response = PropertiesLoader
 99  
                                         .getProperty(CheckTag.PROPERTY_MESSAGE_FILE_BROWSING_ENABLED);
 100  
                         else
 101  0
                                 response = PropertiesLoader
 102  
                                         .getProperty(CheckTag.PROPERTY_MESSAGE_FILE_BROWSING_DISABLED);
 103  
                 }
 104  0
                 if (command.equals(COMPATIBLE_BROWSER)) {
 105  0
                         if (Compatibility.isCompatibleBrowser(request))
 106  0
                                 response = PropertiesLoader
 107  
                                         .getProperty(CheckTag.PROPERTY_MESSAGE_COMPATIBLE_BROWSER);
 108  
                         else
 109  0
                                 response = PropertiesLoader
 110  
                                         .getProperty(CheckTag.PROPERTY_MESSAGE_NOT_COMPATIBLE_BROWSER);
 111  
                 }
 112  
 
 113  
                 try {
 114  0
                         out.print(response);
 115  0
                 } catch (IOException e) {
 116  0
                         throw new JspException("Tag response could not be written to the user!",e);
 117  0
                 }
 118  
 
 119  0
                 return SKIP_BODY;
 120  
         }
 121  
 
 122  
 }