List of usage examples for com.liferay.portal.kernel.xml Element attributeValue
public String attributeValue(String name);
From source file:com.liferay.dynamic.data.mapping.web.internal.exportimport.data.handler.DDMStructureStagedModelDataHandler.java
License:Open Source License
@Override protected void doImportStagedModel(PortletDataContext portletDataContext, DDMStructure structure) throws Exception { long userId = portletDataContext.getUserId(structure.getUserUuid()); Map<Long, Long> structureIds = (Map<Long, Long>) portletDataContext .getNewPrimaryKeysMap(DDMStructure.class); long parentStructureId = MapUtil.getLong(structureIds, structure.getParentStructureId(), structure.getParentStructureId()); Map<String, String> structureKeys = (Map<String, String>) portletDataContext .getNewPrimaryKeysMap(DDMStructure.class + ".ddmStructureKey"); Element structureElement = portletDataContext.getImportDataElement(structure); DDMForm ddmForm = getImportDDMForm(portletDataContext, structureElement); importDDMDataProviderInstances(portletDataContext, structureElement, ddmForm); DDMFormLayout ddmFormLayout = getImportDDMFormLayout(portletDataContext, structureElement); ServiceContext serviceContext = portletDataContext.createServiceContext(structure); DDMStructure importedStructure = null; Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class); long targetGroupId = portletDataContext.getScopeGroupId(); if (groupIds.containsKey(structure.getGroupId())) { targetGroupId = groupIds.get(structure.getGroupId()); }//from ww w .j ava2 s. c o m if (portletDataContext.isDataStrategyMirror()) { Element element = portletDataContext.getImportDataStagedModelElement(structure); boolean preloaded = GetterUtil.getBoolean(element.attributeValue("preloaded")); DDMStructure existingStructure = fetchExistingStructure(structure.getUuid(), targetGroupId, structure.getClassNameId(), structure.getStructureKey(), preloaded); if (existingStructure == null) { serviceContext.setUuid(structure.getUuid()); // Force a new structure key if a structure with the same key // already exists existingStructure = _ddmStructureLocalService.fetchStructure(targetGroupId, structure.getClassNameId(), structure.getStructureKey()); if (existingStructure != null) { structure.setStructureKey(null); } importedStructure = _ddmStructureLocalService.addStructure(userId, targetGroupId, parentStructureId, structure.getClassNameId(), structure.getStructureKey(), structure.getNameMap(), structure.getDescriptionMap(), ddmForm, ddmFormLayout, structure.getStorageType(), structure.getType(), serviceContext); } else if (isModifiedStructure(existingStructure, structure)) { importedStructure = _ddmStructureLocalService.updateStructure(userId, existingStructure.getStructureId(), parentStructureId, structure.getNameMap(), structure.getDescriptionMap(), ddmForm, ddmFormLayout, serviceContext); } else { if (_log.isDebugEnabled()) { _log.debug("Not importing DDM structure with key " + structure.getStructureKey() + " since it was not modified"); } importedStructure = existingStructure; } } else { importedStructure = _ddmStructureLocalService.addStructure(userId, targetGroupId, parentStructureId, structure.getClassNameId(), null, structure.getNameMap(), structure.getDescriptionMap(), ddmForm, ddmFormLayout, structure.getStorageType(), structure.getType(), serviceContext); } portletDataContext.importClassedModel(structure, importedStructure); structureKeys.put(structure.getStructureKey(), importedStructure.getStructureKey()); }
From source file:com.liferay.dynamic.data.mapping.web.internal.exportimport.data.handler.DDMStructureStagedModelDataHandler.java
License:Open Source License
protected DDMForm getImportDDMForm(PortletDataContext portletDataContext, Element structureElement) throws PortalException { String ddmFormPath = structureElement.attributeValue("ddm-form-path"); String serializedDDMForm = portletDataContext.getZipEntryAsString(ddmFormPath); return _ddmFormJSONDeserializer.deserialize(serializedDDMForm); }
From source file:com.liferay.dynamic.data.mapping.web.internal.exportimport.data.handler.DDMStructureStagedModelDataHandler.java
License:Open Source License
protected DDMFormLayout getImportDDMFormLayout(PortletDataContext portletDataContext, Element structureElement) throws PortalException { String ddmFormLayoutPath = structureElement.attributeValue("ddm-form-layout-path"); String serializedDDMFormLayout = portletDataContext.getZipEntryAsString(ddmFormLayoutPath); return _ddmFormLayoutJSONDeserializer.deserialize(serializedDDMFormLayout); }
From source file:com.liferay.dynamic.data.mapping.web.internal.exportimport.data.handler.DDMStructureStagedModelDataHandler.java
License:Open Source License
protected void importDDMDataProviderInstances(PortletDataContext portletDataContext, Element structureElement, DDMForm ddmForm) throws PortletDataException { String[] ddmDataProviderInstanceIds = StringUtil .split(structureElement.attributeValue(_DDM_DATA_PROVIDER_INSTANCE_IDS)); if (ArrayUtil.isEmpty(ddmDataProviderInstanceIds)) { return;/*from w w w . j a v a 2 s . c o m*/ } Map<Long, Long> dataProviderInstanceIdsMap = (Map<Long, Long>) portletDataContext .getNewPrimaryKeysMap(DDMDataProviderInstance.class); for (String ddmDataProviderInstanceId : ddmDataProviderInstanceIds) { long oldDDMDataProviderInstanceId = Long.parseLong(ddmDataProviderInstanceId); long newDDMDataProviderInstanceId = MapUtil.getLong(dataProviderInstanceIdsMap, oldDDMDataProviderInstanceId); StagedModelDataHandlerUtil.importReferenceStagedModel(portletDataContext, DDMDataProviderInstance.class, newDDMDataProviderInstanceId); } List<DDMFormField> ddmFormFields = ddmForm.getDDMFormFields(); for (DDMFormField ddmFormField : ddmFormFields) { if (!ddmFormField.getType().equals(DDMFormFieldType.SELECT)) { continue; } long oldDDMDataProviderInstanceId = Long .valueOf(String.valueOf(ddmFormField.getProperty("ddmDataProviderInstanceId"))); long newDDMDataProviderInstanceId = MapUtil.getLong(dataProviderInstanceIdsMap, oldDDMDataProviderInstanceId); ddmFormField.setProperty("ddmDataProviderInstanceId", newDDMDataProviderInstanceId); } }
From source file:com.liferay.dynamic.data.mapping.web.internal.exportimport.data.handler.DDMTemplateStagedModelDataHandler.java
License:Open Source License
@Override public boolean validateReference(PortletDataContext portletDataContext, Element referenceElement) { validateMissingGroupReference(portletDataContext, referenceElement); String uuid = referenceElement.attributeValue("uuid"); Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class); long groupId = GetterUtil.getLong(referenceElement.attributeValue("group-id")); groupId = MapUtil.getLong(groupIds, groupId); long classNameId = _portal.getClassNameId(referenceElement.attributeValue("referenced-class-name")); String templateKey = referenceElement.attributeValue("template-key"); boolean preloaded = GetterUtil.getBoolean(referenceElement.attributeValue("preloaded")); DDMTemplate existingTemplate = fetchExistingTemplate(uuid, groupId, classNameId, templateKey, preloaded); if (existingTemplate == null) { return false; }/*from w ww. ja v a 2 s.c o m*/ return true; }
From source file:com.liferay.dynamic.data.mapping.web.internal.exportimport.data.handler.DDMTemplateStagedModelDataHandler.java
License:Open Source License
@Override protected void doImportMissingReference(PortletDataContext portletDataContext, Element referenceElement) throws PortletDataException { importMissingGroupReference(portletDataContext, referenceElement); String uuid = referenceElement.attributeValue("uuid"); Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class); long groupId = GetterUtil.getLong(referenceElement.attributeValue("group-id")); groupId = MapUtil.getLong(groupIds, groupId); long classNameId = _portal.getClassNameId(referenceElement.attributeValue("referenced-class-name")); String templateKey = referenceElement.attributeValue("template-key"); boolean preloaded = GetterUtil.getBoolean(referenceElement.attributeValue("preloaded")); DDMTemplate existingTemplate = null; existingTemplate = fetchExistingTemplate(uuid, groupId, classNameId, templateKey, preloaded); Map<Long, Long> templateIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(DDMTemplate.class); long templateId = GetterUtil.getLong(referenceElement.attributeValue("class-pk")); templateIds.put(templateId, existingTemplate.getTemplateId()); Map<String, String> templateKeys = (Map<String, String>) portletDataContext .getNewPrimaryKeysMap(DDMTemplate.class + ".ddmTemplateKey"); templateKeys.put(templateKey, existingTemplate.getTemplateKey()); }
From source file:com.liferay.dynamic.data.mapping.web.internal.exportimport.data.handler.DDMTemplateStagedModelDataHandler.java
License:Open Source License
@Override protected void doImportStagedModel(PortletDataContext portletDataContext, DDMTemplate template) throws Exception { long userId = portletDataContext.getUserId(template.getUserUuid()); long classPK = template.getClassPK(); if (classPK > 0) { Map<Long, Long> structureIds = (Map<Long, Long>) portletDataContext .getNewPrimaryKeysMap(DDMStructure.class); classPK = MapUtil.getLong(structureIds, classPK, classPK); }/*from w w w .j a v a 2 s .c om*/ Element element = portletDataContext.getImportDataStagedModelElement(template); File smallFile = null; try { if (template.isSmallImage()) { String smallImagePath = element.attributeValue("small-image-path"); if (Validator.isNotNull(template.getSmallImageURL())) { String smallImageURL = _ddmTemplateExportImportContentProcessor.replaceImportContentReferences( portletDataContext, template, template.getSmallImageURL()); template.setSmallImageURL(smallImageURL); } else if (Validator.isNotNull(smallImagePath)) { byte[] bytes = portletDataContext.getZipEntryAsByteArray(smallImagePath); if (bytes != null) { smallFile = FileUtil.createTempFile(template.getSmallImageType()); FileUtil.write(smallFile, bytes); } } } String script = _ddmTemplateExportImportContentProcessor .replaceImportContentReferences(portletDataContext, template, template.getScript()); template.setScript(script); long resourceClassNameId = 0L; if (template.getResourceClassNameId() > 0) { String resourceClassName = element.attributeValue("resource-class-name"); if (Validator.isNotNull(resourceClassName)) { resourceClassNameId = _portal.getClassNameId(resourceClassName); } } ServiceContext serviceContext = portletDataContext.createServiceContext(template); DDMTemplate importedTemplate = null; if (portletDataContext.isDataStrategyMirror()) { boolean preloaded = GetterUtil.getBoolean(element.attributeValue("preloaded")); DDMTemplate existingTemplate = fetchExistingTemplate(template.getUuid(), portletDataContext.getScopeGroupId(), template.getClassNameId(), template.getTemplateKey(), preloaded); if (existingTemplate == null) { serviceContext.setUuid(template.getUuid()); // Force a new template key if a template with the same key // already exists existingTemplate = _ddmTemplateLocalService.fetchTemplate(portletDataContext.getScopeGroupId(), template.getClassNameId(), template.getTemplateKey()); if (existingTemplate != null) { template.setTemplateKey(null); } importedTemplate = _ddmTemplateLocalService.addTemplate(userId, portletDataContext.getScopeGroupId(), template.getClassNameId(), classPK, resourceClassNameId, template.getTemplateKey(), template.getNameMap(), template.getDescriptionMap(), template.getType(), template.getMode(), template.getLanguage(), template.getScript(), template.isCacheable(), template.isSmallImage(), template.getSmallImageURL(), smallFile, serviceContext); } else { importedTemplate = _ddmTemplateLocalService.updateTemplate(userId, existingTemplate.getTemplateId(), classPK, template.getNameMap(), template.getDescriptionMap(), template.getType(), template.getMode(), template.getLanguage(), template.getScript(), template.isCacheable(), template.isSmallImage(), template.getSmallImageURL(), smallFile, serviceContext); } } else { importedTemplate = _ddmTemplateLocalService.addTemplate(userId, portletDataContext.getScopeGroupId(), template.getClassNameId(), classPK, resourceClassNameId, null, template.getNameMap(), template.getDescriptionMap(), template.getType(), template.getMode(), template.getLanguage(), template.getScript(), template.isCacheable(), template.isSmallImage(), template.getSmallImageURL(), smallFile, serviceContext); } portletDataContext.importClassedModel(template, importedTemplate); Map<String, String> ddmTemplateKeys = (Map<String, String>) portletDataContext .getNewPrimaryKeysMap(DDMTemplate.class + ".ddmTemplateKey"); ddmTemplateKeys.put(template.getTemplateKey(), importedTemplate.getTemplateKey()); } finally { if (smallFile != null) { smallFile.delete(); } } }
From source file:com.liferay.exportimport.content.processor.base.BaseTextExportImportContentProcessor.java
License:Open Source License
protected String replaceImportDLReferences(PortletDataContext portletDataContext, StagedModel stagedModel, String content) throws Exception { List<Element> referenceElements = portletDataContext.getReferenceElements(stagedModel, DLFileEntry.class); for (Element referenceElement : referenceElements) { long classPK = GetterUtil.getLong(referenceElement.attributeValue("class-pk")); Element referenceDataElement = portletDataContext.getReferenceDataElement(stagedModel, DLFileEntry.class, classPK); String path = null;//from w w w . ja va2 s. c o m if (referenceDataElement != null) { path = referenceDataElement.attributeValue("path"); } long groupId = GetterUtil.getLong(referenceElement.attributeValue("group-id")); if (Validator.isNull(path)) { String className = referenceElement.attributeValue("class-name"); path = ExportImportPathUtil.getModelPath(groupId, className, classPK); } if (!content.contains("[$dl-reference=" + path + "$]")) { continue; } try { StagedModelDataHandlerUtil.importReferenceStagedModel(portletDataContext, stagedModel, DLFileEntry.class, classPK); } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e, e); } else if (_log.isWarnEnabled()) { StringBundler sb = new StringBundler(6); sb.append("Unable to process file entry "); sb.append(classPK); sb.append(" for "); sb.append(stagedModel.getModelClassName()); sb.append(" with primary key "); sb.append(stagedModel.getPrimaryKeyObj()); _log.warn(sb.toString()); } } Map<Long, Long> dlFileEntryIds = (Map<Long, Long>) portletDataContext .getNewPrimaryKeysMap(DLFileEntry.class); long fileEntryId = MapUtil.getLong(dlFileEntryIds, classPK, classPK); int beginPos = content.indexOf("[$dl-reference=" + path); int endPos = content.indexOf("$]", beginPos) + 2; FileEntry importedFileEntry = null; try { importedFileEntry = DLAppLocalServiceUtil.getFileEntry(fileEntryId); } catch (PortalException pe) { if (_log.isDebugEnabled()) { _log.debug(pe, pe); } else if (_log.isWarnEnabled()) { _log.warn(pe.getMessage()); } if (content.startsWith("[#dl-reference=", endPos)) { int prefixPos = endPos + "[#dl-reference=".length(); int postfixPos = content.indexOf("#]", prefixPos); String originalReference = content.substring(prefixPos, postfixPos); String exportedReference = content.substring(beginPos, postfixPos + 2); content = StringUtil.replace(content, exportedReference, originalReference); } continue; } String url = DLUtil.getPreviewURL(importedFileEntry, importedFileEntry.getFileVersion(), null, StringPool.BLANK, false, false); if (url.contains(StringPool.QUESTION)) { content = StringUtil.replace(content, "$]?", "$]&"); } String exportedReference = "[$dl-reference=" + path + "$]"; if (content.startsWith("[#dl-reference=", endPos)) { endPos = content.indexOf("#]", beginPos) + 2; exportedReference = content.substring(beginPos, endPos); } content = StringUtil.replace(content, exportedReference, url); } return content; }
From source file:com.liferay.exportimport.controller.LayoutImportController.java
License:Open Source License
protected void deletePortletData(PortletDataContext portletDataContext) throws Exception { List<Element> portletElements = fetchPortletElements(portletDataContext.getImportDataRootElement()); Map<Long, Layout> layouts = (Map<Long, Layout>) portletDataContext .getNewPrimaryKeysMap(Layout.class + ".layout"); if (_log.isDebugEnabled()) { if (!portletElements.isEmpty()) { _log.debug("Deleting portlet data"); }/*from ww w. j a va 2s . co m*/ } for (Element portletElement : portletElements) { long layoutId = GetterUtil.getLong(portletElement.attributeValue("layout-id")); long plid = LayoutConstants.DEFAULT_PLID; Layout layout = layouts.get(layoutId); if (layout != null) { plid = layout.getPlid(); } portletDataContext.setPlid(plid); portletDataContext.setPortletId(portletElement.attributeValue("portlet-id")); _portletImportController.deletePortletData(portletDataContext); } }
From source file:com.liferay.exportimport.controller.LayoutImportController.java
License:Open Source License
protected void doImportFile(PortletDataContext portletDataContext, long userId) throws Exception { Map<String, String[]> parameterMap = portletDataContext.getParameterMap(); Group group = _groupLocalService.getGroup(portletDataContext.getGroupId()); String layoutsImportMode = MapUtil.getString(parameterMap, PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE, PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_UUID); boolean permissions = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PERMISSIONS); if (group.isLayoutSetPrototype()) { parameterMap.put(PortletDataHandlerKeys.LAYOUT_SET_PROTOTYPE_LINK_ENABLED, new String[] { Boolean.FALSE.toString() }); }/* ww w .ja va2 s. c o m*/ if (_log.isDebugEnabled()) { _log.debug("Import permissions " + permissions); } StopWatch stopWatch = new StopWatch(); stopWatch.start(); LayoutCache layoutCache = new LayoutCache(); long companyId = portletDataContext.getCompanyId(); ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); if (serviceContext == null) { serviceContext = new ServiceContext(); } serviceContext.setCompanyId(companyId); serviceContext.setSignedIn(false); serviceContext.setUserId(userId); ServiceContextThreadLocal.pushServiceContext(serviceContext); // LAR validation validateFile(companyId, portletDataContext.getGroupId(), parameterMap, portletDataContext.getZipReader()); // Source and target group id Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class); groupIds.put(portletDataContext.getSourceGroupId(), portletDataContext.getGroupId()); // Manifest ManifestSummary manifestSummary = _exportImportHelper.getManifestSummary(portletDataContext); portletDataContext.setManifestSummary(manifestSummary); // Layout and layout set prototype Element rootElement = portletDataContext.getImportDataRootElement(); Element headerElement = rootElement.element("header"); String layoutSetPrototypeUuid = headerElement.attributeValue("layout-set-prototype-uuid"); String larType = headerElement.attributeValue("type"); portletDataContext.setType(larType); if (group.isLayoutPrototype() && larType.equals("layout-prototype")) { parameterMap.put(PortletDataHandlerKeys.DELETE_MISSING_LAYOUTS, new String[] { Boolean.FALSE.toString() }); LayoutPrototype layoutPrototype = _layoutPrototypeLocalService.getLayoutPrototype(group.getClassPK()); String layoutPrototypeUuid = GetterUtil.getString(headerElement.attributeValue("type-uuid")); LayoutPrototype existingLayoutPrototype = null; if (Validator.isNotNull(layoutPrototypeUuid)) { try { existingLayoutPrototype = _layoutPrototypeLocalService .getLayoutPrototypeByUuidAndCompanyId(layoutPrototypeUuid, companyId); } catch (NoSuchLayoutPrototypeException nslpe) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(nslpe, nslpe); } } } if (existingLayoutPrototype == null) { List<Layout> layouts = _layoutLocalService .getLayoutsByLayoutPrototypeUuid(layoutPrototype.getUuid()); layoutPrototype.setUuid(layoutPrototypeUuid); _layoutPrototypeLocalService.updateLayoutPrototype(layoutPrototype); for (Layout layout : layouts) { layout.setLayoutPrototypeUuid(layoutPrototypeUuid); _layoutLocalService.updateLayout(layout); } } } else if (group.isLayoutSetPrototype() && larType.equals("layout-set-prototype")) { parameterMap.put(PortletDataHandlerKeys.LAYOUT_SET_PROTOTYPE_SETTINGS, new String[] { Boolean.TRUE.toString() }); LayoutSetPrototype layoutSetPrototype = _layoutSetPrototypeLocalService .getLayoutSetPrototype(group.getClassPK()); String importedLayoutSetPrototypeUuid = GetterUtil.getString(headerElement.attributeValue("type-uuid")); LayoutSetPrototype existingLayoutSetPrototype = null; if (Validator.isNotNull(importedLayoutSetPrototypeUuid)) { try { existingLayoutSetPrototype = _layoutSetPrototypeLocalService .getLayoutSetPrototypeByUuidAndCompanyId(importedLayoutSetPrototypeUuid, companyId); } catch (NoSuchLayoutSetPrototypeException nslspe) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(nslspe, nslspe); } } } if (existingLayoutSetPrototype == null) { List<LayoutSet> layoutSets = _layoutSetLocalService .getLayoutSetsByLayoutSetPrototypeUuid(layoutSetPrototype.getUuid()); layoutSetPrototype.setUuid(importedLayoutSetPrototypeUuid); _layoutSetPrototypeLocalService.updateLayoutSetPrototype(layoutSetPrototype); for (LayoutSet curLayoutSet : layoutSets) { curLayoutSet.setLayoutSetPrototypeUuid(importedLayoutSetPrototypeUuid); _layoutSetLocalService.updateLayoutSet(curLayoutSet); } } } else if (larType.equals("layout-set-prototype")) { parameterMap.put(PortletDataHandlerKeys.LAYOUT_SET_PROTOTYPE_SETTINGS, new String[] { Boolean.TRUE.toString() }); layoutSetPrototypeUuid = GetterUtil.getString(headerElement.attributeValue("type-uuid")); } if (Validator.isNotNull(layoutSetPrototypeUuid)) { portletDataContext.setLayoutSetPrototypeUuid(layoutSetPrototypeUuid); } List<Element> portletElements = fetchPortletElements(rootElement); if (permissions) { for (Element portletElement : portletElements) { String portletPath = portletElement.attributeValue("path"); Document portletDocument = SAXReaderUtil.read(portletDataContext.getZipEntryAsString(portletPath)); _permissionImporter.checkRoles(layoutCache, companyId, portletDataContext.getGroupId(), userId, portletDocument.getRootElement()); } _permissionImporter.readPortletDataPermissions(portletDataContext); } if (!layoutsImportMode.equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) { _portletImportController.readExpandoTables(portletDataContext); } _portletImportController.readLocks(portletDataContext); // Import the group Element groupsElement = portletDataContext.getImportDataGroupElement(StagedGroup.class); for (Element groupElement : groupsElement.elements()) { StagedModelDataHandlerUtil.importStagedModel(portletDataContext, groupElement); } // Asset links _portletImportController.importAssetLinks(portletDataContext); // Site _groupLocalService.updateSite(portletDataContext.getGroupId(), true); if (_log.isInfoEnabled()) { _log.info("Importing layouts takes " + stopWatch.getTime() + " ms"); } ZipReader zipReader = portletDataContext.getZipReader(); zipReader.close(); }