use of org.opencms.file.CmsPropertyDefinition in project opencms-core by alkacon.
the class CmsResourceWrapperUtils method createPropertyFile.
/**
* Creates a virtual CmsFile with the individual and shared properties as content.<p>
*
* For example looks like this:<br/>
* Title.i=The title of the resource set as individual property<br/>
* Title.s=The title of the resource set as shared property<br/>
*
* @see #writePropertyFile(CmsObject, String, byte[])
*
* @param cms the initialized CmsObject
* @param res the resource where to read the properties from
* @param path the full path to set for the created property file
*
* @return the created CmsFile with the individual and shared properties as the content
*
* @throws CmsException if something goes wrong
*/
public static CmsFile createPropertyFile(CmsObject cms, CmsResource res, String path) throws CmsException {
StringBuffer content = new StringBuffer();
// header
content.append("# Properties for resource ");
content.append(res.getRootPath());
content.append("\n");
content.append("#\n");
content.append("# ${property_name}.i : individual property\n");
content.append("# ${property_name}.s : shared property\n\n");
List<CmsPropertyDefinition> propertyDef = cms.readAllPropertyDefinitions();
Map<String, CmsProperty> activeProperties = CmsProperty.getPropertyMap(cms.readPropertyObjects(res, false));
String resourceType = OpenCms.getResourceManager().getResourceType(res).getTypeName();
content.append("resourceType=");
content.append(resourceType);
content.append("\n\n");
// iterate over all possible properties for the resource
Iterator<CmsPropertyDefinition> i = propertyDef.iterator();
while (i.hasNext()) {
CmsPropertyDefinition currentPropertyDef = i.next();
String propName = currentPropertyDef.getName();
CmsProperty currentProperty = activeProperties.get(propName);
if (currentProperty == null) {
currentProperty = new CmsProperty();
}
String individualValue = currentProperty.getStructureValue();
String sharedValue = currentProperty.getResourceValue();
if (individualValue == null) {
individualValue = "";
}
if (sharedValue == null) {
sharedValue = "";
}
individualValue = escapeString(individualValue);
sharedValue = escapeString(sharedValue);
content.append(propName);
content.append(SUFFIX_PROP_INDIVIDUAL);
content.append("=");
content.append(individualValue);
content.append("\n");
content.append(propName);
content.append(SUFFIX_PROP_SHARED);
content.append("=");
content.append(sharedValue);
content.append("\n\n");
}
CmsWrappedResource wrap = new CmsWrappedResource(res);
wrap.setRootPath(addFileExtension(cms, path, EXTENSION_PROPERTIES));
int plainId = OpenCms.getResourceManager().getResourceType(CmsResourceTypePlain.getStaticTypeName()).getTypeId();
wrap.setTypeId(plainId);
wrap.setFolder(false);
CmsFile ret = wrap.getFile();
try {
ret.setContents(content.toString().getBytes(CmsEncoder.ENCODING_UTF_8));
} catch (UnsupportedEncodingException e) {
// this will never happen since UTF-8 is always supported
ret.setContents(content.toString().getBytes());
}
return ret;
}
use of org.opencms.file.CmsPropertyDefinition in project opencms-core by alkacon.
the class CmsSecurityManager method readPropertyDefinition.
/**
* Reads a property definition.<p>
*
* If no property definition with the given name is found,
* <code>null</code> is returned.<p>
*
* @param context the current request context
* @param name the name of the property definition to read
*
* @return the property definition that was read
*
* @throws CmsException a CmsDbEntryNotFoundException is thrown if the property definition does not exist
*/
public CmsPropertyDefinition readPropertyDefinition(CmsRequestContext context, String name) throws CmsException {
CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
CmsPropertyDefinition result = null;
try {
result = m_driverManager.readPropertyDefinition(dbc, name);
} catch (Exception e) {
dbc.report(null, Messages.get().container(Messages.ERR_READ_PROPDEF_1, name), e);
} finally {
dbc.clear();
}
return result;
}
use of org.opencms.file.CmsPropertyDefinition in project opencms-core by alkacon.
the class CmsCmisTypeManager method getCmsPropertyNames.
/**
* Gets a list of names of OpenCms property definitions.<p>
*
* @return the list of OpenCms property names
*/
public List<String> getCmsPropertyNames() {
refresh();
List<String> result = new ArrayList<String>();
for (CmsPropertyDefinition propDef : m_cmsPropertyDefinitions) {
result.add(propDef.getName());
}
return result;
}
use of org.opencms.file.CmsPropertyDefinition in project opencms-core by alkacon.
the class CmsCmisTypeManager method addCmsPropertyDefinitions.
/**
* Adds the CMIS property definitions corresponding to the OpenCms property definitions to a CMIS type definition.<p>
*
* @param type the type to which the property definitions should be added
*/
private void addCmsPropertyDefinitions(AbstractTypeDefinition type) {
for (CmsPropertyDefinition propDef : m_cmsPropertyDefinitions) {
type.addPropertyDefinition(createOpenCmsPropertyDefinition(propDef));
type.addPropertyDefinition(createPropDef(INHERITED_PREFIX + propDef.getName(), propDef.getName(), propDef.getName(), PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, false, false));
}
type.addPropertyDefinition(createPropDef(PROPERTY_RESOURCE_TYPE, "Resource type", "Resource type", PropertyType.STRING, Cardinality.SINGLE, Updatability.ONCREATE, false, true));
}
use of org.opencms.file.CmsPropertyDefinition in project opencms-core by alkacon.
the class CmsVfsDriver method readPropertyDefinition.
/**
* @see org.opencms.db.I_CmsVfsDriver#readPropertyDefinition(org.opencms.db.CmsDbContext, java.lang.String, CmsUUID)
*/
public CmsPropertyDefinition readPropertyDefinition(CmsDbContext dbc, String name, CmsUUID projectId) throws CmsDataAccessException {
CmsPropertyDefinition propDef = null;
ResultSet res = null;
PreparedStatement stmt = null;
Connection conn = null;
try {
conn = m_sqlManager.getConnection(dbc);
stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_PROPERTYDEF_READ");
stmt.setString(1, name);
res = stmt.executeQuery();
// if result set exists - return it
if (res.next()) {
propDef = new CmsPropertyDefinition(new CmsUUID(res.getString(m_sqlManager.readQuery("C_PROPERTYDEF_ID"))), res.getString(m_sqlManager.readQuery("C_PROPERTYDEF_NAME")), CmsPropertyDefinition.CmsPropertyType.valueOf(res.getInt(m_sqlManager.readQuery("C_PROPERTYDEF_TYPE"))));
while (res.next()) {
// do nothing only move through all rows because of mssql odbc driver
}
} else {
throw new CmsDbEntryNotFoundException(Messages.get().container(Messages.ERR_NO_PROPERTYDEF_WITH_NAME_1, name));
}
} catch (SQLException e) {
throw new CmsDbSqlException(Messages.get().container(Messages.ERR_GENERIC_SQL_1, CmsDbSqlException.getErrorQuery(stmt)), e);
} finally {
m_sqlManager.closeAll(dbc, conn, stmt, res);
}
return propDef;
}
Aggregations