Пример #1
0
 public void attributeReplaced(HttpSessionBindingEvent evt) {
   final String name = evt.getName();
   if (!shallIgnore(name)) {
     final Session sess = Sessions.getCurrent();
     if (sess instanceof SimpleSession && evt.getSession().equals(sess.getNativeSession()))
       ((SimpleSession) sess).getScopeListeners().notifyReplaced(name, evt.getValue());
   }
 }
Пример #2
0
 @Init
 public void initLogin() {
   Session s = this.getSessionZK();
   s.setAttribute(Config.LOGEADO, new Boolean(false));
   BindUtils.postGlobalCommand(null, null, "deshabilitarMenu", null);
   this.setTextoFormularioCorriente(" ");
   this.loadUsers();
 }
 @Override
 public UserCredential getUserCredential() {
   Session sess = Sessions.getCurrent();
   UserCredential cre = (UserCredential) sess.getAttribute("userCredential");
   if (cre == null) {
     cre = new UserCredential(); // new a anonymous user and set to session
     sess.setAttribute("userCredential", cre);
   }
   return cre;
 }
Пример #4
0
 /** 初始化树上的数据 */
 public void initTree() {
   Session session = Executions.getCurrent().getDesktop().getSession();
   Object selectedViewNameObject = session.getAttribute("selectedViewName");
   if (selectedViewNameObject != null) {
     String selectedViewName = (String) selectedViewNameObject;
     if (selectedViewName != null && !selectedViewName.isEmpty()) {
       this.viewName = selectedViewName;
     }
   }
   this.initTree(this.getViewName());
 }
Пример #5
0
  /**
   * Outputs the HTML tags of the given component to the given writer.
   *
   * @param path the request path. If null, the servlet path is assumed.
   * @param out the output (never null).
   * @param richlet the richlet to run. If you have only one component to show and no need process
   *     it under an execution, you could use {@link #render(javax.servlet.ServletContext,
   *     javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
   *     org.zkoss.zk.ui.Component, String, java.io.Writer)} instead.
   * @since 5.0.5
   */
  public static final void render(
      ServletContext ctx,
      HttpServletRequest request,
      HttpServletResponse response,
      Richlet richlet,
      String path,
      Writer out)
      throws ServletException, IOException {
    if (path == null) path = Https.getThisServletPath(request);

    WebManager webman = WebManager.getWebManagerIfAny(ctx);
    if (webman == null) {
      final String ATTR = "org.zkoss.zkplus.embed.updateURI";
      String updateURI = Library.getProperty(ATTR);
      if (updateURI == null) updateURI = "/zkau";
      else updateURI = Utils.checkUpdateURI(updateURI, ATTR);
      webman = new WebManager(ctx, updateURI);
    }

    final Session sess = WebManager.getSession(ctx, request);
    final WebApp wapp = sess.getWebApp();
    final WebAppCtrl wappc = (WebAppCtrl) wapp;
    final Object old =
        I18Ns.setup(sess, request, response, wapp.getConfiguration().getResponseCharset());
    Execution exec = null;
    try {
      final Desktop desktop = webman.getDesktop(sess, request, response, path, true);
      if (desktop == null) // forward or redirect
      return;

      final RequestInfo ri =
          new RequestInfoImpl(wapp, sess, desktop, request, PageDefinitions.getLocator(wapp, path));
      sess.setAttribute(Attributes.GAE_FIX, new Integer(0));
      ((SessionCtrl) sess).notifyClientRequest(true);

      final UiFactory uf = wappc.getUiFactory();
      final Page page = WebManager.newPage(uf, ri, richlet, response, path);
      exec = new ExecutionImpl(ctx, request, response, desktop, page);
      exec.setAttribute(Attributes.PAGE_REDRAW_CONTROL, "page");
      exec.setAttribute(Attributes.PAGE_RENDERER, new PageRenderer(exec));

      wappc.getUiEngine().execNewPage(exec, richlet, page, out);
      // no need to set device type here, since UiEngine will do it later
    } finally {
      I18Ns.cleanup(request, old);
      if (exec != null) {
        exec.removeAttribute(Attributes.PAGE_REDRAW_CONTROL);
        exec.removeAttribute(Attributes.PAGE_RENDERER);
      }
    }
  }
Пример #6
0
  /**
   * Generates the special JavaScript code, such as the application's name. It shall be called,
   * before generating "zkmx(" and "zkx(".
   *
   * @since 5.0.6
   */
  public static final String outSpecialJS(Desktop desktop) {
    final StringBuffer sb = new StringBuffer();

    // output application name
    String oldnm = (String) desktop.getAttribute(ATTR_APPNM);
    if (oldnm == null) oldnm = "ZK";
    final String appnm = desktop.getWebApp().getAppName();
    if (!oldnm.equals(appnm)) {
      sb.append("zk.appName='");
      Strings.escape(sb, appnm, Strings.ESCAPE_JAVASCRIPT).append("';");
      desktop.setAttribute(ATTR_APPNM, appnm);
    }

    // output zktheme cookie
    String oldthemenm = (String) desktop.getAttribute(ATTR_THEMENM);
    if (oldthemenm == null) oldthemenm = "";
    final Object request = desktop.getExecution().getNativeRequest();
    String themenm = "";
    if (request instanceof HttpServletRequest) {
      themenm = ThemeFns.getThemeResolver().getTheme((HttpServletRequest) request);
    }
    if (!oldthemenm.equals(themenm)) {
      sb.append("zk.themeName='");
      Strings.escape(sb, themenm, Strings.ESCAPE_JAVASCRIPT).append("';");
      desktop.setAttribute(ATTR_THEMENM, themenm);
    }

    // output ZK ICON
    final Session sess = Sessions.getCurrent();
    if (sess != null) {
      WebApp wapp = desktop.getWebApp();
      if (wapp == null
          || "CE".equals(WebApps.getEdition())
          || wapp.getAttribute("org.zkoss.zk.ui.notice") != null) {
        final PI pi = (PI) sess.getAttribute(ATTR_PI);
        boolean show = pi == null;
        if (show) sess.setAttribute(ATTR_PI, new PI());
        else show = pi.show();
        if (show) sb.append("zk.pi=1;");
      }
    }
    return sb.toString();
  }
  @Override
  public boolean login(String nm, String pd) {
    User user = userInfoService.findUser(nm);
    // a simple plan text password verification
    if (user == null || !user.getPassword().equals(pd)) {
      return false;
    }

    Session sess = Sessions.getCurrent();
    UserCredential cre = new UserCredential(user.getAccount(), user.getFullName());
    // just in case for this demo.
    if (cre.isAnonymous()) {
      return false;
    }
    sess.setAttribute("userCredential", cre);

    // TODO handle the role here for authorization
    return true;
  }
Пример #8
0
 public static GrantTreeModel getInstance(
     Session session, String rootid) // modifyed by qimin.xiong 2009-10-10
     {
   EccTreeModel eccModel = (EccTreeModel) session.getAttribute("eccWholeViewTreeModel");
   GrantTreeModel model = null;
   if (eccModel == null) {
     model = new GrantTreeModel(new EccTreeItem(null, rootid, "监测树", ""));
   } else {
     model = new GrantTreeModel(eccModel.getRoot());
   }
   model.addSpecialNode();
   return model;
 }
  public void onEventEdit(CalendarsEvent event) throws InterruptedException, RemoteException {
    try {
      StorageComponentProxy proxy = SystemDictionary.getSCProxy();
      Session ses = Sessions.getCurrent();
      String userid = (String) ses.getAttribute("userid");
      bookEventWin = (Window) Executions.createComponents("bookEvent.zul", self.getParent(), null);
      bookEventWin.setAttribute("calendars", cal);
      bookEventWin.setAttribute("calevent", event);
      Date setting = event.getCalendarEvent().getBeginDate();
      SimpleCalendarEvent scevent = (SimpleCalendarEvent) event.getCalendarEvent();
      bookEventWin.getFellow("cancelbutton").setVisible(true);
      ((Datebox) bookEventWin.getFellow("datetask")).setValue(setting);
      ((Datebox) bookEventWin.getFellow("datetask")).setReadonly(true);
      ((Datebox) bookEventWin.getFellow("datetask")).setButtonVisible(false);
      ((Timebox) bookEventWin.getFellow("timetask")).setValue(setting);
      ((Timebox) bookEventWin.getFellow("timetask")).setReadonly(true);
      ((Timebox) bookEventWin.getFellow("timetask")).setButtonVisible(false);
      ((Textbox) bookEventWin.getFellow("taskidfield"))
          .setValue((String) scevent.getParams().get("task"));
      ((Textbox) bookEventWin.getFellow("taskstatusfield"))
          .setValue(
              SystemDictionary.getTaskStatusLabel((String) scevent.getParams().get("status")));
      bookEventWin.getFellow("rowtaskstatus").setVisible(true);
      if (scevent.getParams().get("status").equals(SystemDictionary.TASK_STATUS_COMPLETED)) {
        bookEventWin.getFellow("cancelbutton").setVisible(false);
        String tasktype = (String) scevent.getParams().get("type");
        if (tasktype.equals(SystemDictionary.TASK_TYPE_CARERQS)
            || tasktype.equals(SystemDictionary.TASK_TYPE_PATIENTQS)) {
          // TODO retrieve Questionnaire answers and show in the task window
          Questionnaire q = (Questionnaire) scevent.getParams().get("questionnaire");
          QuestionnaireAnswers qa =
              proxy.getQuestionnaireAnswersByTask((String) scevent.getParams().get("task"), userid);
          SystemDictionary.webguiLog(
              "INFO", "task id: " + (String) scevent.getParams().get("task"));
          // SystemDictionary.webguiLog("INFO", "ANSWERS LENGTH: "+ qa.getAnswer().length);
          // SystemDictionary.webguiLog("INFO", "getQuestion: "+ q.getQuestion().length);
          ArrayList<QuestionnaireAnswer> qalist = new ArrayList<QuestionnaireAnswer>();
          if (qa.getAnswer() != null)
            for (int i = 0; i < qa.getAnswer().length; i++) {
              qalist.add(i, qa.getAnswer(i));
            }

          String responses = provideQuestionnaireResponse(toPlainList(q.getQuestion()), qalist);
          SystemDictionary.webguiLog("DEBUG", "RESPONSES: " + responses);
          bookEventWin.getFellow("qsanswersrow").setVisible(true);
          ((Label) bookEventWin.getFellow("qsanswersfield")).setValue(responses);

        } else if (tasktype.equals(SystemDictionary.TASK_TYPE_BLOODPRESSURE_MEASUREMENT)
            || tasktype.equals(SystemDictionary.TASK_TYPE_WEIGHT_MEASUREMENT)
            || tasktype.equals(SystemDictionary.TASK_TYPE_ACTMONITOR)) {
          String resultfieldvalue = "";
          SearchCriteria searchc =
              new SearchCriteria(
                  "task",
                  new SystemParameter(SystemDictionary.COMPARE_EQ, ""),
                  (String) scevent.getParams().get("task"),
                  "");
          Measurement[] results = proxy.getMeasurement(new SearchCriteria[] {searchc}, userid);
          if (results.length <= 0) {
            resultfieldvalue = "No measurement could be retrieved";
          } else {
            resultfieldvalue = "Use 'Monitor Measurements' button for viewing the measurements";
            /*SystemDictionary.webguiLog("DEBUG", "RESULTS LENGHT: "+results.length);
            for(int ii = 0 ; ii < results.length ; ii++){
            	resultfieldvalue += results[ii].getValue()+""+results[ii].getUnits()+"\n";
            }*/
          }
          bookEventWin.getFellow("mresultrow").setVisible(true);
          ((Label) bookEventWin.getFellow("mresultrowfield")).setValue(resultfieldvalue);
        }
      }
      User addressed = proxy.getUser((String) scevent.getParams().get("objid"));
      Patient patient = proxy.getPatient(addressed.getPersonID(), userid);
      ((Textbox) bookEventWin.getFellow("addressedid"))
          .setValue((String) scevent.getParams().get("objid"));
      ((Textbox) bookEventWin.getFellow("addressedstr")).setValue(patient.toString());
      User object = proxy.getUser((String) scevent.getParams().get("exec"));
      Carer executor = proxy.getCarer(object.getPersonID(), userid);
      ((Textbox) bookEventWin.getFellow("objid"))
          .setValue((String) scevent.getParams().get("exec"));
      ((Textbox) bookEventWin.getFellow("objstr")).setValue(executor.toString());
      User assigner = proxy.getUser((String) scevent.getParams().get("assign"));
      Clinician assg = proxy.getClinician(assigner.getPersonID(), userid);
      ((Textbox) bookEventWin.getFellow("userid"))
          .setValue((String) scevent.getParams().get("assign"));
      ((Textbox) bookEventWin.getFellow("userstr")).setValue(assg.toString());
      ((Textbox) bookEventWin.getFellow("tasktypetext")).setValue(scevent.getContent());
      bookEventWin.getFellow("tasktypetext").setVisible(true);
      // ((Combobox)bookEventWin.getFellow("addressedtext")).setVisible(false);
      int tasktype2 = Integer.parseInt((String) scevent.getParams().get("type"));
      this.showCustomFields(tasktype2);
      bookEventWin.getFellow("tasktypesel").setVisible(false);
      @SuppressWarnings("rawtypes")
      List items = ((Listbox) bookEventWin.getFellow("urlfield")).getItems();
      @SuppressWarnings("rawtypes")
      Iterator it = items.iterator();
      while (it.hasNext()) {
        Listitem currentitem = (Listitem) it.next();
        if (currentitem.getValue().equals((String) scevent.getParams().get("url"))) {
          ((Listbox) bookEventWin.getFellow("urlfield")).setSelectedItem(currentitem);
          break;
        }
      }
      ((Listbox) bookEventWin.getFellow("urlfield")).setDisabled(true);
      if (scevent.getParams().get("questionnaire") != null) {
        items = ((Listbox) bookEventWin.getFellow("questnamefield")).getItems();
        it = items.iterator();
        while (it.hasNext()) {
          Listitem currentitem = (Listitem) it.next();
          if (currentitem
              .getValue()
              .equals(((Questionnaire) scevent.getParams().get("questionnaire")).getID())) {
            ((Listbox) bookEventWin.getFellow("questnamefield")).setSelectedItem(currentitem);
            break;
          }
        }
      }
      ((Listbox) bookEventWin.getFellow("questnamefield")).setDisabled(true);
      // ((Textbox)bookEventWin.getFellow("urlfield")).setValue((String)scevent.getParams().get("url"));
      ((Textbox) bookEventWin.getFellow("textfield"))
          .setValue((String) scevent.getParams().get("text"));

      bookEventWin.setTitle("View Task");
      bookEventWin.setVisible(true);
      bookEventWin.doModal();
    } catch (Exception e) {
      e.printStackTrace();
      Executions.sendRedirect("");
    }
  }
Пример #10
0
  /**
   * Returns HTML tags to include all JavaScript files and codes that are required when loading a
   * ZUML page (never null).
   *
   * <p>FUTURE CONSIDERATION: we might generate the inclusion on demand instead of all at once.
   *
   * @param exec the execution (never null)
   * @param wapp the Web application. If null, exec.getDesktop().getWebApp() is used. So you have to
   *     specify it if the execution is not associated with desktop (a fake execution, such as
   *     JSP/DSP).
   * @param deviceType the device type, such as ajax. If null, exec.getDesktop().getDeviceType() is
   *     used. So you have to specify it if the execution is not associated with desktop (a fake
   *     execution).
   */
  public static final String outLangJavaScripts(Execution exec, WebApp wapp, String deviceType) {
    if (exec.isAsyncUpdate(null) || exec.getAttribute(ATTR_LANG_JS_GENED) != null)
      return ""; // nothing to generate
    exec.setAttribute(ATTR_LANG_JS_GENED, Boolean.TRUE);

    final Desktop desktop = exec.getDesktop();
    if (wapp == null) wapp = desktop.getWebApp();
    if (deviceType == null) deviceType = desktop != null ? desktop.getDeviceType() : "ajax";

    final StringBuffer sb = new StringBuffer(1536);

    final Set<JavaScript> jses = new LinkedHashSet<JavaScript>(32);
    for (LanguageDefinition langdef : LanguageDefinition.getByDeviceType(deviceType))
      jses.addAll(langdef.getJavaScripts());
    for (JavaScript js : jses) append(sb, js);

    sb.append("\n<!-- ZK ").append(wapp.getVersion());
    if (WebApps.getFeature("ee")) sb.append(" EE");
    else if (WebApps.getFeature("pe")) sb.append(" PE");
    sb.append(' ').append(wapp.getBuild());
    Object o = wapp.getAttribute("org.zkoss.zk.ui.notice");
    if (o != null) sb.append(o);
    sb.append(" -->\n");

    int tmout = 0;
    final Boolean autoTimeout = getAutomaticTimeout(desktop);
    if (autoTimeout != null
        ? autoTimeout.booleanValue()
        : wapp.getConfiguration().isAutomaticTimeout(deviceType)) {
      if (desktop != null) {
        tmout = desktop.getSession().getMaxInactiveInterval();
      } else {
        Object req = exec.getNativeRequest();
        if (req instanceof HttpServletRequest) {
          final HttpSession hsess = ((HttpServletRequest) req).getSession(false);
          if (hsess != null) {
            final Session sess = SessionsCtrl.getSession(wapp, hsess);
            if (sess != null) {
              tmout = sess.getMaxInactiveInterval();
            } else {
              // try configuration first since HttpSession's timeout is set
              // when ZK Session is created (so it is not set yet)
              // Note: no need to setMaxInactiveInternval here since it will
              // be set later or not useful at the end
              tmout = wapp.getConfiguration().getSessionMaxInactiveInterval();
              if (tmout <= 0) // system default
              tmout = hsess.getMaxInactiveInterval();
            }
          } else tmout = wapp.getConfiguration().getSessionMaxInactiveInterval();
        }
      }
      if (tmout > 0) { // unit: seconds
        int extra = tmout / 8;
        tmout += extra > 60 ? 60 : extra < 5 ? 5 : extra;
        // Add extra seconds to ensure it is really timeout
      }
    }

    final boolean
        keepDesktop =
            exec.getAttribute(Attributes.NO_CACHE) == null
                && !"page".equals(ExecutionsCtrl.getPageRedrawControl(exec)),
        groupingAllowed = isGroupingAllowed(desktop);
    final String progressboxPos =
        org.zkoss.lang.Library.getProperty("org.zkoss.zul.progressbox.position", "");
    if (tmout > 0 || keepDesktop || progressboxPos.length() > 0 || !groupingAllowed) {
      sb.append("<script class=\"z-runonce\" type=\"text/javascript\">\nzkopt({");

      if (keepDesktop) sb.append("kd:1,");
      if (!groupingAllowed) sb.append("gd:1,");
      if (tmout > 0) sb.append("to:").append(tmout).append(',');
      if (progressboxPos.length() > 0) sb.append("ppos:'").append(progressboxPos).append('\'');

      if (sb.charAt(sb.length() - 1) == ',') sb.setLength(sb.length() - 1);
      sb.append("});\n</script>");
    }

    final Device device = Devices.getDevice(deviceType);
    String s = device.getEmbedded();
    if (s != null) sb.append(s).append('\n');
    return sb.toString();
  }
Пример #11
0
 /**
  * Returns the desktop of the specified ID, or null if not found. If null is returned, {@link
  * #recoverDesktop} will be invoked.
  *
  * @param sess the session (never null)
  * @param dtid the desktop ID to look for
  * @since 5.0.3
  */
 protected Desktop getDesktop(Session sess, String dtid) {
   return ((WebAppCtrl) sess.getWebApp()).getDesktopCache(sess).getDesktopIfAny(dtid);
 }
Пример #12
0
  /**
   * Process asynchronous update requests from the client.
   *
   * @since 3.0.0
   */
  protected void process(Session sess, HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    final String errClient = request.getHeader("ZK-Error-Report");
    if (errClient != null)
      if (log.debugable())
        log.debug("Error found at client: " + errClient + "\n" + Servlets.getDetail(request));

    // parse desktop ID
    final WebApp wapp = sess.getWebApp();
    final WebAppCtrl wappc = (WebAppCtrl) wapp;
    final AuDecoder audec = getAuDecoder(wapp);
    final String dtid = audec.getDesktopId(request);
    if (dtid == null) {
      // Bug 1929139: incomplete request (IE only)
      if (log.debugable()) {
        final String msg = "Incomplete request\n" + Servlets.getDetail(request);
        log.debug(msg);
      }

      response.sendError(467, "Incomplete request");
      return;
    }

    Desktop desktop = getDesktop(sess, dtid);
    if (desktop == null) {
      final String cmdId = audec.getFirstCommand(request);
      if (!"rmDesktop".equals(cmdId))
        desktop = recoverDesktop(sess, request, response, wappc, dtid);

      if (desktop == null) {
        response.setIntHeader("ZK-Error", response.SC_GONE); // denote timeout
        sessionTimeout(request, response, wapp, dtid);
        return;
      }
    }
    WebManager.setDesktop(request, desktop);
    // reason: a new page might be created (such as include)

    final String sid = request.getHeader("ZK-SID");
    if (sid != null) // Some client might not have ZK-SID
    response.setHeader("ZK-SID", sid);

    // parse commands
    final Configuration config = wapp.getConfiguration();
    final List aureqs;
    boolean keepAlive = false;
    try {
      final boolean timerKeepAlive = config.isTimerKeepAlive();
      aureqs = audec.decode(request, desktop);
      for (Iterator it = aureqs.iterator(); it.hasNext(); ) {
        final String cmdId = ((AuRequest) it.next()).getCommand();
        keepAlive = !(!timerKeepAlive && Events.ON_TIMER.equals(cmdId)) && !"dummy".equals(cmdId);
        // dummy is used for PollingServerPush for piggyback
        if (keepAlive) break; // done
      }
    } catch (Throwable ex) {
      log.warningBriefly(ex);
      responseError(request, response, Exceptions.getMessage(ex));
      return;
    }

    if (aureqs.isEmpty()) {
      final String errmsg = "Illegal request: cmd required";
      log.debug(errmsg);
      responseError(request, response, errmsg);
      return;
    }

    ((SessionCtrl) sess).notifyClientRequest(keepAlive);

    //		if (log.debugable()) log.debug("AU request: "+aureqs);
    final DesktopCtrl desktopCtrl = (DesktopCtrl) desktop;
    final Execution exec = new ExecutionImpl(getServletContext(), request, response, desktop, null);
    if (sid != null) ((ExecutionCtrl) exec).setRequestId(sid);

    final AuWriter out = AuWriters.newInstance();
    out.setCompress(_compress);
    out.open(
        request,
        response,
        desktop.getDevice().isSupported(Device.RESEND)
            ? getProcessTimeout(config.getResendDelay())
            : 0);
    // Note: getResendDelay() might return nonpositive
    try {
      wappc.getUiEngine().execUpdate(exec, aureqs, out);
    } catch (RequestOutOfSequenceException ex) {
      log.warning(ex.getMessage());
      response.setHeader("ZK-SID", sid);
      response.setIntHeader("ZK-Error", AuResponse.SC_OUT_OF_SEQUENCE);
    }
    out.close(request, response);
  }
 @Override
 public void logout() {
   Session sess = Sessions.getCurrent();
   sess.removeAttribute("userCredential");
 }