/**
   * Since this property depends on the user agent it is saved separately for each combination of
   * {@link org.eclipse.scout.rt.shared.ui.IUiLayer IUiLayer} and {@link
   * org.eclipse.scout.rt.shared.ui.IUiDeviceType IUiDeviceType}.
   */
  public Rectangle getFormBounds(IForm form) {
    String key = form.computeCacheBoundsKey();
    if (key == null) {
      return null;
    }

    key = getUserAgentPrefix() + FORM_BOUNDS + key;
    String value = m_env.get(key, "");
    if (StringUtility.isNullOrEmpty(value)) {
      key = getLegacyFormBoundsKey(form);
      value = m_env.get(key, "");
    }

    if (!StringUtility.isNullOrEmpty(value)) {
      try {
        StringTokenizer tok = new StringTokenizer(value, ",");
        Rectangle r =
            new Rectangle(
                new Integer(tok.nextToken()).intValue(),
                new Integer(tok.nextToken()).intValue(),
                new Integer(tok.nextToken()).intValue(),
                new Integer(tok.nextToken()).intValue());
        return r;
      } catch (Exception e) {
        LOG.warn("value=" + value, e);
      }
    }
    return null;
  }
 @Override
 protected IStatus run(IProgressMonitor monitor) {
   String pattern;
   synchronized (navigationLock) {
     if (monitor.isCanceled() || StringUtility.isNullOrEmpty(m_filterText)) {
       return Status.CANCEL_STATUS;
     }
     pattern = StringUtility.toRegExPattern(m_filterText.toLowerCase());
     pattern = pattern + ".*";
   }
   // this call must be outside lock!
   handleSearchPattern(pattern);
   return Status.OK_STATUS;
 }
Example #3
0
  @Override
  public String getText(Object element) {
    ICell cell = getCell(element);
    if (cell == null) {
      return "";
    }

    String text = cell.getText();
    if (text == null) {
      text = "";
    }
    if (HtmlTextUtility.isTextWithHtmlMarkup(text)) {
      text = m_uiList.getUiEnvironment().adaptHtmlCell(m_uiList, text);
      text = m_uiList.getUiEnvironment().convertLinksWithLocalUrlsInHtmlCell(m_uiList, text);
    } else {
      boolean multiline = false;
      if (text.indexOf("\n") >= 0) {
        multiline = isMultiline();
        if (!multiline) {
          text = StringUtility.replaceNewLines(text, " ");
        }
      }
      boolean markupEnabled =
          Boolean.TRUE.equals(getUiList().getUiField().getData(RWT.MARKUP_ENABLED));
      if (markupEnabled || multiline) {
        text = HtmlTextUtility.transformPlainTextToHtml(text);
      }
    }
    return text;
  }
 @Override
 protected void execChangedValue() throws ProcessingException {
   String s = StringUtility.emptyIfNull(getValue()).trim();
   if (s.length() > 0) {
     if (!s.endsWith("*")) {
       s = s + "*";
     }
     if (!s.startsWith("*")) {
       s = "*" + s;
     }
     m_lowercaseFilterPattern =
         Pattern.compile(
             StringUtility.toRegExPattern(s.toLowerCase(LocaleThreadLocal.get())));
     getSecondTreeField().getTree().addNodeFilter(this);
   } else {
     getSecondTreeField().getTree().removeNodeFilter(this);
   }
 }
 private static int getScopePriority(String scope) {
   int prio = IFormFieldExtension.SCOPE_DEFAULT;
   if (StringUtility.isNullOrEmpty(scope) || scope.equalsIgnoreCase("default")) {
     prio = IFormFieldExtension.SCOPE_DEFAULT;
   } else if (scope.equalsIgnoreCase("global")) {
     prio = IFormFieldExtension.SCOPE_GLOBAL;
   }
   return prio;
 }
  private String buildQueryUrl() {
    String url = getQueryCriteria();
    String assignee = StringUtility.nvl(getAssignee(), "").trim();
    String product = StringUtility.nvl(getProduct(), "").trim();

    if (assignee.length() > 0) {
      LOG.info("assignee='" + assignee + "'");
      url += "&emailtype1=substring&emailassigned_to1=1&email1=" + assignee;
    }

    if (product.length() > 0) {
      LOG.info("product='" + product + "'");
      url += "&product=" + product;
    }

    LOG.info("using query url='" + url + "'");

    return url;
  }
  public int[] getPropertyIntArray(String propName) {
    String strVal = m_env.get(propName, null);
    if (!StringUtility.hasText(strVal)) {
      return null;
    }

    String[] split = strVal.split(";");
    int[] val = new int[split.length];
    for (int i = 0; i < split.length; i++) {
      val[i] = Integer.parseInt(split[i]);
    }
    return val;
  }
  private MqttConnectOptions getConnectOptions(
      String userName,
      String password,
      Boolean clearSession,
      Integer connectionTimeout,
      String lwtTopic,
      String lwtMessage,
      Integer lwtQos,
      Boolean lwtRetained) {
    MqttConnectOptions connectOpts = new MqttConnectOptions();

    if (!StringUtility.isNullOrEmpty(userName)) {
      connectOpts.setUserName(userName);

      if (!StringUtility.isNullOrEmpty(password)) {
        connectOpts.setPassword(password.toCharArray());
      }
    }

    if (clearSession != null) {
      connectOpts.setCleanSession(clearSession);
    }

    if (connectionTimeout != null) {
      connectOpts.setConnectionTimeout(connectionTimeout);
    }

    if (!StringUtility.isNullOrEmpty(lwtTopic) && !StringUtility.isNullOrEmpty(lwtMessage)) {
      connectOpts.setWill(
          lwtTopic,
          lwtMessage.getBytes(),
          NumberUtility.nvl(lwtQos, 1),
          BooleanUtility.nvl(lwtRetained, false));
    }

    return connectOpts;
  }
  /**
   * This method parses and normalizes the Scout keystroke and sets the class' member variables.
   * Example: <code>
   * {@link KeyStrokeNormalizer} ks = new {@link KeyStrokeNormalizer}("ALT-shiFt-F11");<br>
   * ks.{@link #normalize()};<br>
   * <br>
   * ks.{@link #getNormalizedKeystroke()}; //returns 'shift-alternate-f11'<br>
   * ks.{@link #getKey()}; //returns 'f11' <br>
   * ks.{@link #hasShift()}; //returns 'true'<br>
   * ks.{@link #hasAlt()}; //returns 'true' <br>
   * ks.{@link #hasCtrl()}; //returns 'false'<br>
   * ks.{@link #isValid()}; //returns 'true' <br>
   * </code>
   * <br>
   * If the keystroke is invalid, {@link #isValid()} will return <code>false</code>, all modifiers ({@link #hasAlt()},
   * {@link #hasCtrl()}, {@link #hasShift()}) will be <code>false</code> and the
   * <code>{@link #getNormalizedKeystroke()} will return <code>null</code>
   */
  public void normalize() {
    String keyStroke = m_originalKeyStroke;
    if (StringUtility.hasText(keyStroke)) {
      keyStroke = keyStroke.toLowerCase();
      List<String> components = getComponents(keyStroke);

      performSanityChecks(keyStroke, components);
      parseModifiers(components);
      parseKey(components);

      if (!m_isValid) {
        setInvalid();
      }
    }
  }
  @Override
  public Date unmarshal(String rawValue) throws Exception {
    if (!StringUtility.hasText(rawValue)) {
      return null;
    }

    // local time of given timezone (or default timezone if not applicable)
    DatatypeFactory factory = DatatypeFactory.newInstance();
    XMLGregorianCalendar xmlCalendar = factory.newXMLGregorianCalendar(rawValue);
    GregorianCalendar calendar = xmlCalendar.toGregorianCalendar();
    long utcMillis = calendar.getTimeInMillis();

    // default time
    Calendar defaultTimezoneCalendar = Calendar.getInstance();
    defaultTimezoneCalendar.setTimeInMillis(utcMillis);
    return defaultTimezoneCalendar.getTime();
  }
  private Element getBugTableElement(String url, int timeout) throws ProcessingException {
    Document doc = null;

    if (StringUtility.isNullOrEmpty(url)) {
      throw new ProcessingException(
          "No bugzilla base query url provided, check your config.ini file");
    }

    try {
      doc = Jsoup.parse(new URL(url), timeout);
      if (doc == null)
        throw new ProcessingException("Empty document received, check your connection");
    } catch (Exception e) {
      throw new ProcessingException(
          "Exception ", "check your connection and url: '" + url + "'", e);
    }

    return doc.getElementsByClass("bz_buglist").first();
  }
  private String getUserAgentPrefix() {
    UserAgent currentUserAgent = null;
    if (m_session != null) {
      currentUserAgent = m_session.getUserAgent();
    } else {
      currentUserAgent = UserAgentUtility.getCurrentUserAgent();
    }
    if (currentUserAgent == null) {
      return "";
    }

    String uiLayer = null;
    if (!UiLayer.UNKNOWN.equals(currentUserAgent.getUiLayer())) {
      uiLayer = currentUserAgent.getUiLayer().getIdentifier();
    }
    String uiDeviceType = null;
    if (!UiDeviceType.UNKNOWN.equals(currentUserAgent.getUiDeviceType())) {
      uiDeviceType = currentUserAgent.getUiDeviceType().getIdentifier();
    }

    return StringUtility.concatenateTokens(uiLayer, ".", uiDeviceType, ".");
  }
 /**
  * Process xml tags.<br>
  * Keep content of "rec" tag.<br>
  * Remove key,text,all tags.
  */
 protected String filterSqlByRec(String sqlSelect) {
   return StringUtility.removeTagBounds(
       StringUtility.removeTags(sqlSelect, new String[] {"key", "text", "all"}), "rec");
 }
  private void doHtmlResponse(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String errorMsg = "";

    /* run garbage collection for better estimation of current memory usage */
    String doGc = req.getParameter("gc");
    if (StringUtility.hasText(doGc)) {
      System.gc();
      errorMsg = "<font color='blue'> System.gc() triggered.</font>";
    }

    List<List<String>> result = getDiagnosticItems();

    IDiagnostic[] diagnosticServices = DiagnosticFactory.getDiagnosticProviders();
    for (IDiagnostic diagnosticService : diagnosticServices) {
      if (CollectionUtility.hasElements(diagnosticService.getPossibleActions())) {
        diagnosticService.addSubmitButtonsHTML(result);
      }
    }
    DiagnosticFactory.addDiagnosticItemToList(
        result, "System.gc()", "", "<input type='checkbox' name='gc' value='yes'/>");

    String diagnosticHTML = getDiagnosticItemsHTML(result);

    String title = "unknown";
    Version version = Version.emptyVersion;
    IProduct product = Platform.getProduct();
    if (product != null) {
      title = product.getName();
      version =
          Version.parseVersion("" + product.getDefiningBundle().getHeaders().get("Bundle-Version"));
    }

    resp.setContentType("text/html");
    ServletOutputStream out = resp.getOutputStream();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>" + title + "</title>");
    out.println("<style>");
    out.println("body {font-family: sans-serif; font-size: 12; background-color : #F6F6F6;}");
    out.println("a,a:VISITED {color: #6666ff;text-decoration: none;}");
    out.println("table {font-size: 12; empty-cells: show;}");
    out.println(
        "th {text-align: left;vertical-align: top; padding-left: 2; background-color : #cccccc;}");
    out.println("td {text-align: left;vertical-align: top; padding-left: 2;}");
    out.println("p {margin-top: 4; margin-bottom: 4; padding-top: 4; padding-bottom: 4;}");
    out.println("dt {font-weight: bold;}");
    out.println("dd {margin-left: 20px; margin-bottom: 3px;}");
    out.println(".copyright {font-size: 10;}");
    out.println("</style>");
    out.println("<script type=\"text/javascript\">");
    out.println("function toggle_visibility(id) {");
    out.println("   var el = document.getElementById(id);");
    out.println("   el.style.display = (el.style.display != 'none' ? 'none' : 'block');");
    out.println("}");
    out.println("</script>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h3>" + title + " " + version + "</h3>");
    out.println(
        "<form method='POST' action='"
            + StringUtility.join("?", req.getRequestURL().toString(), req.getQueryString())
            + "'>");
    out.print(diagnosticHTML);
    out.println("<p><input type='submit' value='submit'/></p>");
    out.println("</form>");
    out.print(errorMsg);
    out.println("<p class=\"copyright\">&copy; " + OfficialVersion.COPYRIGHT + "</p>");
    out.println("</body>");
    out.println("</html>");
  }