<commit_before>/*
 * Copyright 2003 - 2009 The eFaps Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Revision:        $Rev$
 * Last Changed:    $Date$
 * Last Changed By: $Author$
 */

package org.efaps.admin.datamodel.ui;

import java.util.List;

import org.efaps.admin.ui.field.Field;

/**
 * Class to represent a String for the user interface.
 *
 * @author tmo
 * @version $Id$
 *
 */
public class StringUI extends AbstractUI {

  /**
   * Needed for serialization.
   */
  private static final long serialVersionUID = 1L;

  /**
   * Method to get the Value for viewing in an html document.
   *
   * @param _fieldValue Fieldvalue the representation is requested
   * @return value for field
   *
   */
  @Override
  public String getViewHtml(final FieldValue _fieldValue) {
    final StringBuilder ret = new StringBuilder();

    if (_fieldValue.getValue() != null) {

      if (_fieldValue.getValue() instanceof List) {
        final List<?> values = (List<?>) _fieldValue.getValue();
        boolean first = true;
        for (final Object value : values) {
          final String tmp = value.toString();
          if (tmp != null) {
            if (first) {
              first = false;
            } else {
              ret.append("<br/>");
            }
            ret.append(tmp.replaceAll("\\n", "<br/>").replaceAll("<", "&lt;")
                        .replaceAll(">", "&gt;"));
          }
        }
      } else {
        final String tmp = _fieldValue.getValue().toString();
        if (tmp != null) {
          ret.append(tmp.replaceAll("\\n", "<br/>").replaceAll("<", "&lt;")
                        .replaceAll(">", "&gt;"));
        }
      }
    }
    return ret.toString();
  }

  /**
   * Method to get the Value for editing in an html document.
   *
   * @param _fieldValue Fieldvalue the representation is requested
   * @return value for field
   *
   */
  @Override
  public String getEditHtml(final FieldValue _fieldValue) {
    String ret;
    final Field field = _fieldValue.getField();
    final Object value = _fieldValue.getValue();
    if (field.getRows() > 1) {
      ret =
          "<textarea " + "type=\"text\" " + "cols=\"" + field.getCols() + "\" "
              + "rows=\"" + field.getRows() + "\" " + "name=\""
              + field.getName() + "\"" + ">";
      if (value != null) {
        ret += value;
      }
      ret += "</textarea>";
    } else {<commit_msg>- bugFix: wrong order of replacing tags in string<commit_after>/*
 * Copyright 2003 - 2009 The eFaps Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Revision:        $Rev$
 * Last Changed:    $Date$
 * Last Changed By: $Author$
 */

package org.efaps.admin.datamodel.ui;

import java.util.List;

import org.efaps.admin.ui.field.Field;

/**
 * Class to represent a String for the user interface.
 *
 * @author tmo
 * @version $Id$
 *
 */
public class StringUI extends AbstractUI {

  /**
   * Needed for serialization.
   */
  private static final long serialVersionUID = 1L;

  /**
   * Method to get the Value for viewing in an html document.
   *
   * @param _fieldValue Fieldvalue the representation is requested
   * @return value for field
   *
   */
  @Override
  public String getViewHtml(final FieldValue _fieldValue) {
    final StringBuilder ret = new StringBuilder();

    if (_fieldValue.getValue() != null) {

      if (_fieldValue.getValue() instanceof List) {
        final List<?> values = (List<?>) _fieldValue.getValue();
        boolean first = true;
        for (final Object value : values) {
          final String tmp = value.toString();
          if (tmp != null) {
            if (first) {
              first = false;
            } else {
              ret.append("<br/>");
            }
            ret.append(tmp.replaceAll("<", "&lt;").replaceAll(">", "&gt;")
                          .replaceAll("\\n", "<br/>"));
          }
        }
      } else {
        final String tmp = _fieldValue.getValue().toString();
        if (tmp != null) {
          ret.append(tmp.replaceAll("<", "&lt;").replaceAll(">", "&gt;")
                        .replaceAll("\\n", "<br/>"));
        }
      }
    }
    return ret.toString();
  }

  /**
   * Method to get the Value for editing in an html document.
   *
   * @param _fieldValue Fieldvalue the representation is requested
   * @return value for field
   *
   */
  @Override
  public String getEditHtml(final FieldValue _fieldValue) {
    String ret;
    final Field field = _fieldValue.getField();
    final Object value = _fieldValue.getValue();
    if (field.getRows() > 1) {
      ret =
          "<textarea " + "type=\"text\" " + "cols=\"" + field.getCols() + "\" "
              + "rows=\"" + field.getRows() + "\" " + "name=\""
              + field.getName() + "\"" + ">";
      if (value != null) {
        ret += value;
      }
      ret += "</textarea>";
    } else {
{'fraction_non_alphanumeric': 0.13486953575059302, 'fraction_numerical': 0.004744154523890207, 'mean_word_length': 2.2505506607929515, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '677497', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1666, 'n_words': 550}