private void copyContent(Resource source, Resource target, boolean skipPrimaryType)
     throws PersistenceException {
   ValueMap sourceProps = source.adaptTo(ValueMap.class);
   ModifiableValueMap targetProps = target.adaptTo(ModifiableValueMap.class);
   for (Map.Entry<String, Object> entry : sourceProps.entrySet()) {
     if (skipPrimaryType && StringUtils.equals(entry.getKey(), JcrConstants.JCR_PRIMARYTYPE)) {
       continue;
     }
     targetProps.put(entry.getKey(), entry.getValue());
   }
   copyChildren(source, target);
 }
Пример #2
0
  @Test
  public void testGetLanguage() {
    Page profilesPage = context.pageManager().getPage("/content/sample/en/toolbar/profiles");

    // set language in site root
    ModifiableValueMap props = this.page.getContentResource().adaptTo(ModifiableValueMap.class);
    props.put(JcrConstants.JCR_LANGUAGE, "fr_FR");

    // test get language from content
    Locale locale = profilesPage.getLanguage(false);
    assertEquals(Locale.forLanguageTag("fr-FR"), locale);

    // test get language from path
    locale = profilesPage.getLanguage(true);
    assertEquals(Locale.forLanguageTag("en"), locale);
  }
Пример #3
0
  @Test
  public void testValidityOnTimeInPast() throws PersistenceException {

    // set on/off-times
    Calendar onTime = Calendar.getInstance();
    onTime.add(Calendar.DAY_OF_MONTH, -2);
    Calendar offTime = Calendar.getInstance();
    offTime.add(Calendar.DAY_OF_MONTH, -1);
    ModifiableValueMap props = this.page.getContentResource().adaptTo(ModifiableValueMap.class);
    props.put(NameConstants.PN_ON_TIME, onTime);
    props.put(NameConstants.PN_OFF_TIME, offTime);
    this.context.resourceResolver().commit();

    // Validate
    assertEquals(onTime.getTime(), this.page.getOnTime().getTime());
    assertEquals(offTime.getTime(), this.page.getOffTime().getTime());
    assertFalse(this.page.isValid());
    assertTrue(this.page.timeUntilValid() < 0L);
  }
Пример #4
0
  @Override
  public void setTags(Resource resource, Tag[] tags, boolean autoSave) {
    ModifiableValueMap props = resource.adaptTo(ModifiableValueMap.class);
    if (tags == null) {
      props.remove(TagConstants.PN_TAGS);
    } else {
      String[] tagStrings = new String[tags.length];
      for (int i = 0; i < tags.length; ++i) {
        // 6.0 has appeared to have switched to storing (the shorter) tagIDs, from where 5.6 was
        // storing absolute paths.
        tagStrings[i] = tags[i].getTagID();
      }
      props.put(TagConstants.PN_TAGS, tagStrings);
    }

    if (autoSave) {
      try {
        resourceResolver.commit();
      } catch (PersistenceException e) {
        log.error("failed to commit updates for setting tags", e);
      }
    }
  }