/** * Assumes context is such that we're in the / site. Steals locks, so should be used in single-user mode. * * @throws CmsException */ public void completeCalendarEntryImport() throws CmsException { // Loop through all resources in the calendar entry folder. final CmsResourceFilter filter = CmsResourceFilter.ALL.addExcludeState(CmsResource.STATE_DELETED); final List calendarEntries = this.cmsObject.getFilesInFolder("/sites/default/calendarentries", filter); for (final CmsResource cmsResource : calendarEntries) { final String absoluteResourcePath = cmsResource.getRootPath(); System.out.println("Handling " + absoluteResourcePath); this.cmsObject.lockResource(absoluteResourcePath); // Change the resource's type. this.cmsObject.chtype(absoluteResourcePath, ConfigurationParameters.CALENDAR_ENTRY_TYPE_ID); // Get hold of the resource as an XML document. CmsFile resourceFile = null; try { resourceFile = CmsFile.upgrade(cmsResource, this.cmsObject); I_CmsXmlDocument xmlDocument = CmsXmlContentFactory.unmarshal(this.cmsObject, resourceFile); // Get Title, DateReleased, DateExpired, EnableNotification, NotificationInterval elements and map to // resource properties or attributes as appropriate. First, attributes. String s = xmlDocument.getStringValue(this.cmsObject, "DateReleased", ConfigurationParameters.PRIMARY_CONTENT_LOCALE_LANGUAGE_ONLY); if (s != null) { cmsResource.setDateReleased(Long.valueOf(s).longValue()); } s = xmlDocument.getStringValue(this.cmsObject, "DateExpired", ConfigurationParameters.PRIMARY_CONTENT_LOCALE_LANGUAGE_ONLY); if (s != null) { cmsResource.setDateExpired(Long.valueOf(s).longValue()); } // Now, properties. final List propertiesToChange = new ArrayList(); s = xmlDocument.getStringValue(this.cmsObject, "Title", ConfigurationParameters.PRIMARY_CONTENT_LOCALE_LANGUAGE_ONLY); if (s != null) { propertiesToChange.add(new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, s, null, true)); } s = xmlDocument.getStringValue(this.cmsObject, "EnableNotification", ConfigurationParameters.PRIMARY_CONTENT_LOCALE_LANGUAGE_ONLY); if (s != null) { propertiesToChange.add(new CmsProperty(CmsPropertyDefinition.PROPERTY_ENABLE_NOTIFICATION, s, null, true)); } s = xmlDocument.getStringValue(this.cmsObject, "NotificationInterval", ConfigurationParameters.PRIMARY_CONTENT_LOCALE_LANGUAGE_ONLY); if (s != null) { propertiesToChange.add(new CmsProperty(CmsPropertyDefinition.PROPERTY_NOTIFICATION_INTERVAL, s, null, true)); } // Now set other properties required by our site machinery: template-elements and content-conversion. propertiesToChange.add(new CmsProperty("content-conversion", "cleanup;xhtml", null, true)); propertiesToChange.add(new CmsProperty("template-elements", "/system/modules/com.scintillance.opencms.module/template-elements/calendarentry.jsp", null, true)); // Write out the properties. this.cmsObject.writePropertyObjects(absoluteResourcePath, propertiesToChange); // Finally, unlock the resource. this.cmsObject.unlockResource(absoluteResourcePath); } catch (CmsException e) { // Do the best we can - just log the problem and carry on with the next resource. LOG.debug("For resource " + absoluteResourcePath, e); continue; } } }