/** * Creates a clone of this property that already is of type <code>{@link CmsProperty}</code>.<p> * * The cloned property will not be frozen.<p> * * @return a clone of this property that already is of type <code>{@link CmsProperty}</code> */ public CmsProperty cloneAsProperty() { if (this == NULL_PROPERTY) { // null property must never be cloned return NULL_PROPERTY; } CmsProperty clone = new CmsProperty(); clone.m_name = m_name; clone.m_structureValue = m_structureValue; clone.m_structureValueList = m_structureValueList; clone.m_resourceValue = m_resourceValue; clone.m_resourceValueList = m_resourceValueList; clone.m_autoCreatePropertyDefinition = m_autoCreatePropertyDefinition; // the value for m_frozen does not need to be set as it is false by default return clone; }
/** * Creates a clone of this property that already is of type <code>{@link CmsProperty}</code>.<p> * * The cloned property will not be frozen.<p> * * @return a clone of this property that already is of type <code>{@link CmsProperty}</code> */ public CmsProperty cloneAsProperty() { if (this == NULL_PROPERTY) { // null property must never be cloned return NULL_PROPERTY; } CmsProperty clone = new CmsProperty(); clone.m_name = m_name; clone.m_structureValue = m_structureValue; clone.m_structureValueList = m_structureValueList; clone.m_resourceValue = m_resourceValue; clone.m_resourceValueList = m_resourceValueList; clone.m_autoCreatePropertyDefinition = m_autoCreatePropertyDefinition; clone.m_origin = m_origin; // the value for m_frozen does not need to be set as it is false by default return clone; }
/** * Transforms a Map of String values into a list of * {@link CmsProperty} objects with the property name set from the * Map key, and the structure value set from the Map value.<p> * * @param map a Map with String keys and String values * * @return a list of {@link CmsProperty} objects */ public static List<CmsProperty> toList(Map<String, String> map) { if ((map == null) || (map.size() == 0)) { return Collections.emptyList(); } List<CmsProperty> result = new ArrayList<CmsProperty>(map.size()); Iterator<Map.Entry<String, String>> i = map.entrySet().iterator(); while (i.hasNext()) { Map.Entry<String, String> e = i.next(); CmsProperty property = new CmsProperty(e.getKey(), e.getValue(), null); result.add(property); } return result; }
/** * Transforms a Map of String values into a list of * {@link CmsProperty} objects with the property name set from the * Map key, and the structure value set from the Map value.<p> * * @param map a Map with String keys and String values * * @return a list of {@link CmsProperty} objects */ public static List toList(Map map) { if ((map == null) || (map.size() == 0)) { return Collections.EMPTY_LIST; } List result = new ArrayList(map.size()); Iterator i = map.entrySet().iterator(); while (i.hasNext()) { Map.Entry e = (Map.Entry)i.next(); String name = String.valueOf(e.getKey()); String value = String.valueOf(e.getValue()); CmsProperty property = new CmsProperty(name, value, null); result.add(property); } return result; }
/** * @see org.opencms.file.types.A_CmsResourceType#getConfiguredDefaultProperties() */ @Override public List<CmsProperty> getConfiguredDefaultProperties() { Map<String, CmsProperty> propertyMap = CmsProperty.toObjectMap(super.getConfiguredDefaultProperties()); String localeStr = CmsLocaleManager.MASTER_LOCALE.toString(); for (String propName : new String[] { CmsPropertyDefinition.PROPERTY_AVAILABLE_LOCALES, CmsPropertyDefinition.PROPERTY_LOCALE}) { propertyMap.put(propName, new CmsProperty(propName, localeStr, localeStr, true)); } return new ArrayList<CmsProperty>(propertyMap.values()); }
/** * Helper method to create OpenCms property objects from a map of CMIS properties.<p> * * @param properties the CMIS properties * * @return the OpenCms properties */ protected List<CmsProperty> getOpenCmsProperties(Map<String, PropertyData<?>> properties) { List<CmsProperty> cmsProperties = new ArrayList<CmsProperty>(); for (Map.Entry<String, PropertyData<?>> entry : properties.entrySet()) { String propId = entry.getKey(); if (propId.startsWith(CmsCmisTypeManager.PROPERTY_PREFIX)) { String propName = propId.substring(CmsCmisTypeManager.PROPERTY_PREFIX.length()); String value = (String)entry.getValue().getFirstValue(); if (value == null) { value = ""; } cmsProperties.add(new CmsProperty(propName, value, null)); } } return cmsProperties; }
/** * Writes the given property to the resource as structure value.<p> * * @param resourceName the resource to write the value to * @param propertyName the property to write the value to * @param value the value to write * * @throws CmsException if something goes wrong */ public void writeProperty(String resourceName, String propertyName, String value) throws CmsException { m_cms.lockResource(resourceName); m_cms.writePropertyObject(resourceName, new CmsProperty(propertyName, value, null)); }
/** * Generates a list of property object to save to the sitemap entry resource to apply the given change.<p> * * @param change the change * * @return the property objects */ private List<CmsProperty> generateOwnProperties(CmsSitemapChange change) { List<CmsProperty> result = new ArrayList<CmsProperty>(); Map<String, CmsClientProperty> clientProps = change.getDefaultFileProperties(); boolean hasTitle = false; if (clientProps != null) { for (CmsClientProperty clientProp : clientProps.values()) { if (CmsPropertyDefinition.PROPERTY_TITLE.equals(clientProp.getName())) { hasTitle = true; } CmsProperty prop = new CmsProperty( clientProp.getName(), clientProp.getStructureValue(), clientProp.getResourceValue()); result.add(prop); } } if (!hasTitle) { result.add(new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, change.getName(), null)); } return result; }
/** * Reads a property object from a resource specified by a property name.<p> * * Returns <code>{@link CmsProperty#getNullProperty()}</code> if the property is not found.<p> * * @param dbc the current database context * @param resource the resource where the property is read from * @param key the property key name * @param search if <code>true</code>, the property is searched on all parent folders of the resource. * if it's not found attached directly to the resource. * * @return the required property, or <code>{@link CmsProperty#getNullProperty()}</code> if the property was not found * * @throws CmsException if something goes wrong */ public CmsProperty readPropertyObject(CmsDbContext dbc, CmsResource resource, String key, boolean search) throws CmsException { // NOTE: Do not call readPropertyObject(dbc, resource, key, search, null) for performance reasons // use the list reading method to obtain all properties for the resource List<CmsProperty> properties = readPropertyObjects(dbc, resource, search); int i = properties.indexOf(new CmsProperty(key, null, null)); if (i >= 0) { // property has been found in the map CmsProperty result = properties.get(i); // ensure the result value is not frozen return result.cloneAsProperty(); } return CmsProperty.getNullProperty(); }
/** * Writes a property as a structure value for a file or folder.<p> * * @param resourceName the resource-name for which the property will be set * @param key the property definition name * @param value the value for the property to be set * * @throws CmsException if operation was not successful * * @deprecated use <code>{@link #writePropertyObject(String, CmsProperty)}</code> instead. */ public void writeProperty(String resourceName, String key, String value) throws CmsException { CmsProperty property = new CmsProperty(); property.setName(key); property.setStructureValue(value); writePropertyObject(resourceName, property); }
/** * Deletes a property for a file or folder.<p> * * @param resourcename the name of a resource for which the property should be deleted * @param key the name of the property * * @throws CmsException if something goes wrong * * @deprecated use <code>{@link #writePropertyObject(String, CmsProperty)}</code> instead. */ public void deleteProperty(String resourcename, String key) throws CmsException { CmsProperty property = new CmsProperty(); property.setName(key); property.setStructureValue(CmsProperty.DELETE_VALUE); writePropertyObject(resourcename, property); }
/** * Applys the given remove change.<p> * * @param change the change to apply * * @return the changed client sitemap entry or <code>null</code> * * @throws CmsException if something goes wrong */ private CmsSitemapChange removeEntryFromNavigation(CmsSitemapChange change) throws CmsException { CmsObject cms = getCmsObject(); CmsResource entryFolder = cms.readResource(change.getEntryId(), CmsResourceFilter.ONLY_VISIBLE_NO_DELETED); ensureLock(entryFolder); List<CmsProperty> properties = new ArrayList<CmsProperty>(); properties.add( new CmsProperty( CmsPropertyDefinition.PROPERTY_NAVTEXT, CmsProperty.DELETE_VALUE, CmsProperty.DELETE_VALUE)); properties.add( new CmsProperty(CmsPropertyDefinition.PROPERTY_NAVPOS, CmsProperty.DELETE_VALUE, CmsProperty.DELETE_VALUE)); cms.writePropertyObjects(cms.getSitePath(entryFolder), properties); tryUnlock(entryFolder); return change; }
/** * Writes a property for a file or folder.<p> * * @param resourcename the resource-name for which the property will be set * @param key the property-definition name * @param value the value for the property to be set * @param addDefinition flag to indicate if unknown definitions should be added * * @throws CmsException if operation was not successful * * @deprecated use <code>{@link #writePropertyObject(String, CmsProperty)}</code> instead. */ public void writeProperty(String resourcename, String key, String value, boolean addDefinition) throws CmsException { CmsProperty property = new CmsProperty(); property.setName(key); property.setStructureValue(value); property.setAutoCreatePropertyDefinition(addDefinition); writePropertyObject(resourcename, property); }
/** * Creates a single property object and sets the value individual or shared depending on the OpenCms settings.<p> * * @param name the name of the property * @param value the value to set * @return an initialized property object */ protected static CmsProperty createPropertyObject(String name, String value) { CmsProperty prop = new CmsProperty(); prop.setAutoCreatePropertyDefinition(true); prop.setName(name); if (OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) { prop.setValue(value, CmsProperty.TYPE_INDIVIDUAL); } else { prop.setValue(value, CmsProperty.TYPE_SHARED); } return prop; }
/** * Tries to either read or create the default folder for model pages in the current sitemap, and returns it.<p> * * @param rootResource the root of the sitemap * * @return the folder resource * * @throws CmsException if something goes wrong */ public CmsResource ensureModelFolder(CmsResource rootResource) throws CmsException { String modelFolderPath = CmsStringUtil.joinPaths(m_adeConfig.getBasePath(), ".content/.templates"); try { CmsResource result = m_cms.readFolder(modelFolderPath); return result; } catch (CmsVfsResourceNotFoundException e) { CmsProperty searchExclude = new CmsProperty(CmsPropertyDefinition.PROPERTY_SEARCH_EXCLUDE, "all", null); CmsResource result = m_cms.createResource( modelFolderPath, getType(CmsResourceTypeFolder.getStaticTypeName()), null, Arrays.asList(searchExclude)); tryUnlock(result); return result; } }
/** * Creates a single property object and sets the value individual or shared depending on the OpenCms settings.<p> * * @param name the name of the property * @param value the value to set * @return an initialized property object */ protected static CmsProperty createPropertyObject(String name, String value) { CmsProperty prop = new CmsProperty(); prop.setAutoCreatePropertyDefinition(true); prop.setName(name); if (OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) { prop.setValue(value, CmsProperty.TYPE_INDIVIDUAL); } else { prop.setValue(value, CmsProperty.TYPE_SHARED); } return prop; }
/** * @see org.opencms.ade.sitemap.shared.rpc.I_CmsSitemapService#changeCategory(java.lang.String, org.opencms.util.CmsUUID, java.lang.String, java.lang.String) */ public void changeCategory(String entryPoint, CmsUUID id, String title, String name) throws CmsRpcException { try { name = OpenCms.getResourceManager().getFileTranslator().translateResource(name.trim().replace('/', '-')); CmsObject cms = getCmsObject(); CmsResource categoryResource = cms.readResource(id); ensureLock(categoryResource); String sitePath = cms.getSitePath(categoryResource); String newPath = CmsStringUtil.joinPaths(CmsResource.getParentFolder(sitePath), name); cms.writePropertyObject(sitePath, new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, title, null)); if (!CmsStringUtil.joinPaths("/", newPath, "/").equals(CmsStringUtil.joinPaths("/", sitePath, "/"))) { cms.moveResource(sitePath, newPath); } } catch (Exception e) { error(e); } }
/** * Creates a replace html tag Thread.<p> * * @param cms the current cms context. * * @param settings the settings needed to perform the operation. */ public CmsTagReplaceThread(CmsObject cms, CmsTagReplaceSettings settings) { super(cms, Messages.get().getBundle().key(Messages.GUI_TAGREPLACE_THREAD_NAME_0)); initHtmlReport(cms.getRequestContext().getLocale()); m_settings = settings; m_markerProperty = new CmsProperty( CmsTagReplaceSettings.PROPERTY_CONTENTOOLS_TAGREPLACE, null, m_settings.getPropertyValueTagReplaceID(), true); }
/** * @see org.opencms.gwt.shared.rpc.I_CmsVfsService#createNewExternalLink(java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ public void createNewExternalLink(String title, String link, String resourceName, String parentFolderPath) throws CmsRpcException { CmsObject cms = getCmsObject(); try { CmsProperty titleProp = new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, title, null); @SuppressWarnings("deprecation") CmsResource resource = cms.createResource( CmsStringUtil.joinPaths(parentFolderPath, resourceName), CmsResourceTypePointer.getStaticTypeId(), new byte[0], Collections.singletonList(titleProp)); CmsFile file = cms.readFile(resource); file.setContents(link.getBytes(CmsLocaleManager.getResourceEncoding(cms, resource))); cms.writeFile(file); tryUnlock(resource); // update the offline search indices OpenCms.getSearchManager().updateOfflineIndexes(); } catch (Exception e) { error(e); } }
/** * Enumeration class for the mode parameter in the * {@link CmsDriverManager#readChangedResourcesInsideProject(CmsDbContext, CmsUUID, CmsReadChangedProjectResourceMode)} * method.<p> */ private static class CmsReadChangedProjectResourceMode { /** * Default constructor.<p> */ protected CmsReadChangedProjectResourceMode() { // noop } }