protected void populateExpandoAttributes( ExpandoBridge expandoBridge, Map<String, String[]> expandoAttributes) { for (Map.Entry<String, String[]> expandoAttribute : expandoAttributes.entrySet()) { String name = expandoAttribute.getKey(); if (!expandoBridge.hasAttribute(name)) { continue; } int type = expandoBridge.getAttributeType(name); Serializable value = ExpandoConverterUtil.getAttributeFromStringArray(type, expandoAttribute.getValue()); try { ExpandoValueLocalServiceUtil.addValue( expandoBridge.getCompanyId(), expandoBridge.getClassName(), ExpandoTableConstants.DEFAULT_TABLE_NAME, name, expandoBridge.getClassPK(), value); } catch (Exception e) { _log.error(e, e); } } }
protected void readExpandoTables(PortletDataContext portletDataContext) throws Exception { String xml = portletDataContext.getZipEntryAsString( portletDataContext.getSourceRootPath() + "/expando-tables.xml"); if (xml == null) { return; } Document document = SAXReaderUtil.read(xml); Element rootElement = document.getRootElement(); List<Element> expandoTableElements = rootElement.elements("expando-table"); for (Element expandoTableElement : expandoTableElements) { String className = expandoTableElement.attributeValue("class-name"); ExpandoTable expandoTable = null; try { expandoTable = ExpandoTableLocalServiceUtil.getDefaultTable( portletDataContext.getCompanyId(), className); } catch (NoSuchTableException nste) { expandoTable = ExpandoTableLocalServiceUtil.addDefaultTable( portletDataContext.getCompanyId(), className); } List<Element> expandoColumnElements = expandoTableElement.elements("expando-column"); for (Element expandoColumnElement : expandoColumnElements) { long columnId = GetterUtil.getLong(expandoColumnElement.attributeValue("column-id")); String name = expandoColumnElement.attributeValue("name"); int type = GetterUtil.getInteger(expandoColumnElement.attributeValue("type")); String defaultData = expandoColumnElement.elementText("default-data"); String typeSettings = expandoColumnElement.elementText("type-settings"); Serializable defaultDataObject = ExpandoConverterUtil.getAttributeFromString(type, defaultData); ExpandoColumn expandoColumn = null; try { expandoColumn = ExpandoColumnLocalServiceUtil.getColumn(expandoTable.getTableId(), name); ExpandoColumnLocalServiceUtil.updateColumn( expandoColumn.getColumnId(), name, type, defaultDataObject); } catch (NoSuchColumnException nsce) { expandoColumn = ExpandoColumnLocalServiceUtil.addColumn( expandoTable.getTableId(), name, type, defaultDataObject); } ExpandoColumnLocalServiceUtil.updateTypeSettings(expandoColumn.getColumnId(), typeSettings); portletDataContext.importPermissions( ExpandoColumn.class, columnId, expandoColumn.getColumnId()); } } }