package REST_Plugins; import java.util.Map; import javax.servlet.http.HttpServletRequest; import com.extentech.ExtenXLS.WorkSheetHandle; import com.extentech.formats.XLS.WorkSheetNotFoundException; import com.extentech.ExtenXLS.ESS.WorkBookCommander; import com.extentech.ExtenXLS.plugin.RestCall; import com.extentech.ExtenXLS.plugin.RestTest; import com.extentech.ExtenXLS.web.MemeDocument; import com.extentech.ExtenXLS.web.WebWorkBook; import com.extentech.security.AclEntry; import com.extentech.security.User; /** * This custom plugin example overrides the buqilt in PluginSheet and adds two methods. * * as of this writing these methods exist in production however the example is valid. * * @author John McMahon :: May 2, 2011 :: Copyright ©2010 Extentech Inc. * */ public class PluginSheet extends com.extentech.ExtenXLS.plugin.builtin.PluginSheet { /** * gets the sheet protection status * * * @return sheet protection status */ @RestTest ( target = "testPluginSheet.xls", url = "Sheet1!A3/") @RestCall ( formats = {"txt"}, methods = {"GET"} ) public static String getprotected(Map parameters) { WebWorkBook wbh = (WebWorkBook)parameters.get(WorkBookCommander.WORKBOOK); String resource = (String)parameters.get(WorkBookCommander.RESOURCE); try { WorkSheetHandle c = wbh.getWorkSheet(resource); return String.valueOf(c.getProtected()); }catch(WorkSheetNotFoundException e) { return WorkBookCommander.returnXMLErrorResponse("Get Sheet Protection failed:" + resource + " failed. " + e.toString()); } } /** * set the sheet protection status * * locking the sheet is a prerequisite for Cell locking * * @return sheet protection status */ @RestTest ( target = "testPluginSheet.xls", url = "Sheet1!A3/true") @RestCall ( formats = {"txt"}, methods = {"GET"} ) public static String setprotected(Map parameters) { WebWorkBook wbh = (WebWorkBook)parameters.get(WorkBookCommander.WORKBOOK); String resource = (String)parameters.get(WorkBookCommander.RESOURCE); String format = (String)parameters.get(WorkBookCommander.FORMAT); String bval = (String)parameters.get(WorkBookCommander.VALUE); HttpServletRequest req = (HttpServletRequest)parameters.get(WorkBookCommander.REQUEST); String password = req.getParameter("password"); try { boolean lck = false; if(bval != null) lck = bval.equalsIgnoreCase("true"); WorkSheetHandle c = wbh.getWorkSheet(resource); c.setProtected(lck, password); return String.valueOf(c.getProtected()); }catch(WorkSheetNotFoundException e) { return WorkBookCommander.returnXMLErrorResponse("Set Sheet Protection: " + bval + " on: " + resource + " failed. " + e.toString()); } } /** * Check acccess for different methods based on userid, memeid, and methodcalled * * This method cannot be reached unless the user has at least read permissions * to the meme, so methods that only read can return true without checking. */ @Override public boolean checkAccess(Map parameters){ User usr = (User)parameters.get(WorkBookCommander.USER); String command = (String)parameters.get(WorkBookCommander.COMMAND); String memeid = (String)parameters.get(WorkBookCommander.ID); MemeDocument webdoc = (MemeDocument)parameters.get(WorkBookCommander.WORKBOOK); // defer to superclass for non-overridden methods if(super.checkAccess(parameters)) return true; command = command.toLowerCase(); if (command.equals("getprotected")){ if(webdoc.isPublic()) return true; else return usr.checkAccess("meme_" + memeid, AclEntry.READ); }else if(command.equals("setprotected")){ if (usr.checkAccess("meme_" + memeid, AclEntry.UPDATE)){ return true; } } return false; } }