protected void checkEmptyCollection(String line, String fileName, int lineCount) {

    // LPS-46028

    Matcher matcher = emptyCollectionPattern.matcher(line);

    if (matcher.find()) {
      String collectionType = TextFormatter.format(matcher.group(1), TextFormatter.J);

      processErrorMessage(
          fileName, "Use Collections.empty" + collectionType + "(): " + fileName + " " + lineCount);
    }
  }
Пример #2
0
  public String getId(HttpServletRequest request, String namespace) {
    if (_uniqueId) {
      return _id;
    }

    if (Validator.isNotNull(_id)) {
      _id = PortalUtil.getUniqueElementId(request, namespace, _id);
      _uniqueId = true;

      return _id;
    }

    String id = null;

    if (Validator.isNotNull(_className)) {
      String simpleClassName = _className;

      int pos = simpleClassName.lastIndexOf(StringPool.PERIOD);

      if (pos != -1) {
        simpleClassName = simpleClassName.substring(pos + 1);
      }

      String variableCasingSimpleClassName = TextFormatter.format(simpleClassName, TextFormatter.I);

      id = TextFormatter.formatPlural(variableCasingSimpleClassName);

      id = id.concat("SearchContainer");

      _id = PortalUtil.getUniqueElementId(request, namespace, id);
      _uniqueId = true;

      return _id;
    }

    id = DeterminateKeyGenerator.generate("taglib_search_container");

    _id = id.concat("SearchContainer");
    _uniqueId = true;

    return _id;
  }
 public String getVariableName(String name) {
   return TextFormatter.format(name, TextFormatter.I);
 }
  protected String[] getLanguageKeys(Matcher matcher) {
    int groupCount = matcher.groupCount();

    if (groupCount == 1) {
      String languageKey = matcher.group(1);

      if (Validator.isNotNull(languageKey)) {
        return new String[] {languageKey};
      }
    } else if (groupCount == 2) {
      String languageKey = matcher.group(2);

      languageKey = TextFormatter.format(languageKey, TextFormatter.P);

      return new String[] {languageKey};
    }

    StringBundler sb = new StringBundler();

    String match = matcher.group();

    int count = 0;

    for (int i = 0; i < match.length(); i++) {
      char c = match.charAt(i);

      switch (c) {
        case CharPool.CLOSE_PARENTHESIS:
          if (count <= 1) {
            return new String[0];
          }

          count--;

          break;

        case CharPool.OPEN_PARENTHESIS:
          count++;

          break;

        case CharPool.QUOTE:
          if (count > 1) {
            break;
          }

          while (i < match.length()) {
            i++;

            if (match.charAt(i) == CharPool.QUOTE) {
              String languageKey = sb.toString();

              if (match.startsWith("names")) {
                return StringUtil.split(languageKey);
              } else {
                return new String[] {languageKey};
              }
            }

            sb.append(match.charAt(i));
          }
      }
    }

    return new String[0];
  }
  protected String fixSessionKey(String fileName, String content, Pattern pattern) {

    Matcher matcher = pattern.matcher(content);

    if (!matcher.find()) {
      return content;
    }

    String newContent = content;

    do {
      String match = matcher.group();

      String s = null;

      if (pattern.equals(sessionKeyPattern)) {
        s = StringPool.COMMA;
      } else if (pattern.equals(taglibSessionKeyPattern)) {
        s = "key=";
      }

      int x = match.indexOf(s);

      if (x == -1) {
        continue;
      }

      x = x + s.length();

      String substring = match.substring(x).trim();

      String quote = StringPool.BLANK;

      if (substring.startsWith(StringPool.APOSTROPHE)) {
        quote = StringPool.APOSTROPHE;
      } else if (substring.startsWith(StringPool.QUOTE)) {
        quote = StringPool.QUOTE;
      } else {
        continue;
      }

      int y = match.indexOf(quote, x);
      int z = match.indexOf(quote, y + 1);

      if ((y == -1) || (z == -1)) {
        continue;
      }

      String prefix = match.substring(0, y + 1);
      String suffix = match.substring(z);
      String oldKey = match.substring(y + 1, z);

      boolean alphaNumericKey = true;

      for (char c : oldKey.toCharArray()) {
        if (!Validator.isChar(c)
            && !Validator.isDigit(c)
            && (c != CharPool.DASH)
            && (c != CharPool.UNDERLINE)) {

          alphaNumericKey = false;
        }
      }

      if (!alphaNumericKey) {
        continue;
      }

      String newKey = TextFormatter.format(oldKey, TextFormatter.O);

      newKey = TextFormatter.format(newKey, TextFormatter.M);

      if (newKey.equals(oldKey)) {
        continue;
      }

      String oldSub = prefix.concat(oldKey).concat(suffix);
      String newSub = prefix.concat(newKey).concat(suffix);

      newContent = StringUtil.replaceFirst(newContent, oldSub, newSub);
    } while (matcher.find());

    return newContent;
  }
Пример #6
0
  @Override
  protected void setAttributes(HttpServletRequest request) {
    super.setAttributes(request);

    Object bean = getBean();

    if (bean == null) {
      bean = pageContext.getAttribute("aui:model-context:bean");
    }

    Class<?> model = getModel();

    String defaultLanguageId = getDefaultLanguageId();

    if (Validator.isNull(defaultLanguageId)) {
      defaultLanguageId = (String) pageContext.getAttribute("aui:model-context:defaultLanguageId");
    }

    if (Validator.isNull(defaultLanguageId)) {
      if ((model != null) && ModelHintsUtil.hasField(model.getName(), "groupId")) {

        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

        defaultLanguageId = LocaleUtil.toLanguageId(themeDisplay.getSiteDefaultLocale());
      }
    }

    if (Validator.isNull(defaultLanguageId)) {
      Locale defaultLocale = LocaleUtil.getDefault();

      defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);
    }

    String name = getName();

    int pos = name.indexOf(StringPool.DOUBLE_DASH);

    if (pos != -1) {
      name = name.substring(pos + 2, name.length() - 2);
    }

    String field = getField();

    if (Validator.isNull(field)) {
      field = getName();
    }

    String formName = getFormName();

    if (formName == null) {
      FormTag formTag = (FormTag) findAncestorWithClass(this, FormTag.class);

      if (formTag != null) {
        formName = formTag.getName();
      }
    }

    String id = getId();
    String type = getType();

    if (Validator.isNull(id)) {
      String fieldParam = getFieldParam();

      if ((model != null) && Validator.isNull(type) && Validator.isNotNull(fieldParam)) {

        id = AUIUtil.normalizeId(fieldParam);
      } else if (!Objects.equals(type, "assetTags") && !Objects.equals(type, "radio")) {

        id = AUIUtil.normalizeId(name);
      } else {
        id = PortalUtil.getUniqueElementId(request, StringPool.BLANK, AUIUtil.normalizeId(name));
      }
    }

    String forLabel = id;

    if (Objects.equals(type, "assetTags")) {
      forLabel = forLabel.concat("assetTagNames");
    }

    String languageId = getLanguageId();

    if (Validator.isNotNull(languageId)) {
      forLabel = LocalizationUtil.getLocalizedName(forLabel, languageId);
    }

    String label = getLabel();

    if (label == null) {
      label = TextFormatter.format(name, TextFormatter.P);
    }

    String title = getTitle();

    if ((title == null) && (Validator.isNull(label) || Objects.equals(type, "image"))) {

      title = TextFormatter.format(name, TextFormatter.P);
    }

    boolean wrappedField = getWrappedField();

    FieldWrapperTag fieldWrapper =
        (FieldWrapperTag) findAncestorWithClass(this, FieldWrapperTag.class);

    if (fieldWrapper != null) {
      wrappedField = true;
    }

    setNamespacedAttribute(request, "baseType", getBaseType());
    setNamespacedAttribute(request, "bean", bean);
    setNamespacedAttribute(request, "defaultLanguageId", defaultLanguageId);
    setNamespacedAttribute(request, "field", field);
    setNamespacedAttribute(request, "forLabel", forLabel);
    setNamespacedAttribute(request, "formName", formName);
    setNamespacedAttribute(request, "id", id);
    setNamespacedAttribute(request, "label", label);
    setNamespacedAttribute(request, "model", model);
    setNamespacedAttribute(request, "title", String.valueOf(title));
    setNamespacedAttribute(request, "wrappedField", wrappedField);

    request.setAttribute(getAttributeNamespace() + "value", getValue());

    Map<String, ValidatorTag> validatorTags = getValidatorTags();

    if ((validatorTags != null) && (validatorTags.get("required") != null)) {

      setNamespacedAttribute(request, "required", Boolean.TRUE.toString());
    }
  }
Пример #7
0
  @Override
  protected void setAttributes(HttpServletRequest request) {
    super.setAttributes(request);

    Object bean = getBean();

    if (bean == null) {
      bean = pageContext.getAttribute("aui:model-context:bean");
    }

    String name = getName();

    int pos = name.indexOf(StringPool.DOUBLE_DASH);

    if (pos != -1) {
      name = name.substring(pos + 2, name.length() - 2);
    }

    String field = getField();

    if (Validator.isNull(field)) {
      field = getName();
    }

    String formName = getFormName();

    if (formName == null) {
      FormTag formTag = (FormTag) findAncestorWithClass(this, FormTag.class);

      if (formTag != null) {
        formName = formTag.getName();
      }
    }

    String id = getId();
    String type = getType();

    if (Validator.isNull(id)) {
      if (!Validator.equals(type, "assetTags") && !Validator.equals(type, "radio")) {

        id = name;
      } else {
        id = PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
      }
    }

    String label = getLabel();

    if (label == null) {
      label = TextFormatter.format(name, TextFormatter.K);
    }

    Class<?> model = getModel();

    if (model == null) {
      model = (Class<?>) pageContext.getAttribute("aui:model-context:model");
    }

    _forLabel = id;

    String baseType = null;

    if ((model != null) && Validator.isNull(type)) {
      baseType = ModelHintsUtil.getType(model.getName(), field);

      String fieldParam = getFieldParam();

      if (Validator.isNotNull(fieldParam)) {
        _forLabel = fieldParam;
      }

      if (ModelHintsUtil.isLocalized(model.getName(), field)) {
        Locale defaultLocale = LocaleUtil.getDefault();
        String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);

        _forLabel += StringPool.UNDERLINE + defaultLanguageId;
      }
    } else if (Validator.isNotNull(type)) {
      if (Validator.equals(type, "checkbox") || Validator.equals(type, "radio")) {

        baseType = type;
      }
    }

    if (Validator.isNull(baseType)) {
      baseType = "text";
    }

    setNamespacedAttribute(request, "baseType", baseType);
    setNamespacedAttribute(request, "bean", bean);
    setNamespacedAttribute(request, "field", field);
    setNamespacedAttribute(request, "forLabel", _forLabel);
    setNamespacedAttribute(request, "formName", formName);
    setNamespacedAttribute(request, "id", id);
    setNamespacedAttribute(request, "label", label);
    setNamespacedAttribute(request, "model", model);

    request.setAttribute(getAttributeNamespace() + "value", getValue());
  }