Example #1
0
  public void render(FacesContext context) throws FacesException {
    if (context.getResponseComplete()) return;

    Application app = context.getApplication();
    ViewHandler view = app.getViewHandler();

    beforePhase(context, PhaseId.RENDER_RESPONSE);

    try {
      if (log.isLoggable(Level.FINER)) log.finer(context.getViewRoot() + " before render view");

      view.renderView(context, context.getViewRoot());
    } catch (java.io.IOException e) {
      if (sendError(context, "renderView", e)) return;

      throw new FacesException(e);
    } catch (RuntimeException e) {
      if (sendError(context, "renderView", e)) return;

      throw e;
    } finally {
      afterPhase(context, PhaseId.RENDER_RESPONSE);

      logMessages(context);
    }
  }
Example #2
0
  /**
   * 返回响应结果
   *
   * @param response
   * @return
   */
  public static RestResponse returnResponse(
      BaseRestRequest request,
      RestResponse response,
      RestServiceMapping serviceMapping,
      RestServiceConfiguration configuration) {

    String cmd = request.getRestRequest().getCmd();

    // 调用后置拦截器
    List<RestRequestAfterInterceptor> requestAfterInterceptors =
        configuration.getRequestAfterInterceptors();
    for (RestRequestAfterInterceptor requestInterceptor : requestAfterInterceptors) {
      String requestInterceptorName = requestInterceptor.getName();
      logger.debug(
          "REST_AFTER_INTERCEPTOR_START, cmd: {}, name: {}",
          cmd,
          requestInterceptorName + "|" + requestInterceptor.getClass().getName());
      try {
        requestInterceptor.setConfiguration(configuration);
        requestInterceptor.execute(serviceMapping, request, response);
      } catch (Exception e) {
        response.setException(e);
        logger.warn("执行拦截器 {} 失败", requestInterceptorName, e);
      }
      logger.debug(
          "REST_AFTER_INTERCEPTOR_COMPLETE, cmd: {}, name: {}",
          cmd,
          requestInterceptorName + "|" + requestInterceptor.getClass().getName());
    }
    return response;
  }
  /**
   * Returns true if the user represented by the current request plays the named role.
   *
   * @param role the named role to test.
   * @return true if the user plays the role.
   */
  public boolean isUserInRole(String role) {
    ServletInvocation invocation = getInvocation();

    if (invocation == null) {
      if (getRequest() != null) return getRequest().isUserInRole(role);
      else return false;
    }

    HashMap<String, String> roleMap = invocation.getSecurityRoleMap();

    if (roleMap != null) {
      String linkRole = roleMap.get(role);

      if (linkRole != null) role = linkRole;
    }

    String runAs = getRunAs();

    if (runAs != null) return runAs.equals(role);

    WebApp webApp = getWebApp();

    Principal user = getUserPrincipal();

    if (user == null) {
      if (log.isLoggable(Level.FINE)) log.fine(this + " no user for isUserInRole");

      return false;
    }

    RoleMapManager roleManager = webApp != null ? webApp.getRoleMapManager() : null;

    if (roleManager != null) {
      Boolean result = roleManager.isUserInRole(role, user);

      if (result != null) {
        if (log.isLoggable(Level.FINE)) log.fine(this + " userInRole(" + role + ")->" + result);

        return result;
      }
    }

    Login login = webApp == null ? null : webApp.getLogin();

    boolean inRole = login != null && login.isUserInRole(user, role);

    if (log.isLoggable(Level.FINE)) {
      if (login == null) log.fine(this + " no Login for isUserInRole");
      else if (user == null) log.fine(this + " no user for isUserInRole");
      else if (inRole) log.fine(this + " " + user + " is in role: " + role);
      else log.fine(this + " failed " + user + " in role: " + role);
    }

    return inRole;
  }
Example #4
0
  /** Returns a JarDiff for the given request */
  public synchronized DownloadResponse getJarDiffEntry(
      ResourceCatalog catalog, DownloadRequest dreq, JnlpResource res) {
    if (dreq.getCurrentVersionId() == null) return null;

    // check whether the request is from javaws 1.0/1.0.1
    // do not generate minimal jardiff if it is from 1.0/1.0.1
    boolean doJarDiffWorkAround = isJavawsVersion(dreq, "1.0*");

    // First do a lookup to find a match
    JarDiffKey key =
        new JarDiffKey(
            res.getName(),
            dreq.getCurrentVersionId(),
            res.getReturnVersionId(),
            !doJarDiffWorkAround);

    JarDiffEntry entry = (JarDiffEntry) _jarDiffEntries.get(key);
    // If entry is not found, then the querty has not been made.
    if (entry == null) {
      if (_log.isInformationalLevel()) {
        _log.addInformational(
            "servlet.log.info.jardiff.gen",
            res.getName(),
            dreq.getCurrentVersionId(),
            res.getReturnVersionId());
      }
      File f = generateJarDiff(catalog, dreq, res, doJarDiffWorkAround);
      if (f == null) {
        _log.addWarning(
            "servlet.log.warning.jardiff.failed",
            res.getName(),
            dreq.getCurrentVersionId(),
            res.getReturnVersionId());
      }
      // Store entry in table
      entry = new JarDiffEntry(f);
      _jarDiffEntries.put(key, entry);
    }

    // Check for no JarDiff to return
    if (entry.getJarDiffFile() == null) {
      return null;
    } else {
      return DownloadResponse.getFileDownloadResponse(
          entry.getJarDiffFile(),
          _jarDiffMimeType,
          entry.getJarDiffFile().lastModified(),
          res.getReturnVersionId());
    }
  }
  public void summaryAction(HttpServletRequest req, HttpServletResponse res) {
    if (AccountController.redirectIfNoCookie(req, res)) return;

    Map<String, Object> viewData = new HashMap<String, Object>();
    DocumentManager docMan = new DocumentManager();

    try {

      if (req.getParameter("documentId") != null) {
        // Get the document ID
        int docId = Integer.parseInt(req.getParameter("documentId"));
        // Get the document using document id
        Document document = docMan.get(docId);
        // Set title to name of the document
        viewData.put("title", document.getDocumentName());
        // Create List of access records
        List<AccessRecord> accessRecords = new LinkedList<AccessRecord>();
        // Add access records for document to the list
        accessRecords = docMan.getAccessRecords(docId);

        viewData.put("accessRecords", accessRecords);
      } else {
        // Go back to thread page.
      }

    } catch (Exception e) {
      Logger.getLogger("").log(Level.SEVERE, "An error occurred when getting profile user", e);
    }

    view(req, res, "/views/group/Document.jsp", viewData);
  }
  public final Response executeCommand(
      Object inputPar,
      UserSessionParameters userSessionPars,
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession userSession,
      ServletContext context) {
    try {
      String tableName = ((Object[]) inputPar)[0].toString();
      ArrayList oldVOs = (ArrayList) ((Object[]) inputPar)[1];
      ArrayList newVOs = (ArrayList) ((Object[]) inputPar)[2];

      VariantTypes bean = (VariantTypes) JAIOBeanFactory.getInstance().getBean(VariantTypes.class);
      Response answer =
          bean.updateVariantTypes(
              tableName,
              oldVOs,
              newVOs,
              ((JAIOUserSessionParameters) userSessionPars).getServerLanguageId(),
              userSessionPars.getUsername());

      return answer;
    } catch (Throwable ex) {
      Logger.error(
          userSessionPars.getUsername(),
          this.getClass().getName(),
          "executeCommand",
          "Error while processing request",
          ex);
      return new ErrorResponse(ex.getMessage());
    }
  }
  public final Response executeCommand(
      Object inputPar,
      UserSessionParameters userSessionPars,
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession userSession,
      ServletContext context) {
    ArrayList vos = (ArrayList) inputPar;
    try {

      ItemDiscounts bean =
          (ItemDiscounts) JAIOBeanFactory.getInstance().getBean(ItemDiscounts.class);
      Response answer =
          bean.deleteItemDiscounts(
              vos,
              ((JAIOUserSessionParameters) userSessionPars).getServerLanguageId(),
              userSessionPars.getUsername());

      return answer;
    } catch (Throwable ex) {
      Logger.error(
          userSessionPars.getUsername(),
          this.getClass().getName(),
          "executeCommand",
          "Error while processing request",
          ex);
      return new ErrorResponse(ex.getMessage());
    }
  }
  @Override
  public void render(RenderRequest portletReq, RenderResponse portletResp)
      throws PortletException, IOException {
    LOGGER.entering(LOG_CLASS, "main portlet render entry");

    long tid = Thread.currentThread().getId();
    portletReq.setAttribute(THREADID_ATTR, tid);

    PrintWriter writer = portletResp.getWriter();

    writer.write(
        "<div id=\"DispatcherTests_SPEC2_19_ForwardServletResource\">no resource output.</div>\n");
    ResourceURL resurl = portletResp.createResourceURL();
    resurl.setCacheability(PAGE);
    writer.write("<script>\n");
    writer.write("(function () {\n");
    writer.write("   var xhr = new XMLHttpRequest();\n");
    writer.write("   xhr.onreadystatechange=function() {\n");
    writer.write("      if (xhr.readyState==4 && xhr.status==200) {\n");
    writer.write(
        "         document.getElementById(\"DispatcherTests_SPEC2_19_ForwardServletResource\").innerHTML=xhr.responseText;\n");
    writer.write("      }\n");
    writer.write("   };\n");
    writer.write("   xhr.open(\"GET\",\"" + resurl.toString() + "\",true);\n");
    writer.write("   xhr.send();\n");
    writer.write("})();\n");
    writer.write("</script>\n");
  }
  public final Response executeCommand(
      Object inputPar,
      UserSessionParameters userSessionPars,
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession userSession,
      ServletContext context) {
    GridParams gridParams = (GridParams) inputPar;
    try {
      String companyCode =
          (String) gridParams.getOtherGridParams().get(ApplicationConsts.COMPANY_CODE_SYS01);
      BigDecimal progressiveHie02 =
          (BigDecimal) gridParams.getOtherGridParams().get(ApplicationConsts.PROGRESSIVE_HIE02);

      ItemFields bean = (ItemFields) JAIOBeanFactory.getInstance().getBean(ItemFields.class);
      Response answer =
          bean.loadItemFields(
              companyCode,
              progressiveHie02,
              ((JAIOUserSessionParameters) userSessionPars).getServerLanguageId(),
              userSessionPars.getUsername());

      return answer;
    } catch (Throwable ex) {
      Logger.error(
          userSessionPars.getUsername(),
          this.getClass().getName(),
          "executeCommand",
          "Error while processing request",
          ex);
      return new ErrorResponse(ex.getMessage());
    }
  }
Example #10
0
 protected void logParams() {
   Enumeration en = req.getParameterNames();
   while (en.hasMoreElements()) {
     String name = (String) en.nextElement();
     String vals[];
     String dispval;
     if (StringUtil.indexOfIgnoreCase(name, "passw") >= 0) {
       dispval = req.getParameter(name).length() == 0 ? "" : "********";
     } else if (log.isDebug2() && (vals = req.getParameterValues(name)).length > 1) {
       dispval = StringUtil.separatedString(vals, ", ");
     } else {
       dispval = req.getParameter(name);
     }
     log.debug(name + " = " + dispval);
   }
 }
Example #11
0
public class IdlePointCron extends HttpServlet {
  /** */
  private static final long serialVersionUID = 1L;

  private static final Logger log = Logger.getLogger(IdlePointCron.class.getName());

  @Override
  @SuppressWarnings(Const.WARNING_UNCHECKED)
  public void doGet(final HttpServletRequest req, final HttpServletResponse resp)
      throws IOException {
    // PrintWriter out;
    // out = resp.getWriter();
    try {
      processGet();
    } catch (NimbitsException e) {
      LogHelper.logException(IdlePointCron.class, e);
    }
  }

  protected static int processGet() throws NimbitsException {
    final List<Entity> points = EntityServiceFactory.getInstance().getIdleEntities();
    log.info("Processing " + points.size() + " potentially idle points");
    for (final Entity p : points) {
      try {
        checkIdle((Point) p);
      } catch (NimbitsException e) {

        LogHelper.logException(IdlePointCron.class, e);
      }
    }
    return points.size();
  }

  protected static boolean checkIdle(final Point p) throws NimbitsException {
    final Calendar c = Calendar.getInstance();
    c.add(Calendar.SECOND, p.getIdleSeconds() * -1);
    boolean retVal = false;
    final List<Entity> result =
        EntityServiceFactory.getInstance()
            .getEntityByKey(
                UserServiceFactory.getServerInstance().getAdmin(), p.getOwner(), EntityType.user);
    if (!result.isEmpty()) {
      final User u = (User) result.get(0);
      final List<Value> v = ValueServiceFactory.getInstance().getCurrentValue(p);
      if (p.getIdleSeconds() > 0
          && !v.isEmpty()
          && v.get(0).getTimestamp().getTime() <= c.getTimeInMillis()
          && !p.getIdleAlarmSent()) {
        p.setIdleAlarmSent(true);
        EntityServiceFactory.getInstance().addUpdateEntity(u, p);
        // PointServiceFactory.getInstance().updatePoint(u, p);
        final Value va = ValueFactory.createValueModel(v.get(0), AlertType.IdleAlert);
        SubscriptionServiceFactory.getInstance().processSubscriptions(u, p, va);
        retVal = true;
      }
    }
    return retVal;
  }
}
  @Override
  public boolean login(boolean isFail) {
    try {
      WebApp webApp = getWebApp();

      if (webApp == null) {
        if (log.isLoggable(Level.FINE)) log.finer("authentication failed, no web-app found");

        getResponse().sendError(HttpServletResponse.SC_FORBIDDEN);

        return false;
      }

      // If the authenticator can find the user, return it.
      Login login = webApp.getLogin();

      if (login != null) {
        Principal user = login.login(this, getResponse(), isFail);

        return user != null;
        /*
        if (user == null)
          return false;

        setAttribute(AbstractLogin.LOGIN_NAME, user);

        return true;
        */
      } else if (isFail) {
        if (log.isLoggable(Level.FINE))
          log.finer("authentication failed, no login module found for " + webApp);

        getResponse().sendError(HttpServletResponse.SC_FORBIDDEN);

        return false;
      } else {
        // if a non-failure, then missing login is fine

        return false;
      }
    } catch (IOException e) {
      log.log(Level.FINE, e.toString(), e);

      return false;
    }
  }
Example #13
0
  private void logMessages(FacesContext context) {
    UIViewRoot root = context.getViewRoot();
    String viewId = "";

    if (root != null) viewId = root.getViewId();

    Iterator<FacesMessage> iter = context.getMessages();

    while (iter != null && iter.hasNext()) {
      FacesMessage msg = iter.next();

      if (log.isLoggable(Level.FINE)) {
        if (msg.getDetail() != null)
          log.fine(
              viewId + " [ " + msg.getSeverity() + "] " + msg.getSummary() + " " + msg.getDetail());
        else log.fine(viewId + " [ " + msg.getSeverity() + "] " + msg.getSummary());
      }
    }
  }
  @Override
  public void serveResource(ResourceRequest portletReq, ResourceResponse portletResp)
      throws PortletException, IOException {
    LOGGER.entering(LOG_CLASS, "main portlet serveResource entry");

    long tid = Thread.currentThread().getId();
    portletReq.setAttribute(THREADID_ATTR, tid);

    PrintWriter writer = portletResp.getWriter();
  }
  @Override
  public void processAction(ActionRequest portletReq, ActionResponse portletResp)
      throws PortletException, IOException {
    LOGGER.entering(LOG_CLASS, "main portlet processAction entry");

    portletResp.setRenderParameters(portletReq.getParameterMap());
    long tid = Thread.currentThread().getId();
    portletReq.setAttribute(THREADID_ATTR, tid);

    StringWriter writer = new StringWriter();
  }
Example #16
0
  protected static void recordToErrorCounter(String cmd) {

    String today = DateUtil.format(new Date(), "yyyyMMdd");
    try {

      RedisUtil.incr(ERROR_COUNT_KEY + today);

    } catch (Exception e) {

      logger.warn("记录api返回错误请求的次数失败, today: {}", today, e);
    }

    try {

      RedisUtil.incr(ERROR_COUNT_KEY + today + ":cmd:" + cmd);

    } catch (Exception e) {

      logger.warn("记录cmd: {}, today: {} 返回错误请求的次数失败", cmd, today, e);
    }
  }
  /* good2() reverses the bodies in the if statement */
  private void good2(HttpServletRequest request, HttpServletResponse response) throws Throwable {
    if (IO.static_returns_t()) {
      Logger tcLog = Logger.getLogger("cwe_testcases_logger");
      if (request.getParameter("username") == null) {
        return;
      }
      String username = request.getParameter("username");
      if (username.matches("[a-zA-Z0-9]*")) {
        HttpSession session = request.getSession(true);
        /* FIX: logged message does not contain session id */
        tcLog.log(Level.FINEST, "Username: "******" Session ID:" + session.getId());
      } else {
        response.getWriter().println("Invalid characters");
      }
    } else {
      /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */

      Logger tcLog = Logger.getLogger("cwe_testcases_logger");
      if (request.getParameter("username") == null) {
        return;
      }

      String username = request.getParameter("username");

      if (username.matches("[a-zA-Z0-9]*")) {
        HttpSession session = request.getSession(true);
        /* FLAW: leak session ID to debug log */
        tcLog.log(Level.FINEST, "Username: "******" Session ID:" + session.getId());
      } else {
        response.getWriter().println("Invalid characters");
      }
    }
  }
Example #18
0
  protected void service(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String action = request.getParameter("action");
    String name = request.getParameter("name");

    String redirect = "/user.jsp?name=" + name;
    Client client = ClientRepository.getInstance().getClient(name);

    if ("kick".equals(action)) {
      logger.info(
          client.getUser().getName()
              + " ("
              + client.getInetAddress()
              + ") has been kicked by "
              + request.getRemoteUser()
              + " ("
              + request.getRemoteHost()
              + ")");
    } else if ("ban".equals(action)) {
      Banlist banlist = Banlist.getInstance();
      banlist.ban(client.getInetAddress().getHostAddress());

      logger.info(
          client.getUser().getName()
              + " ("
              + client.getInetAddress()
              + ") has been banned by "
              + request.getRemoteUser()
              + " ("
              + request.getRemoteHost()
              + ")");

      // save the server configuration
      Server.getInstance().getConfig().save();
    }

    client.disconnect();

    response.sendRedirect("/channel.jsp?name=" + client.getChannel().getConfig().getName());
  }
Example #19
0
  protected static int processGet() throws NimbitsException {
    final List<Entity> points = EntityServiceFactory.getInstance().getIdleEntities();
    log.info("Processing " + points.size() + " potentially idle points");
    for (final Entity p : points) {
      try {
        checkIdle((Point) p);
      } catch (NimbitsException e) {

        LogHelper.logException(IdlePointCron.class, e);
      }
    }
    return points.size();
  }
Example #20
0
 String getLocalIPAddr() {
   if (localAddr == null) {
     try {
       IPAddr localHost = IPAddr.getLocalHost();
       localAddr = localHost.getHostAddress();
     } catch (UnknownHostException e) {
       // shouldn't happen
       log.error("LockssServlet: getLocalHost: " + e.toString());
       return "???";
     }
   }
   return localAddr;
 }
Example #21
0
 public MultiPartRequest getMultiPartRequest(int maxLen)
     throws FormDataTooLongException, IOException {
   if (req.getContentType() == null || !req.getContentType().startsWith("multipart/form-data")) {
     return null;
   }
   if (req.getContentLength() > maxLen) {
     throw new FormDataTooLongException(req.getContentLength() + " bytes, " + maxLen + " allowed");
   }
   MultiPartRequest multi = new MultiPartRequest(req);
   if (log.isDebug2()) {
     String[] parts = multi.getPartNames();
     log.debug3("Multipart request, " + parts.length + " parts");
     if (log.isDebug3()) {
       for (int p = 0; p < parts.length; p++) {
         String name = parts[p];
         String cont = multi.getString(parts[p]);
         log.debug3(name + ": " + cont);
       }
     }
   }
   multiReq = multi;
   return multi;
 }
Example #22
0
 private static synchronized String getJavascript() {
   if (jstext == null) {
     InputStream istr = null;
     try {
       ClassLoader loader = Thread.currentThread().getContextClassLoader();
       istr = loader.getResourceAsStream(JAVASCRIPT_RESOURCE);
       jstext = StringUtil.fromInputStream(istr);
       istr.close();
     } catch (Exception e) {
       log.error("Can't load javascript", e);
     } finally {
       IOUtil.safeClose(istr);
     }
   }
   return jstext;
 }
Example #23
0
  /** Download resource to the given file */
  private boolean download(URL target, File file) {

    _log.addDebug("JarDiffHandler:  Doing download");

    boolean ret = true;
    boolean delete = false;
    // use bufferedstream for better performance
    BufferedInputStream in = null;
    BufferedOutputStream out = null;
    try {
      in = new BufferedInputStream(target.openStream());
      out = new BufferedOutputStream(new FileOutputStream(file));
      int read = 0;
      int totalRead = 0;
      byte[] buf = new byte[BUF_SIZE];
      while ((read = in.read(buf)) != -1) {
        out.write(buf, 0, read);
        totalRead += read;
      }

      _log.addDebug("total read: " + totalRead);
      _log.addDebug("Wrote URL " + target.toString() + " to file " + file);

    } catch (IOException ioe) {

      _log.addDebug("Got exception while downloading resource: " + ioe);

      ret = false;

      if (file != null) delete = true;

    } finally {

      try {
        in.close();
        in = null;
      } catch (IOException ioe) {
        _log.addDebug("Got exception while downloading resource: " + ioe);
      }

      try {
        out.close();
        out = null;
      } catch (IOException ioe) {
        _log.addDebug("Got exception while downloading resource: " + ioe);
      }

      if (delete) {
        file.delete();
      }
    }
    return ret;
  }
  @Override
  public void serveResource(ResourceRequest portletReq, ResourceResponse portletResp)
      throws PortletException, IOException {
    LOGGER.entering(LOG_CLASS, "main portlet serveResource entry");

    long tid = Thread.currentThread().getId();
    portletReq.setAttribute(THREADID_ATTR, tid);

    PrintWriter writer = portletResp.getWriter();

    // Now do the actual dispatch
    String target =
        SERVLET_PREFIX
            + "DispatcherTests_SPEC2_19_ForwardServletResource_servlet"
            + SERVLET_SUFFIX
            + "?"
            + QUERY_STRING;
    PortletRequestDispatcher rd = portletConfig.getPortletContext().getRequestDispatcher(target);
    rd.forward(portletReq, portletResp);
  }
  @Override
  public void processAction(ActionRequest portletReq, ActionResponse portletResp)
      throws PortletException, IOException {
    LOGGER.entering(LOG_CLASS, "main portlet processAction entry");

    portletResp.setRenderParameters(portletReq.getParameterMap());
    long tid = Thread.currentThread().getId();
    portletReq.setAttribute(THREADID_ATTR, tid);

    StringWriter writer = new StringWriter();

    // Now do the actual dispatch
    String target =
        JSP_PREFIX
            + "DispatcherReqRespTests3_SPEC2_19_IncludeJSPActionResponse"
            + JSP_SUFFIX
            + "?"
            + QUERY_STRING;
    PortletRequestDispatcher rd = portletConfig.getPortletContext().getRequestDispatcher(target);
    rd.include(portletReq, portletResp);
  }
Example #26
0
  public static void handleException(RestRequest request, RestResponse response, Throwable ex) {

    Throwable rootCause = ExceptionUtils.getRootCause(ex);
    rootCause = rootCause == null ? ex : rootCause;

    logger.error("捕获到Rest异常:request={}", request, rootCause);
    RestError restError = new RestError();
    restError.setErrorCode(2);

    if (ex instanceof RestServiceException) {

      RestServiceException rse = (RestServiceException) ex;

      if (rse.getErrorCode() != 0) {

        restError.setErrorCode(rse.getErrorCode());
      }

      restError.setErrorInfo(rse.getMessage());

    } else {

      restError.setErrorInfo(RestApiConstants.DEFAULT_ERROR_INFO);

      if (request.isDebug()) {

        String stackTrace = ExceptionUtils.getStackTrace(rootCause);
        // 截取有用的部分
        stackTrace = StringUtils.substringBefore(stackTrace, RestApiConstants.STACK_TRACE_BEFORE);
        response.setDebugInfo(stackTrace);
      }

      // 统计响应结果
      recordToErrorCounter(request.getCmd());
    }

    response.setStatusCode(500);
    response.setError(restError);
    response.setResponseTime(new Date());
  }
  public final Response executeCommand(
      Object inputPar,
      UserSessionParameters userSessionPars,
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession userSession,
      ServletContext context) {
    try {
      DetailSaleDocRowVO rowVO = (DetailSaleDocRowVO) inputPar;
      VariantDescriptionsVO vo =
          (VariantDescriptionsVO)
              ((JAIOUserSessionParameters) userSessionPars)
                  .getVariantDescriptionsVO()
                  .get(rowVO.getCompanyCodeSys01DOC02());
      InsertSaleItem bean =
          (InsertSaleItem) JAIOBeanFactory.getInstance().getBean(InsertSaleItem.class);
      Response answer =
          bean.insertSaleItem(
              vo.getVariant1Descriptions(),
              vo.getVariant2Descriptions(),
              vo.getVariant3Descriptions(),
              vo.getVariant4Descriptions(),
              vo.getVariant5Descriptions(),
              rowVO,
              ((JAIOUserSessionParameters) userSessionPars).getServerLanguageId(),
              userSessionPars.getUsername());

      return answer;
    } catch (Throwable ex) {
      Logger.error(
          userSessionPars.getUsername(),
          this.getClass().getName(),
          "executeCommand",
          "Error while processing request",
          ex);
      return new ErrorResponse(ex.getMessage());
    }
  }
 public Logger getLogger() {
   if (logger == null) {
     logger = Logger.getLogger("jmaki.services.xhp.Log");
   }
   return logger;
 }
public final class abstractItemTreeNodeChip_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  Logger log = Logger.getLogger(this.getClass().getName());
  static final String SERVLETPATH = "";

  final boolean DEBUG_COMMENTS = ConfigConstants.getInstance().DEBUG_SHOWJSPCOMMENTS;

  private String getRequestURL() {
    return SERVLETPATH + "?" + MasterServlet.WINDOW_ID + "=" + Frame.getCurrent().getID();
  }

  private String getRequestURL(String frameName) {
    return SERVLETPATH
        + "?"
        + MasterServlet.WINDOW_ID
        + "=frame"
        + DisplayState.DELIMITER
        + frameName;
  }

  private String getWindowRequestURL(String windowName) {
    return SERVLETPATH + "?" + MasterServlet.WINDOW_ID + "=" + windowName;
  }

  private String localized(String strKey) {
    return DisplayState.getCurrent().getLocalizedString(strKey);
  }

  /**
   * If the appropriate config property is true (hmc.escape.html), all html content in the given
   * string will be escaped.
   */
  private String escapeHTML(String text) {
    if (ConfigConstants.getInstance().HTML_ESCAPE) {
      return Utilities.escapeHTML(text);
    } else {
      return text;
    }
  }

  private String getExternalLink(final String url, final String label, final String css) {
    StringBuffer link = new StringBuffer();
    link.append("<a href=\"" + url + "\" ");
    if (css != null) {
      link.append("class=\"" + css + "\" ");
    }
    link.append(">");
    link.append(label);
    link.append("</a>");
    return link.toString();
  }

  private String getExternalLink(final String url, final String label) {
    return getExternalLink(url, label, null);
  }

  private String getLink(
      final String event,
      final String label,
      final String css,
      String defaultValue,
      String selectedValue,
      String tooltip) {
    String status = Utilities.escapeHTML(Utilities.filterOutHTMLTags(tooltip));

    StringBuffer link = new StringBuffer();
    defaultValue = defaultValue == null ? AbstractChip.FALSE : defaultValue;
    selectedValue = selectedValue == null ? AbstractChip.TRUE : selectedValue;
    link.append("<input type=\"hidden\" name=\"" + event + "\" value=\"" + defaultValue + "\" />");
    link.append(
        "<a href=\"#\" onMouseover=\"window.status='"
            + status
            + "'; return true;\" onMouseout=\"window.status=''; return true;\" ");
    if (css != null) {
      link.append("class=\"" + css + "\" ");
    }
    link.append("hidefocus=\"true\" ");
    link.append(
        "onclick=\"document.editorForm.elements['"
            + event
            + "'].value='"
            + selectedValue
            + "';setScrollAndSubmit();return false;\">");
    link.append(label);
    link.append("</a>");
    return link.toString();
  }

  private String getLink(
      final String event,
      final String label,
      final String css,
      String defaultValue,
      String selectedValue) {
    return getLink(event, label, css, defaultValue, selectedValue, label);
  }

  private String getLink(final String url, final String label, final String css) {
    return getLink(url, label, css, null, null);
  }

  private String getLink(final String url, final String label) {
    return getLink(url, label, null);
  }

  private String getMainToolbarButton(
      final String event,
      final String label,
      final String image,
      String javascript,
      final boolean showLabel,
      final boolean isDropDown,
      final boolean isEnabled) {
    return getMainToolbarButton(
        event, label, label, image, javascript, showLabel, isDropDown, isEnabled);
  }

  private String getMainToolbarButton(
      final String event,
      final String label,
      final String tooltip,
      final String image,
      String javascript,
      final boolean showLabel,
      final boolean isDropDown,
      final boolean isEnabled) {
    if ((javascript == null) || javascript.equals("")) {
      javascript = "true";
    }

    final String imageID = event + "_img";
    final String color = isEnabled ? "#333333" : "#999999";

    StringBuffer link = new StringBuffer();

    if (isEnabled) {
      link.append(
          "<input type=\"hidden\" name=\"" + event + "\" value=\"" + AbstractChip.FALSE + "\" />");
      link.append(
          "<a href=\"#\" hidefocus=\"true\" style=\"text-decoration:none; \" alt=\""
              + tooltip
              + "\" ");
      link.append(
          "onMouseover=\"window.status='"
              + tooltip
              + "'; "
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/header_background_hover_main_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/header_background_hover_main_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/header_background_hover_main_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onMouseout=\"window.status='';"
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/header_background_main_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/header_background_main_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/header_background_main_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onFocus=\"window.status='"
              + tooltip
              + "'; "
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/header_background_hover_main_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/header_background_hover_main_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/header_background_hover_main_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onBlur=\"window.status='';"
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/header_background_main_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/header_background_main_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/header_background_main_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onclick=\"document.editorForm.elements['"
              + event
              + "'].value = "
              + javascript
              + "; setScrollAndSubmit(); return false;\">");
    }

    link.append(
        "<table title=\""
            + tooltip
            + "\" style=\"vertical-align:middle; width:100%; height:23px;\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">");
    link.append("<tr>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_left\" style=\"width:3px;\" background=\"images/icons/header_background_main_l.gif\">&nbsp;</td>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_middle\" style=\"white-space:nowrap;vertical-align:middle;text-align:center;\" background=\"images/icons/header_background_main_m.gif\">");
    link.append(
        "<img id=\"" + imageID + "\" style=\"vertical-align:middle;\" src=\"" + image + "\">");
    if (showLabel) {
      link.append(
          "<span style=\"padding-left:5px; "
              + (!isDropDown ? "padding-right:5px; " : "")
              + "color:"
              + color
              + "\">"
              + label
              + "</span>");
    }

    if (isDropDown) {
      link.append(
          "<span style=\"padding-left:3px; padding-right:5px;\"><img style=\"vertical-align:middle;\" src=\"images/icons/header_downarrow_main"
              + (isEnabled ? "" : "_inactive")
              + ".gif\"></span>");
    }
    link.append("</td>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_right\" style=\"width:3px;\" background=\"images/icons/header_background_main_r.gif\">&nbsp;</td>");
    link.append("</tr>");
    link.append("</table>");

    if (isEnabled) {
      link.append("</a>");
    }

    return link.toString();
  }

  private String getBlueToolbarButton(
      final String event,
      final String label,
      final String image,
      String javascript,
      boolean showLabel,
      boolean isEnabled) {
    return getBlueToolbarButton(event, label, label, image, javascript, showLabel, isEnabled);
  }

  private String getBlueToolbarButton(
      final String event,
      final String label,
      final String tooltip,
      final String image,
      String javascript,
      boolean showLabel,
      boolean isEnabled) {
    if ((javascript == null) || javascript.equals("")) {
      javascript = "true";
    }

    final String imageID = event + "_img";

    StringBuffer link = new StringBuffer();
    final String color = isEnabled ? "#ffffff" : "#aaaaff";

    if (isEnabled) {
      link.append(
          "<input type=\"hidden\" name=\"" + event + "\" value=\"" + AbstractChip.FALSE + "\" />");
      link.append(
          "<a href=\"#\" hidefocus=\"true\" style=\"text-decoration:none; \" alt=\""
              + tooltip
              + "\" ");
      link.append(
          "onMouseover=\"window.status='"
              + tooltip
              + "'; "
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/header_background_hover_blue_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/header_background_hover_blue_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/header_background_hover_blue_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onMouseout=\"window.status='';"
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/header_background_blue_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/header_background_blue_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/header_background_blue_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onFocus=\"window.status='"
              + tooltip
              + "'; "
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/header_background_hover_blue_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/header_background_hover_blue_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/header_background_hover_blue_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onBlur=\"window.status='';"
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/header_background_blue_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/header_background_blue_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/header_background_blue_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onclick=\"document.editorForm.elements['"
              + event
              + "'].value = "
              + javascript
              + "; setScrollAndSubmit(); return false;\">");
    }

    link.append(
        "<table title=\""
            + tooltip
            + "\" style=\"vertical-align:middle; width:100%; height:23px;\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">");
    link.append("<tr>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_left\" style=\"width:3px;\" background=\"images/icons/header_background_blue_l.gif\">&nbsp;</td>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_middle\" style=\"white-space:nowrap;vertical-align:middle;text-align:center;\" background=\"images/icons/header_background_blue_m.gif\">");

    link.append(
        "<img id=\"" + imageID + "\" style=\"vertical-align:middle\" src=\"" + image + "\">");
    if (showLabel) {
      link.append(
          "<span style=\"padding-left:5px; padding-right:5px; color:"
              + color
              + "\">"
              + label
              + "</span>");
    }

    link.append("</td>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_right\" style=\"width:3px;\" background=\"images/icons/header_background_blue_r.gif\">&nbsp;</td>");
    link.append("</tr>");
    link.append("</table>");

    if (isEnabled) {
      link.append("</a>");
    }

    return link.toString();
  }

  private String getGreyToolbarButton(
      final String event,
      final String label,
      final String image,
      String javascript,
      boolean showLabel,
      boolean isEnabled) {
    return getGreyToolbarButton(event, label, label, image, javascript, showLabel, isEnabled);
  }

  private String getGreyToolbarButton(
      final String event,
      final String label,
      final String tooltip,
      final String image,
      String javascript,
      boolean showLabel,
      boolean isEnabled) {
    if ((javascript == null) || javascript.equals("")) {
      javascript = "true";
    }

    final String imageID = event + "_img";

    StringBuffer link = new StringBuffer();
    final String color = isEnabled ? "#ffffff" : "#D8DCE3";

    if (isEnabled) {
      link.append(
          "<input type=\"hidden\" name=\"" + event + "\" value=\"" + AbstractChip.FALSE + "\" />");
      link.append(
          "<a href=\"#\" hidefocus=\"true\" style=\"text-decoration:none; \" alt=\""
              + tooltip
              + "\" ");
      link.append(
          "onMouseover=\"window.status='"
              + tooltip
              + "'; "
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/header_background_hover_grey_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/header_background_hover_grey_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/header_background_hover_grey_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onMouseout=\"window.status='';"
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/header_background_grey_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/header_background_grey_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/header_background_grey_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onFocus=\"window.status='"
              + tooltip
              + "'; "
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/header_background_hover_grey_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/header_background_hover_grey_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/header_background_hover_grey_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onBlur=\"window.status='';"
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/header_background_grey_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/header_background_grey_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/header_background_grey_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onclick=\"document.editorForm.elements['"
              + event
              + "'].value = "
              + javascript
              + "; setScrollAndSubmit(); return false;\">");
    }

    link.append(
        "<table title=\""
            + tooltip
            + "\" style=\"vertical-align:middle; width:100%; height:23px;\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">");
    link.append("<tr>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_left\" style=\"width:3px;\" background=\"images/icons/header_background_grey_l.gif\">&nbsp;</td>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_middle\" style=\"white-space:nowrap;vertical-align:middle;text-align:center;\" background=\"images/icons/header_background_grey_m.gif\">");

    link.append(
        "<img id=\"" + imageID + "\" style=\"vertical-align:middle\" src=\"" + image + "\">");
    if (showLabel) {
      link.append("<span style=\"padding-left:5px; color:" + color + "\">" + label + "</span>");
    }

    link.append("</td>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_right\" style=\"width:3px;\" background=\"images/icons/header_background_grey_r.gif\">&nbsp;</td>");
    link.append("</tr>");
    link.append("</table>");

    if (isEnabled) {
      link.append("</a>");
    }

    return link.toString();
  }

  private String getIconButton(
      final String event,
      final String label,
      final String image,
      String javascript,
      boolean showLabel,
      boolean isEnabled) {
    String status = Utilities.escapeHTML(Utilities.filterOutHTMLTags(label));

    if ((javascript == null) || javascript.equals("")) {
      javascript = "true";
    }

    final String imageID = event + "_img";

    StringBuffer link = new StringBuffer();
    final String color = isEnabled ? "#ffffff" : "#D8DCE3";

    if (isEnabled) {
      link.append(
          "<input type=\"hidden\" name=\"" + event + "\" value=\"" + AbstractChip.FALSE + "\" />");
      link.append(
          "<a href=\"#\" hidefocus=\"true\" style=\"text-decoration:none; \" alt=\""
              + status
              + "\" ");
      link.append(
          "onMouseover=\"window.status='"
              + status
              + "'; "
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/icon_button_background_hover_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/icon_button_background_hover_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/icon_button_background_hover_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onMouseout=\"window.status='';"
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/icon_button_background_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/icon_button_background_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/icon_button_background_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onFocus=\"window.status='"
              + status
              + "'; "
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/icon_button_background_hover_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/icon_button_background_hover__m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/icon_button_background_hover__r.gif)'; "
              + " return true;\" ");
      link.append(
          "onBlur=\"window.status='';"
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/icon_button_background_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/icon_button_background_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/icon_button_background_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onclick=\"document.editorForm.elements['"
              + event
              + "'].value = "
              + javascript
              + "; setScrollAndSubmit(); return false;\">");
    }

    link.append(
        "<table title=\""
            + status
            + "\" style=\"vertical-align:middle; width:100%; height:23px; padding:0px;\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">");
    link.append("<tr>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_left\" style=\"width:3px;font-size:1pt;padding:0px;\" background=\"images/icons/icon_button_background_l.gif\"><div style=\"width:3px;\"></div></td>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_middle\" style=\"white-space:nowrap;vertical-align:middle;text-align:center;padding:0px;\" background=\"images/icons/icon_button_background_m.gif\">");

    link.append(
        "<img id=\"" + imageID + "\" style=\"vertical-align:middle\" src=\"" + image + "\">");
    if (showLabel) {
      link.append("<span style=\"padding-left:5px; color:" + color + "\">" + label + "</span>");
    }

    link.append("</td>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_right\" style=\"width:3px;font-size:1pt;padding:0px;\" background=\"images/icons/icon_button_background_r.gif\"><div style=\"width:3px;\"></div></td>");
    link.append("</tr>");
    link.append("</table>");

    if (isEnabled) {
      link.append("</a>");
    }

    return link.toString();
  }

  private String getFooterButton(
      final String event,
      final String label,
      final String image,
      String javascript,
      boolean showLabel,
      boolean isEnabled) {
    return getFooterButton(event, label, label, image, javascript, showLabel, isEnabled);
  }

  private String getFooterButton(
      final String event,
      final String label,
      final String tooltip,
      final String image,
      String javascript,
      boolean showLabel,
      boolean isEnabled) {
    if ((javascript == null) || javascript.equals("")) {
      javascript = "true";
    }

    final String imageID = event + "_img";

    StringBuffer link = new StringBuffer();
    final String color = isEnabled ? "#333333" : "#999999";

    if (isEnabled) {
      link.append(
          "<input type=\"hidden\" name=\"" + event + "\" value=\"" + AbstractChip.FALSE + "\" />");
      link.append(
          "<a href=\"#\" hidefocus=\"true\" style=\"text-decoration:none; \" alt=\""
              + tooltip
              + "\" ");
      link.append(
          "onMouseover=\"window.status='"
              + tooltip
              + "'; "
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/footer_background_hover_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/footer_background_hover_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/footer_background_hover_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onMouseout=\"window.status='';"
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/footer_background_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/footer_background_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/footer_background_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onFocus=\"window.status='"
              + tooltip
              + "'; "
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/footer_background_hover_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/footer_background_hover_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/footer_background_hover_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onBlur=\"window.status='';"
              + " document.getElementById('"
              + imageID
              + "_bg_left').style.backgroundImage = 'url(images/icons/footer_background_l.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_middle').style.backgroundImage = 'url(images/icons/footer_background_m.gif)'; "
              + " document.getElementById('"
              + imageID
              + "_bg_right').style.backgroundImage = 'url(images/icons/footer_background_r.gif)'; "
              + " return true;\" ");
      link.append(
          "onclick=\"document.editorForm.elements['"
              + event
              + "'].value = "
              + javascript
              + "; setScrollAndSubmit(); return false;\">");
    }

    link.append(
        "<table title=\""
            + tooltip
            + "\" style=\"vertical-align:middle; width:100%; height:23px;\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">");
    link.append("<tr>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_left\" style=\"width:3px;\" background=\"images/icons/footer_background_l.gif\">&nbsp;</td>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_middle\" style=\"white-space:nowrap;vertical-align:middle;text-align:center;\" background=\"images/icons/footer_background_m.gif\">");

    link.append(
        "<img id=\"" + imageID + "\" style=\"vertical-align:middle\" src=\"" + image + "\">");
    if (showLabel) {
      link.append("<span style=\"padding-left:5px; color:" + color + "\">" + label + "</span>");
    }

    link.append("</td>");
    link.append(
        "<td id=\""
            + imageID
            + "_bg_right\" style=\"width:3px;\" background=\"images/icons/footer_background_r.gif\">&nbsp;</td>");
    link.append("</tr>");
    link.append("</table>");

    if (isEnabled) {
      link.append("</a>");
    }

    return link.toString();
  }

  private String getSimpleImageConfirmLink(
      final String event,
      final String label,
      final String image,
      String imageOver,
      String javascript) {
    String status = Utilities.escapeHTML(Utilities.filterOutHTMLTags(label));

    if ((imageOver == null) || imageOver.equals("")) {
      imageOver = image;
    }

    if ((javascript == null) || javascript.equals("")) {
      javascript = "true";
    }

    final String imageID = event + "_img";

    StringBuffer link = new StringBuffer();

    link.append("<input type=\"hidden\" name=\"")
        .append(event)
        .append("\" value=\"")
        .append(AbstractChip.FALSE)
        .append("\" />");
    link.append("<a href=\"#\" hidefocus=\"true\" style=\"text-decoration:none; \" alt=\"")
        .append(status)
        .append("\" title=\"")
        .append(status)
        .append("\"");
    link.append("onMouseover=\"window.status='")
        .append(status)
        .append("'; swapImage('")
        .append(imageID)
        .append("', '")
        .append(imageOver)
        .append("'); return true;\" ");
    link.append("onMouseout=\"window.status=''; swapImage('")
        .append(imageID)
        .append("', '")
        .append(image)
        .append("'); return true;\" ");
    link.append("onFocus=\"swapImage('")
        .append(imageID)
        .append("', '")
        .append(imageOver)
        .append("'); return true;\" ");
    link.append("onBlur=\"swapImage('")
        .append(imageID)
        .append("', '")
        .append(image)
        .append("'); return true;\" ");
    link.append("onclick=\"document.editorForm.elements['")
        .append(event)
        .append("'].value = ")
        .append(javascript)
        .append("; setScrollAndSubmit(); return false;\">");
    link.append("<img id=\"")
        .append(imageID)
        .append("\" src=\"")
        .append(image)
        .append("\" alt=\"")
        .append(status)
        .append("\">");
    link.append("</a>");

    return link.toString();
  }

  private String getSimpleImageLink(
      final String event, final String label, final String image, final String imageOver) {
    return getSimpleImageConfirmLink(event, label, image, imageOver, null);
  }

  public String getLinkedLabel(final String url, final String body) {
    if (url == null) {
      return body;
    } else {
      return "<a href=\"" + url + "\" hidefocus=\"true\">" + body + "</a>";
    }
  }

  public String getLinkedIDLabel(String id, final String url, final String body) {
    if ((id == null) || id.equals("")) {
      return getLinkedLabel(url, body);
    }

    if (url == null) {
      return body;
    } else {
      return "<a id=\"" + id + "\" href=\"" + url + "\" hidefocus=\"true\">" + body + "</a>";
    }
  }

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List _jspx_dependants;

  static {
    _jspx_dependants = new java.util.ArrayList(1);
    _jspx_dependants.add("/ext/catalog/../../head.inc");
  }

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.AnnotationProcessor _jsp_annotationprocessor;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory =
        _jspxFactory
            .getJspApplicationContext(getServletConfig().getServletContext())
            .getExpressionFactory();
    _jsp_annotationprocessor =
        (org.apache.AnnotationProcessor)
            getServletConfig()
                .getServletContext()
                .getAttribute(org.apache.AnnotationProcessor.class.getName());
  }

  public void _jspDestroy() {}

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
      throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
      response.setContentType("text/html");
      pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n\r\n");

      final DisplayState theDisplayState = (DisplayState) request.getAttribute(MasterServlet.STATE);
      final Frame frame = (Frame) request.getAttribute(AbstractChip.FRAME_KEY);

      /*
       //to be definitive NOT serializable
      InputStream noser = (InputStream)session.getAttribute( "NOT_SERIALIZABLE");
      if( noser==null )
      {
      	session.setAttribute( "NOT_SERIALIZABLE", new ByteArrayInputStream( new byte[0] ));
      }
      */

      out.write('\r');
      out.write('\n');

      final AbstractItemTreeNodeChip theChip =
          (AbstractItemTreeNodeChip) request.getAttribute(AbstractChip.CHIP_KEY);

      out.write("\r\n<input type=\"hidden\" name=\"");
      out.print(theChip.getEventID(AbstractTreeNodeChip.EDIT));
      out.write("\" value=\"");
      out.print(AbstractChip.FALSE);
      out.write(
          "\" />\r\n<table class=\"abstractItemTreeNodeChip\" cellspacing=\"0\" cellpadding=\"0\">\r\n\t<tr>\r\n\t\t<td class=\"aitncIcon\">\r\n\t\t\t<div onclick=\"document.editorForm.elements['");
      out.print(theChip.getEventID(AbstractTreeNodeChip.EDIT));
      out.write("'].value='");
      out.print(AbstractChip.TRUE);
      out.write("';setScrollAndSubmit();\">\r\n\t\t\t\t<img src=\"");
      out.print(theChip.getIcon());
      out.write(
          "\" border=\"0\">\r\n\t\t\t</div>\r\n\t\t</td>\r\n\t\t<td class=\"aitncName\">\r\n\t\t\t<div onclick=\"document.editorForm.elements['");
      out.print(theChip.getEventID(AbstractTreeNodeChip.EDIT));
      out.write("'].value='");
      out.print(AbstractChip.TRUE);
      out.write("';setScrollAndSubmit();\">\r\n\t\t\t\t");
      out.print(theChip.getName());
      out.write("\r\n\t\t\t</div>\r\n\t\t</td>\r\n\t</tr>\r\n\t");

      if (theChip.isExpanded()) {
        for (final Iterator it = theChip.getAllChildren().iterator(); it.hasNext(); ) {
          final AbstractTreeNodeChip child = (AbstractTreeNodeChip) it.next();

          out.write("\r\n\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t<td class=\"aitncTreeIMG\" background=\"");
          out.print(it.hasNext() ? "images/vert.gif" : "");
          out.write("\">\r\n\t\t\t\t\t\t\t");

          if (child.hasChildren()) {
            if (child.isExpanded()) {

              out.write("<input type=\"hidden\" name=\"");
              out.print(child.getEventID(AbstractTreeNodeChip.COLLAPSE));
              out.write("\" value=\"");
              out.print(AbstractChip.FALSE);
              out.write("\" /><div onclick=\"document.editorForm.elements['");
              out.print(child.getEventID(AbstractTreeNodeChip.COLLAPSE));
              out.write("'].value='");
              out.print(AbstractChip.TRUE);
              out.write("';setScrollAndSubmit();\">");

              if (it.hasNext()) {

                out.write("<img src=\"images/minus.gif\"></td>");

              } else {

                out.write("<img src=\"images/minusend.gif\"></td>");
              }

              out.write("</div>");

            } else {

              out.write("<input type=\"hidden\" name=\"");
              out.print(child.getEventID(AbstractTreeNodeChip.EXPAND));
              out.write("\" value=\"");
              out.print(AbstractChip.FALSE);
              out.write("\" /><div onclick=\"document.editorForm.elements['");
              out.print(child.getEventID(AbstractTreeNodeChip.EXPAND));
              out.write("'].value='");
              out.print(AbstractChip.TRUE);
              out.write("';setScrollAndSubmit();\">");

              if (it.hasNext()) {

                out.write("<img src=\"images/plus.gif\"></td>");

              } else {

                out.write("<img src=\"images/plusend.gif\"></td>");
              }

              out.write("</div>");
            }
          } else {
            if (it.hasNext()) {

              out.write("<img src=\"images/horiz.gif\"></td>");

            } else {

              out.write("<img src=\"images/end.gif\"></td>");
            }
          }

          out.write("\r\n\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t<td class=\"aitncContext\">");
          child.render(pageContext);
          out.write("</td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t");
        }
      }

      out.write("\r\n</table>\r\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)) {
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try {
            out.clearBuffer();
          } catch (java.io.IOException e) {
          }
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else log(t.getMessage(), t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
/** Implements the "get status table" command */
public class AddAuConfigure extends AuActivityBase {

  private static String NAME = "AddAuConfigure";
  private static Logger log = Logger.getLogger(NAME);

  public AddAuConfigure() {
    super();
  }

  /**
   * Populate the response body
   *
   * @return true on success
   */
  public boolean doRemoteSetupAndVerification() throws IOException {

    /*
     * Stop if any required parameters are missing (error)
     */
    if (!verifyMinimumParameters()) {
      throw new ResponseException("Missing required parameters");
    }
    /*
     * Initial page setup
     */
    return commandSetup();
  }

  /**
   * Populate the response body
   *
   * @return true on success
   */
  public boolean doCommand() throws IOException {
    Element infoElement;

    /*
     * Return disk space
     */
    infoElement = getXmlUtils().createElement(getResponseRoot(), AP_E_INFO);
    renderDiskXml(infoElement);

    /*
     * No further action if this isn't a create command (success)
     */
    if (!isCreateCommand()) {
      return true;
    }
    /*
     * Stop if any required parameters are missing (error)
     */
    if (!verifyTarget() || !verifyMinimumParameters() || !verifyDefiningParameters()) {
      throw new ResponseException("Missing required parameters");
    }
    /*
     * Create the AU
     */
    if (!commandSetup()) {
      return false;
    }
    return createAu();
  }

  /*
   * "Helpers"
   */

  /**
   * Did the client provide the minimal parameters required?
   *
   * @return true If so
   */
  private boolean verifyMinimumParameters() {
    int count = 0;

    if (!StringUtil.isNullString(getParameter(AP_E_PUBLICATION))) count++;
    if (!StringUtil.isNullString(getParameter(AP_E_CLASSNAME))) count++;
    if (!StringUtil.isNullString(getParameter(AP_E_PLUGIN))) count++;

    return (count > 0);
  }

  /**
   * A target system is required to create an AU - was it provided?
   *
   * @return true If at least one target was specified
   */
  private boolean verifyTarget() {
    if (!isCreateCommand()) {
      return true;
    }

    return !StringUtil.isNullString(getParameter(AP_E_TARGET));
  }

  /**
   * Are all of the "defining parameters" required to create an AU available?
   *
   * @return true If so
   */
  private boolean verifyDefiningParameters() {
    KeyedList parameters;
    int size;

    if (!isCreateCommand()) {
      return true;
    }

    parameters = ParseUtils.getDynamicFields(getXmlUtils(), getRequestDocument(), AP_MD_AUDEFINING);
    size = parameters.size();

    for (int i = 0; i < size; i++) {
      if (StringUtil.isNullString((String) parameters.getValue(i))) {
        return false;
      }
    }
    return true;
  }

  /**
   * "Create" command?
   *
   * @return true If so...
   */
  private boolean isCreateCommand() {
    return "create".equalsIgnoreCase(getParameter(AP_E_ACTION));
  }

  /** Query the daemon for information required to set up this command */
  private boolean commandSetup() {

    Configuration configuration = null;
    Collection noEditKeys = null;
    String key;
    String value;

    /*
     * Configure a well known publication?
     */
    if ((value = getParameter(AP_E_PUBLICATION)) != null) {
      PluginProxy plugin = getTitlePlugin(value);

      /*
       * Set plugin and Title configuration information
       */
      if (plugin == null) {
        String message = "Unknown Publication:" + value;

        log.warning(message);
        return error(message);
      }

      setPlugin(plugin);
      setTitleConfig(plugin.getTitleConfig(value));

      configuration = getTitleConfig().getConfig();
      noEditKeys = getNoEditKeys();

    } else {
      /*
       * Lookup by Plugin or Class name - set the plugin
       *
       * NB: As of 23-Feb-04, this is not supported from AddAuPage.java.  See
       *     AddAuWithCompleteFunctionalityPage.java for full support.
       */
      if ((value = getParameter(AP_E_PLUGIN)) != null) {
        key = RemoteApi.pluginKeyFromId(value);

      } else if ((value = getParameter(AP_E_CLASSNAME)) != null) {
        key = RemoteApi.pluginKeyFromId(value);

      } else {
        return error("Supply a Publication, Plugin, or Class name");
      }

      if (StringUtil.isNullString(key)) {
        return error("Supply a valid Publication, Plugin, or Class name");
      }

      if (!pluginLoaded(key)) {
        return error("Plugin is not loaded: " + key);
      }

      setPlugin(getPluginProxy(key));
    }

    /*
     * Finally, return an XML rendition of the Plugin and AU key set up
     */
    generateSetupXml(configuration, noEditKeys);
    return true;
  }

  /**
   * Create an Archival Unit
   *
   * @return true If successful
   */
  private boolean createAu() {

    Configuration config = getAuConfigFromForm();

    AuProxy au;
    Element element;

    try {
      au = getRemoteApi().createAndSaveAuConfiguration(getPlugin(), config);

    } catch (ArchivalUnit.ConfigurationException exception) {
      return error("Configuration failed: " + exception.getMessage());

    } catch (IOException exception) {
      return error("Unable to save configuration: " + exception.getMessage());
    }
    /*
     * Successful creation - add the AU name and ID to the response document
     */
    element = getXmlUtils().createElement(getResponseRoot(), AP_E_AU);
    XmlUtils.addText(element, au.getName());

    element = getXmlUtils().createElement(getResponseRoot(), AP_E_AUID);
    XmlUtils.addText(element, au.getAuId());

    return true;
  }
}