Search in sources :

Example 1 with CmsPropertyDefinition

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;
}
Also used : CmsFile(org.opencms.file.CmsFile) CmsProperty(org.opencms.file.CmsProperty) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CmsPropertyDefinition(org.opencms.file.CmsPropertyDefinition)

Example 2 with CmsPropertyDefinition

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;
}
Also used : CmsPropertyDefinition(org.opencms.file.CmsPropertyDefinition) CmsVfsException(org.opencms.file.CmsVfsException) CmsInitException(org.opencms.main.CmsInitException) CmsRoleViolationException(org.opencms.security.CmsRoleViolationException) CmsSecurityException(org.opencms.security.CmsSecurityException) CmsDataAccessException(org.opencms.file.CmsDataAccessException) CmsException(org.opencms.main.CmsException) CmsVfsResourceNotFoundException(org.opencms.file.CmsVfsResourceNotFoundException) CmsVfsResourceAlreadyExistsException(org.opencms.file.CmsVfsResourceAlreadyExistsException) CmsTooManyPublishResourcesException(org.opencms.ade.publish.CmsTooManyPublishResourcesException) CmsMultiException(org.opencms.main.CmsMultiException) CmsLockException(org.opencms.lock.CmsLockException) SQLException(java.sql.SQLException) CmsIllegalArgumentException(org.opencms.main.CmsIllegalArgumentException) CmsPermissionViolationException(org.opencms.security.CmsPermissionViolationException)

Example 3 with CmsPropertyDefinition

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;
}
Also used : ArrayList(java.util.ArrayList) CmsPropertyDefinition(org.opencms.file.CmsPropertyDefinition)

Example 4 with CmsPropertyDefinition

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));
}
Also used : CmsPropertyDefinition(org.opencms.file.CmsPropertyDefinition)

Example 5 with CmsPropertyDefinition

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;
}
Also used : CmsDbSqlException(org.opencms.db.CmsDbSqlException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) CmsUUID(org.opencms.util.CmsUUID) CmsDbEntryNotFoundException(org.opencms.db.CmsDbEntryNotFoundException) CmsPropertyDefinition(org.opencms.file.CmsPropertyDefinition)

Aggregations

CmsPropertyDefinition (org.opencms.file.CmsPropertyDefinition)27 CmsException (org.opencms.main.CmsException)11 ArrayList (java.util.ArrayList)10 CmsProperty (org.opencms.file.CmsProperty)8 SQLException (java.sql.SQLException)7 CmsObject (org.opencms.file.CmsObject)6 CmsUUID (org.opencms.util.CmsUUID)6 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 CmsDbSqlException (org.opencms.db.CmsDbSqlException)5 CmsDbEntryNotFoundException (org.opencms.db.CmsDbEntryNotFoundException)4 CmsDataAccessException (org.opencms.file.CmsDataAccessException)4 ResultSet (java.sql.ResultSet)3 CmsResource (org.opencms.file.CmsResource)3 CmsVfsResourceNotFoundException (org.opencms.file.CmsVfsResourceNotFoundException)3 CmsLockException (org.opencms.lock.CmsLockException)3 CmsEvent (org.opencms.main.CmsEvent)3 CmsIllegalArgumentException (org.opencms.main.CmsIllegalArgumentException)3 IndexedContainer (com.vaadin.v7.data.util.IndexedContainer)2 CmsTooManyPublishResourcesException (org.opencms.ade.publish.CmsTooManyPublishResourcesException)2