@Test
 public void shouldGetCmServer() throws CMException {
   Policy policy = mock(Policy.class);
   doReturn(policy).when(target).getPolicy();
   when(policy.getCMServer()).thenReturn(policyCMServer);
   assertEquals(policyCMServer, target.getCmServer());
 }
 @Test
 public void shouldGetCurrentRootSiteId() throws CMException {
   doReturn(policyCMServer).when(target).getCmServer();
   doReturn(configUtil).when(target).getConfiguration(policyCMServer);
   Policy topPolicy = mock(Policy.class);
   VersionedContentId id = mock(VersionedContentId.class);
   when(contentSession.getTopPolicy()).thenReturn(topPolicy);
   when(topPolicy.getContentId()).thenReturn(id);
   when(configUtil.getCurrentRootSiteId(id)).thenReturn(siteId);
   assertEquals(siteId, target.getCurrentRootSiteId());
 }
 public void add(int index, Policy policy, ReferenceMetaDataPolicy referenceMetaData) {
   contentIds()
       .add(
           index,
           policy.getContentId().getContentId(),
           (referenceMetaData != null ? referenceMetaData.getContentId().getContentId() : null));
 }
  public int indexOf(Policy policy) {
    VersionedContentId policyId = policy.getContentId();

    for (int i = size() - 1; i >= 0; i--) {
      ContentIdUtil referredContentId = getEntry(i).getReferredContentId();

      if (referredContentId == null) {
        LOGGER.log(WARNING, "There was a null ID added to the content list " + this + ".");
        continue;
      }

      if (referredContentId.equalsIgnoreVersion(policyId)) {
        return i;
      }
    }

    return -1;
  }
Beispiel #5
0
  public String get(Policy policy, PolopolyContext context) {
    if (policy instanceof SingleValued) {
      try {
        return '"' + ((SingleValued) policy).getValue() + '"';
      } catch (CMException e) {
        System.err.println(e.toString());
        return "";
      }
    }
    // ContentPolicy implements ContentListAware but does not generally represent a content list.
    else if (policy instanceof ContentListAware && !(policy.getClass() == ContentPolicy.class)) {
      try {
        ContentList contentList = ((ContentListAware) policy).getContentList();

        StringBuffer result = new StringBuffer(100);

        result.append("[");

        boolean first = true;

        for (ContentId contentId : new ContentListIterator(contentList)) {
          if (!first) {
            result.append(", ");
          }

          result.append(AbstractContentIdField.get(contentId, context));

          first = false;
        }

        result.append("]");

        return result.toString();
      } catch (CMException e) {
        System.err.println(e);

        return "";
      }
    } else {
      return "";
    }
  }
 public void remove(Policy policy) {
   contentIds().remove(policy.getContentId());
 }
 public void add(int index, Policy policy) {
   contentIds().add(index, policy.getContentId().getContentId());
 }