/** * Encodes a property name to use it in a url. * * @param propertyName like dc:title, file:content.3.filename (?) */ public static String encodePropertyName(String propertyName) { if (propertyName == null) { return null; } String[] items = propertyName.split(":"); return join(items, "/"); }
/** * The given propertyName should have 'schema_name:property_name' format. * * @return <code>null</code> if any error occurs. */ public static Object getPropertyValue(DocumentModel doc, String propertyName) { try { String schemaName = getSchemaName(propertyName); String fieldName = getFieldName(propertyName); return doc.getProperty(schemaName, fieldName); } catch (PropertyException e) { log.warn("Error trying to get property " + propertyName + ". " + e.getMessage()); if (log.isDebugEnabled()) { log.debug(e); } return null; } }
public static String getFilename(DocumentModel doc, DocumentView docView) { String filename = docView.getParameter(FILENAME_KEY); if (filename == null) { // try to get it from document String propertyPath = docView.getParameter(FILE_PROPERTY_PATH_KEY); String propertyName = DocumentModelUtils.decodePropertyName(propertyPath); if (propertyName != null) { filename = (String) DocumentModelUtils.getPropertyValue(doc, propertyName + "/filename"); } } return filename; }
/** * Decodes a property path given in a url. * * @param propertyPath like dc:title file/content/3/filename (?) */ public static String decodePropertyName(String propertyPath) { if (propertyPath == null) { return null; } String[] items = propertyPath.split("/"); return join(items, "."); }