private static String getDefaultValue(AttributeValue av, String indent) {
    Object value = av == null ? null : ReqIF10Util.getTheValue(av);
    String textValue;
    if (value == null) {
      textValue = "";
    } else if (value instanceof List<?>) {
      textValue = "";
      for (Iterator<EnumValue> i = ((List<EnumValue>) value).iterator(); i.hasNext(); ) {
        textValue += i.next().getLongName();

        if (i.hasNext()) {
          textValue += ", ";
        }
      }
    } else if (value instanceof XhtmlContent) {
      textValue = ProrXhtmlSimplifiedHelper.xhtmlToSimplifiedString((XhtmlContent) value);

      try {
        String xhtmlString = ReqIF10XhtmlUtil.getXhtmlString((XhtmlContent) value);
        System.out.println("xhtmlString" + xhtmlString);
        xhtmlString = xhtmlString.replace("<xhtml:", "<");
        xhtmlString = xhtmlString.replace("</xhtml:", "</");
        textValue = xhtmlString;
      } catch (IOException e) {
      }
    } else {
      textValue = value.toString();
    }

    return indent + textValue;
  }
Beispiel #2
0
  /**
   * Finds the best labels, according to what is set in the preferences.
   *
   * @param specElement
   * @param adapterFactory
   * @param adapterFactory
   * @return
   */
  public static String getSpecElementLabel(
      SpecElementWithAttributes specElement, AdapterFactory adapterFactory) {

    List<String> labels = getDefaultLabels(ReqIF10Util.getReqIF(specElement));

    // Iterate over the list of labels requested
    for (String label : labels) {

      for (AttributeValue value : specElement.getValues()) {
        AttributeDefinition ad = ReqIF10Util.getAttributeDefinition(value);
        if (ad == null) continue;

        if (label.equals(ad.getLongName())) {
          ProrPresentationConfiguration config = getPresentationConfig(value);

          ItemProviderAdapter ip = ProrUtil.getItemProvider(adapterFactory, config);
          if (ip instanceof PresentationEditInterface) {
            String customLabel = ((PresentationEditInterface) ip).getLabel(value);
            if (customLabel != null) return customLabel;
          }

          Object result = ReqIF10Util.getTheValue(value);
          if (result != null) {

            // If we have an enumeration attribute
            if (value instanceof AttributeValueEnumeration && result instanceof EList) {
              EList<?> list = (EList<?>) result;
              if (!list.isEmpty()) return ((EnumValue) list.get(0)).getLongName();
              else return "";
            } else if (value instanceof AttributeValueXHTML && result instanceof XhtmlContent) {
              XhtmlContent content = (XhtmlContent) result;
              String text = ProrXhtmlSimplifiedHelper.xhtmlToSimplifiedString(content);

              // Ignore empty XHTML
              if (text.trim().length() == 0) {
                continue;
              }

              // Shorten long XHTML
              if (text.length() > 20) text = text.substring(0, 17) + "...";
              return text;
            }
            return result.toString();
          }
        }
      }
    }
    return specElement.getIdentifier();
  }