📄 managecomponents.java
字号:
HttpServletResponse response, HttpSession session ) throws IOException, ServletException { try { JahiaApplicationsManagerService appManServ = sReg.getJahiaApplicationsManagerService(); JahiaWebAppsDeployerService appDepServ = sReg.getJahiaWebAppsDeployerService(); if ( appManServ == null || appDepServ == null ){ throw new JahiaException( "Unavailable Services", "Unavailable Services", JahiaException.SERVICE_ERROR, JahiaException.ERROR ); } request.setAttribute("warningMsg",""); String subAction = (String)request.getParameter("subaction"); String appPath = (String)request.getParameter("appPath"); String appName = (String)request.getParameter("appName"); String appDescr = (String)request.getParameter("appDescr"); if ( subAction == null || (subAction.length()<=0) ){ request.setAttribute("appPath", ""); } else if ( subAction.equals("scanDir") ) { appPath = (String)request.getParameter("appPath"); JahiaWebAppsPackage pack = appDepServ.loadWebAppInfo(appPath); if ( pack != null ){ request.setAttribute("appPath",appPath); // check if this application has been already registered in Jahia ApplicationBean app = appManServ.getApplication("/" + pack.getContextRoot()); if ( app != null ){ request.setAttribute( "warningMsg", "There is already a component registered in Jahia and using the same context."); request.setAttribute("appName",""); request.setAttribute("appDescr",""); } else { if ( appName == null ){ appName = pack.getContextRoot(); } if ( appDescr == null ){ appDescr = ""; } request.setAttribute("appName",appName); request.setAttribute("appDescr",appDescr); request.setAttribute("aPackage",pack); } } else { request.setAttribute("appPath",appPath); request.setAttribute("warningMsg", "No informations relative to a web component has been found, please control the path value"); } } else if ( subAction.equals("deploy") ){ request.setAttribute("appPath",appPath); request.setAttribute("appName",appName); request.setAttribute("appDescr",appDescr); JahiaWebAppsPackage pack = appDepServ.loadWebAppInfo(appPath); if ( pack != null ){ if ( !pack.isDirectory() ){ if ( appDepServ.deploy(site,pack.getContextRoot(),appPath) ){ // update with value from form ApplicationBean app = appManServ.getApplication("/" + pack.getContextRoot()); if ( app != null ){ if (appName != null && appName.trim().length()>0 ){ app.setName(appName); } app.setdesc(appDescr); appManServ.saveDefinition(app); } request.setAttribute("warningMsg", "The component has been successfully registered in Jahia"); } else { request.setAttribute("warningMsg", "An error occurred while registering the new component"); request.setAttribute("aPackage",pack); } } else { appDepServ.registerWebApps( site, pack.getContextRoot(), pack.getContextRoot(), pack.getWebApps()); // update with value from form ApplicationBean app = appManServ.getApplication("/" + pack.getContextRoot()); if ( app != null ){ if (appName != null && appName.trim().length()>0 ){ app.setName(appName); } app.setdesc(appDescr); appManServ.saveDefinition(app); } request.setAttribute("warningMsg", "The component has been successfully registered in Jahia"); } } else { request.setAttribute("warningMsg", "no informations relative to a web component has been found, please control the path value"); } } JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "component_add.jsp" ); } catch ( JahiaException je ){ request.setAttribute("jahiaDisplayMessage", "An error occured while processing your request"); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "menu.jsp" ); } } // end addComponent //------------------------------------------------------------------------- /** * Component sharing between sites. * @author NK * * @param request Servlet request. * @param response Servlet response. * @param session HttpSession object. */ private void shareComponent( HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws IOException, ServletException { try { JahiaApplicationsManagerService appManServ = sReg.getJahiaApplicationsManagerService(); JahiaSitesService sitesServ = sReg.getJahiaSitesService(); AppsShareService appShareServ = sReg.getAppsShareService(); JahiaApplicationsManagerService appPersServ = sReg.getJahiaApplicationsManagerService(); JahiaGroupManagerService grpManServ = sReg.getJahiaGroupManagerService(); if ( appManServ == null || sitesServ == null || appShareServ == null || appPersServ == null || grpManServ == null ){ throw new JahiaException( "Unavailable Services", "Unavailable Services", JahiaException.SERVICE_ERROR, JahiaException.ERROR ); } // get the list of all site Vector apps = appPersServ.getApplications(); Vector ownApps = new Vector(); // the site's apps if ( apps == null ){ apps = new Vector(); } int size = apps.size(); ApplicationBean appItem = null; for ( int i=0 ; i<size ; i++){ appItem = (ApplicationBean)apps.get(i); if ( appItem.getJahiaID() == site.getID() ){ ownApps.add(appItem); } } request.setAttribute("appsList", ownApps.elements()); Vector grantedSites = new Vector(); // get sites where the user has an admin access... try { grantedSites = grpManServ.getAdminGrantedSites( user ); } catch (Exception e) { grantedSites.add( site ); } request.setAttribute( "sitesList", grantedSites ); // get the current application int appID = -1; String appIDStr = ""; ApplicationBean app = null; if ( request.getParameter("apps") == null ){ if ( ownApps.size()>0 ){ app = (ApplicationBean)ownApps.get(0); // get the first app appID = app.getID(); } } else { appIDStr = request.getParameter("apps"); appID = Integer.parseInt(appIDStr); app = appManServ.getApplication(appID); } String subAction = null; if ( request.getParameter("subaction") != null ){ subAction = (String) request.getParameter("subaction"); } if ( subAction != null && subAction.equals("save") ){ // delete all share for this app appShareServ.removeShares(app); // add new ones; String[] vals = request.getParameterValues("authSites"); if ( vals != null ){ JahiaSite authSite = null; for ( int i=0; i<vals.length ; i++){ authSite = sitesServ.getSite(Integer.parseInt(vals[i])); appShareServ.addShare(authSite,app); } } appPersServ.saveDefinition(app); } // get the list of authorized sites for this application Enumeration authSitesID = null; authSitesID = appShareServ.getSites( app ); Vector authSites = new Vector(); Integer siteID = null; while( authSitesID.hasMoreElements() ){ siteID = (Integer)authSitesID.nextElement(); JahiaSite aSite = sitesServ.getSite(siteID.intValue()); authSites.add(aSite); } request.setAttribute( "app", app ); request.setAttribute( "appID", new Integer(appID) ); request.setAttribute( "authSites", authSites.elements() ); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "component_share.jsp" ); } catch ( JahiaException je ){ request.setAttribute("jahiaDisplayMessage", "An error occured while processing your request"); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "menu.jsp" ); } } //------------------------------------------------------------------------- /** * Search Jahia Encrypted Components and decrypt them * * @author NK * @param request Servlet request. * @param response Servlet response. * @param session HttpSession object. */ private void decryptJec( HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws IOException, ServletException { try { JahiaConsole.println(CLASS_NAME+"decryptJec","started"); JahiaWebAppsDeployerService appDepServ = sReg.getJahiaWebAppsDeployerService(); if ( appDepServ == null ){ throw new JahiaException( "Unavailable Services", "Unavailable Services", JahiaException.SERVICE_ERROR, JahiaException.ERROR ); } // get the new component disk path for te current site String path = appDepServ.getNewWebAppsPath() + File.separator + site.getSiteKey() ; File folder = new File(path); File[] files = new File[0]; if ( folder.isDirectory() ){ files = folder.listFiles(); } int size = files.length; Hashtable cryptedComp = new Hashtable(); File f = null; JecFile jec = null; // get license info int jecLicenseType = 0; int jecLicenseTypeRelComp = 0; // decrypt Jahia Encrypted Components for ( int i=0 ; i<size ; i++ ){ f = files[i]; if ( f.isFile() && (f.getName().toLowerCase()).endsWith(".jec") ){ boolean tryAgain = true; boolean goSleep = false; int status = 0; try { JahiaConsole.println(CLASS_NAME+"decryptJec","Found file " + f.getAbsolutePath()); jec = new JecFile(f.getAbsolutePath()); jecLicenseType = jec.getLicenseType(); jecLicenseTypeRelComp = jec.getLicenseTypeRelComp(); if ( mLicenseKey.compareLicense(jecLicenseType, jecLicenseTypeRelComp) ){ jec.extractFiles(); status = JefFileConstants.UNLOCKED; f.delete(); } else { status = JefFileConstants.LOCKED; } jec = null; } catch ( JefFileKeyNotFoundException knf ){ status = JefFileConstants.INVALID_JEF_FILE; JahiaConsole.println(CLASS_NAME+"decryptJec","Exception " + knf.getMessage() ); File tmpFile = new File(f.getAbsolutePath() + "_error"); f.renameTo(tmpFile); } catch ( JefFileInvalidKeyValueException ikv ){ status = JefFileConstants.INVALID_JEF_FILE; JahiaConsole.println(CLASS_NAME+"decryptJec","Exception " + ikv.getMessage() ); File tmpFile = new File(f.getAbsolutePath() + "_error"); f.renameTo(tmpFile); } catch ( InvalidJefFileException ijf ){ status = JefFileConstants.INVALID_JEF_FILE; JahiaConsole.println(CLASS_NAME+"decryptJec","Exception " + ijf.getMessage() ); File tmpFile = new File(f.getAbsolutePath() + "_error"); f.renameTo(tmpFile); } catch ( IOException ioe ){ status = JefFileConstants.IO_ERROR; JahiaConsole.println(CLASS_NAME+"decryptJec","IOException " + ioe.getMessage()); ioe.printStackTrace(); } catch ( JahiaException je ){ status = je.getErrorCode(); JahiaConsole.println(CLASS_NAME+"decryptJec","JahiaException " + je.getMessage()); je.printStackTrace(); } catch ( Throwable t ){ status = JefFileConstants.UNKNOWN_ERROR; JahiaConsole.println(CLASS_NAME+"decryptJec","Exception " + t.getMessage()); t.printStackTrace(); } cryptedComp.put(f.getName(),new Integer(status)); JahiaConsole.println(CLASS_NAME+"decryptJec","Status " + status); } } request.setAttribute("cryptedComp", cryptedComp); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "component_decryptjec.jsp" ); } catch ( JahiaException je ){ request.setAttribute("jahiaDisplayMessage", "An error occured while processing your request"); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "menu.jsp" ); } }} // end ManageComponents
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -