Пример #1
0
  /**
   * Get the list of contents by relationship if exists.
   *
   * @param structure The content structure
   * @param contentlet The content
   * @param parametersOptions The macro form options parameters
   * @return Map<Relationship,List<Contentlet>>
   * @throws DotSecurityException
   */
  private static Map<Relationship, List<Contentlet>> getRelationships(
      Structure structure, Contentlet contentlet, String parametersOptions, User user)
      throws DotDataException, DotSecurityException {
    LanguageAPI lAPI = APILocator.getLanguageAPI();
    Map<Relationship, List<Contentlet>> contentRelationships =
        new HashMap<Relationship, List<Contentlet>>();
    if (contentlet == null) return contentRelationships;
    List<Relationship> rels =
        RelationshipFactory.getAllRelationshipsByStructure(contentlet.getStructure());
    for (Relationship rel : rels) {

      String[] opt = parametersOptions.split(";");
      for (String text : opt) {
        if (text.indexOf(rel.getRelationTypeValue()) != -1) {

          String[] identArray =
              text.substring(text.indexOf("=") + 1)
                  .replaceAll("\\[", "")
                  .replaceAll("\\]", "")
                  .split(",");

          List<Contentlet> cons =
              conAPI.findContentletsByIdentifiers(
                  identArray, true, lAPI.getDefaultLanguage().getId(), user, true);
          if (cons.size() > 0) {
            contentRelationships.put(rel, cons);
          }
        }
      }
    }
    return contentRelationships;
  }