private static String getVarName(String identifier) {
   String[] parts = StringUtilities.tokenizeIdentifierIntoArray(identifier);
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < parts.length; i++) {
     if (i != 0) {
       sb.append("_");
     }
     sb.append(parts[i].toUpperCase());
   }
   return sb.toString();
 }
  /**
   * Heuristically checks if the two layout components belong to the same attribute or rel.
   *
   * @param lc1
   * @param lc2
   * @return true if the two layout components belong to the same attribute or rel.
   */
  private static boolean sameAttributeOrRel(LayoutComponent lc1, LayoutComponent lc2) {

    String lc1Text = lc1.text == null ? "" : lc1.text.replace(" ", "").trim();
    String lc2Text = lc2.text == null ? "" : lc2.text.replace(" ", "").trim();
    // texts match.
    if (lc1Text.length() >= 2 && StringUtilities.equals(lc1Text, lc2Text, true)) {
      return true;
    }

    if (StringUtilities.equals(lc1.varName, lc2Text, true)
        || StringUtilities.equals(lc1Text, lc2.varName, true)) {
      return true;
    }

    // name match.
    String[] lc1NameParts = StringUtilities.tokenizeIdentifierIntoArray(lc1.varName);
    String[] lc2NameParts = StringUtilities.tokenizeIdentifierIntoArray(lc2.varName);
    if (lc1NameParts.length > 1) {
      if (concatenateStrings(lc1NameParts, 1)
          .equalsIgnoreCase(concatenateStrings(lc2NameParts, 0))) {
        return true;
      } else if (lc2NameParts.length > 1
          && concatenateStrings(lc1NameParts, 1)
              .equalsIgnoreCase(concatenateStrings(lc2NameParts, 1))) {
        return true;
      } else if (concatenateStrings(lc1NameParts, 1).equalsIgnoreCase(lc2Text)) {
        return true;
      }
    } else {
      if (lc2NameParts.length > 1) {
        if (concatenateStrings(lc1NameParts, 0)
            .equalsIgnoreCase(concatenateStrings(lc2NameParts, 1))) {
          return true;
        } else if (concatenateStrings(lc2NameParts, 1).equalsIgnoreCase(lc1Text)) {
          return true;
        }
      }
    }
    return false;
  }
 private static Relationship getRelationship(List<Relationship> rels, LayoutComponent lc) {
   Relationship rel = getRelationship(rels, lc.varName);
   if (rel != null) {
     return rel;
   }
   String[] lcNameParts = StringUtilities.tokenizeIdentifierIntoArray(lc.varName);
   if (lcNameParts.length > 1) {
     rel = getRelationship(rels, concatenateStrings(lcNameParts, 1));
   }
   if (rel != null) {
     return rel;
   }
   if (lc.text != null) {
     rel = getRelationship(rels, lc.text.replace(" ", "").trim());
   }
   return rel;
 }
 /**
  * Try to obtain the attribute using the varName or text. To match an attr/rel named 'itemValue',
  * the varName could be 'itemVALUE' or the text 'item value'.
  *
  * @param attrs
  * @param lc
  * @return
  */
 private static Attribute getAttribute(List<Attribute> attrs, LayoutComponent lc) {
   Attribute attr = getAttribute(attrs, lc.varName);
   if (attr != null) {
     return attr;
   }
   String[] lcNameParts = StringUtilities.tokenizeIdentifierIntoArray(lc.varName);
   if (lcNameParts.length > 1) {
     attr = getAttribute(attrs, concatenateStrings(lcNameParts, 1));
   }
   if (attr != null) {
     return attr;
   }
   if (lc.text != null) {
     attr = getAttribute(attrs, lc.text.replace(" ", "").trim());
   }
   return attr;
 }