List of usage examples for javax.servlet ServletContext setAttribute
public void setAttribute(String name, Object object);
From source file:com.ikon.servlet.admin.MimeTypeServlet.java
/** * Delete mime type// w w w. jav a2 s . c om */ private void delete(String userId, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException { log.debug("delete({}, {}, {})", new Object[] { userId, request, response }); ServletContext sc = getServletContext(); int mtId = WebUtils.getInt(request, "mt_id"); MimeType mt = MimeTypeDAO.findByPk(mtId); String extensions = ""; for (String ext : mt.getExtensions()) { extensions += ext + " "; } sc.setAttribute("action", WebUtils.getString(request, "action")); sc.setAttribute("extensions", extensions.trim()); sc.setAttribute("mt", mt); sc.getRequestDispatcher("/admin/mime_edit.jsp").forward(request, response); log.debug("delete: void"); }
From source file:com.ikon.servlet.admin.MimeTypeServlet.java
/** * Edit mime type//from w ww. j a va 2 s .co m */ private void edit(String userId, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException { log.debug("edit({}, {}, {})", new Object[] { userId, request, response }); ServletContext sc = getServletContext(); int mtId = WebUtils.getInt(request, "mt_id"); MimeType mt = MimeTypeDAO.findByPk(mtId); String extensions = ""; for (String ext : mt.getExtensions()) { extensions += ext + " "; } sc.setAttribute("action", WebUtils.getString(request, "action")); sc.setAttribute("extensions", extensions.trim()); sc.setAttribute("mt", mt); sc.getRequestDispatcher("/admin/mime_edit.jsp").forward(request, response); log.debug("edit: void"); }
From source file:com.openkm.servlet.admin.DbRepositoryViewServlet.java
/** * Edit node property.//from w w w . j a v a 2s . com */ private void edit(String uuid, String path, HttpServletRequest request, HttpServletResponse response) throws PathNotFoundException, DatabaseException, ServletException, IOException { log.debug("edit({}, {})", new Object[] { request, response }); String property = WebUtils.getString(request, "property"); String group = WebUtils.getString(request, "group"); String value = WebUtils.getString(request, "value"); String field = WebUtils.getString(request, "field"); ServletContext sc = getServletContext(); sc.setAttribute("uuid", uuid); sc.setAttribute("path", path); sc.setAttribute("field", field); sc.setAttribute("property", property); sc.setAttribute("group", group); sc.setAttribute("value", value); sc.getRequestDispatcher("/admin/db_repository_edit.jsp").forward(request, response); log.debug("edit: void"); }
From source file:com.openkm.servlet.admin.StampServlet.java
/** * Edit image stamp/*w w w .j a va 2 s . c o m*/ */ private void imageEdit(Session session, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException, NoSuchAlgorithmException { log.debug("imageEdit({}, {}, {})", new Object[] { session, request, response }); ServletContext sc = getServletContext(); int siId = WebUtils.getInt(request, "si_id"); sc.setAttribute("action", WebUtils.getString(request, "action")); sc.setAttribute("persist", true); sc.setAttribute("users", AuthDAO.findAllUsers(true)); sc.setAttribute("stamp", StampImageDAO.findByPk(siId)); sc.getRequestDispatcher("/admin/stamp_image_edit.jsp").forward(request, response); log.debug("imageEdit: void"); }
From source file:com.openkm.servlet.admin.StampServlet.java
/** * Delete image stamp/*from ww w . j a v a 2 s . c o m*/ */ private void imageDelete(Session session, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException, NoSuchAlgorithmException { log.debug("imageDelete({}, {}, {})", new Object[] { session, request, response }); ServletContext sc = getServletContext(); int siId = WebUtils.getInt(request, "si_id"); sc.setAttribute("action", WebUtils.getString(request, "action")); sc.setAttribute("persist", true); sc.setAttribute("users", AuthDAO.findAllUsers(true)); sc.setAttribute("stamp", StampImageDAO.findByPk(siId)); sc.getRequestDispatcher("/admin/stamp_image_edit.jsp").forward(request, response); log.debug("imageDelete: void"); }
From source file:org.springframework.web.context.support.ServletContextAttributeExporter.java
@Override public void setServletContext(ServletContext servletContext) { if (this.attributes != null) { for (Map.Entry<String, Object> entry : this.attributes.entrySet()) { String attributeName = entry.getKey(); if (logger.isWarnEnabled()) { if (servletContext.getAttribute(attributeName) != null) { logger.warn(/*from w w w . jav a 2 s .c om*/ "Replacing existing ServletContext attribute with name '" + attributeName + "'"); } } servletContext.setAttribute(attributeName, entry.getValue()); if (logger.isInfoEnabled()) { logger.info("Exported ServletContext attribute with name '" + attributeName + "'"); } } } }
From source file:com.osbitools.ws.shared.prj.web.AbstractWsPrjInit.java
@Override public void contextInitialized(ServletContextEvent evt) { super.contextInitialized(evt); ServletContext ctx = evt.getServletContext(); // First - Load Custom Error List try {/* www.ja v a 2 s. c o m*/ Class.forName("com.osbitools.ws.shared.prj.CustErrorList"); } catch (ClassNotFoundException e) { // Ignore Error } // Initialize Entity Utils IEntityUtils eut = getEntityUtils(); ctx.setAttribute("entity_utils", eut); // Initiate LangSetFileUtils ctx.setAttribute("ll_set_utils", new LangSetUtils()); // Check if git repository exists and create one // Using ds subdirectory as git root repository File drepo = new File( getConfigDir(ctx) + File.separator + eut.getPrjRootDirName() + File.separator + ".git"); Git git; try { if (!drepo.exists()) { if (!drepo.mkdirs()) throw new RuntimeErrorException( new Error("Unable create directory '" + drepo.getAbsolutePath() + "'")); try { git = createGitRepo(drepo); } catch (Exception e) { throw new RuntimeErrorException(new Error( "Unable create new repo on path: " + drepo.getAbsolutePath() + ". " + e.getMessage())); } getLogger(ctx).info("Created new git repository '" + drepo.getAbsolutePath() + "'"); } else if (!drepo.isDirectory()) { throw new RuntimeErrorException( new Error(drepo.getAbsolutePath() + " is regular file and not a directory")); } else { git = Git.open(drepo); getLogger(ctx).debug("Open existing repository " + drepo.getAbsolutePath()); } } catch (IOException e) { // Something unexpected and needs to be analyzed e.printStackTrace(); throw new RuntimeErrorException(new Error(e)); } // Save git handler ctx.setAttribute("git", git); // Check if remote destination set/changed StoredConfig config = git.getRepository().getConfig(); String rname = (String) ctx.getAttribute(PrjMgrConstants.PREMOTE_GIT_NAME); String rurl = (String) ctx.getAttribute("git_remote_url"); if (!Utils.isEmpty(rname) && !Utils.isEmpty(rurl)) { String url = config.getString("remote", rname, "url"); if (!rurl.equals(url)) { config.setString("remote", rname, "url", rurl); try { config.save(); } catch (IOException e) { getLogger(ctx).error("Error saving git remote url. " + e.getMessage()); } } } // Temp directory for files upload String tname = System.getProperty("java.io.tmpdir"); getLogger(ctx).info("Using temporarily directory '" + tname + "' for file uploads"); File tdir = new File(tname); if (!tdir.exists()) throw new RuntimeErrorException( new Error("Temporarily directory for file upload '" + tname + "' is not found")); if (!tdir.isDirectory()) throw new RuntimeErrorException( new Error("Temporarily directory for file upload '" + tname + "' is not a directory")); DiskFileItemFactory dfi = new DiskFileItemFactory(); dfi.setSizeThreshold( ((Integer) ctx.getAttribute(PrjMgrConstants.SMAX_FILE_UPLOAD_SIZE_NAME)) * 1024 * 1024); dfi.setRepository(tdir); evt.getServletContext().setAttribute("dfi", dfi); // Save entity utils in context evt.getServletContext().setAttribute("entity_utils", getEntityUtils()); }
From source file:org.acoustid.server.ApplicationContextListener.java
@Override public void contextInitialized(ServletContextEvent event) { ServletContext servletContext = event.getServletContext(); String configFileName = servletContext.getInitParameter("config"); logger.info("Loading configuration from " + configFileName); XMLConfiguration config;// ww w . j a va 2 s.co m try { config = new XMLConfiguration(configFileName); } catch (ConfigurationException ex) { throw new RuntimeException("Couldn't load configuration file", ex); } Injector injector = Guice.createInjector(new ServerModule(config)); logger.debug("Setting injector"); servletContext.setAttribute(INJECTOR_ATTRIBUTE_NAME, injector); }
From source file:com.openkm.servlet.admin.StampServlet.java
/** * Delete text stamp//from w w w. j a v a 2 s.co m */ private void textDelete(Session session, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException, NoSuchAlgorithmException { log.debug("textDelete({}, {}, {})", new Object[] { session, request, response }); if (WebUtils.getBoolean(request, "persist")) { int stId = WebUtils.getInt(request, "st_id"); StampTextDAO.delete(stId); // Activity log UserActivity.log(session.getUserID(), "ADMIN_STAMP_TEXT_DELETE", Integer.toString(stId), null); } else { ServletContext sc = getServletContext(); int stId = WebUtils.getInt(request, "st_id"); sc.setAttribute("action", WebUtils.getString(request, "action")); sc.setAttribute("persist", true); sc.setAttribute("users", AuthDAO.findAllUsers(true)); sc.setAttribute("stamp", StampTextDAO.findByPk(stId)); sc.getRequestDispatcher("/admin/stamp_text_edit.jsp").forward(request, response); } log.debug("textDelete: void"); }