List of usage examples for com.liferay.portal.kernel.xml Element attributeValue
public String attributeValue(String name);
From source file:com.liferay.exportimport.internal.content.processor.DLReferencesExportImportContentProcessor.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 ww . j av a 2 s .co 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 = _dlAppLocalService.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.lar.DeletionSystemEventImporter.java
License:Open Source License
protected void doImportDeletionSystemEvents(PortletDataContext portletDataContext, Element element) { StagedModelType stagedModelType = new StagedModelType(element.attributeValue("class-name"), element.attributeValue("referrer-class-name")); if (!_shouldImportDeletionSystemEvent(portletDataContext, stagedModelType)) { return;// w w w.ja v a2s . c o m } try { StagedModelDataHandlerUtil.deleteStagedModel(portletDataContext, element); } catch (Exception e) { if (_log.isWarnEnabled()) { StringBundler sb = new StringBundler(4); sb.append("Unable to process deletion for "); sb.append(stagedModelType); sb.append(" with UUID "); sb.append(element.attributeValue("uuid")); _log.warn(sb.toString()); } } }
From source file:com.liferay.exportimport.lar.ExportImportHelperImpl.java
License:Open Source License
@Override public void setPortletScope(PortletDataContext portletDataContext, Element portletElement) { // Portlet data scope String scopeLayoutUuid = GetterUtil.getString(portletElement.attributeValue("scope-layout-uuid")); String scopeLayoutType = GetterUtil.getString(portletElement.attributeValue("scope-layout-type")); portletDataContext.setScopeLayoutUuid(scopeLayoutUuid); portletDataContext.setScopeType(scopeLayoutType); // Layout scope try {//from w ww . ja va2s . c o m Group scopeGroup = null; if (scopeLayoutType.equals("company")) { scopeGroup = _groupLocalService.getCompanyGroup(portletDataContext.getCompanyId()); } else if (Validator.isNotNull(scopeLayoutUuid)) { Layout scopeLayout = _layoutLocalService.getLayoutByUuidAndGroupId(scopeLayoutUuid, portletDataContext.getGroupId(), portletDataContext.isPrivateLayout()); scopeGroup = _groupLocalService.checkScopeGroup(scopeLayout, portletDataContext.getUserId(null)); Group group = scopeLayout.getGroup(); if (group.isStaged() && !group.isStagedRemotely()) { try { boolean privateLayout = GetterUtil .getBoolean(portletElement.attributeValue("private-layout")); Layout oldLayout = _layoutLocalService.getLayoutByUuidAndGroupId(scopeLayoutUuid, portletDataContext.getSourceGroupId(), privateLayout); Group oldScopeGroup = oldLayout.getScopeGroup(); if (group.isStagingGroup()) { scopeGroup.setLiveGroupId(oldScopeGroup.getGroupId()); _groupLocalService.updateGroup(scopeGroup); } else { oldScopeGroup.setLiveGroupId(scopeGroup.getGroupId()); _groupLocalService.updateGroup(oldScopeGroup); } } catch (NoSuchLayoutException nsle) { if (_log.isWarnEnabled()) { _log.warn(nsle); } } } if (!ExportImportThreadLocal.isStagingInProcess() && group.isStagingGroup() && !group.isStagedPortlet(portletDataContext.getPortletId())) { scopeGroup = group.getLiveGroup(); Layout scopeLiveLayout = _layoutLocalService.fetchLayoutByUuidAndGroupId(scopeLayoutUuid, group.getLiveGroupId(), portletDataContext.isPrivateLayout()); if (scopeLiveLayout != null) { scopeGroup = _groupLocalService.checkScopeGroup(scopeLiveLayout, portletDataContext.getUserId(null)); } } } else { Group group = _groupLocalService.getGroup(portletDataContext.getGroupId()); if (!ExportImportThreadLocal.isStagingInProcess() && group.isStagingGroup() && !group.isStagedPortlet(portletDataContext.getPortletId())) { scopeGroup = group.getLiveGroup(); } } if (scopeGroup != null) { portletDataContext.setScopeGroupId(scopeGroup.getGroupId()); Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class); long oldScopeGroupId = GetterUtil.getLong(portletElement.attributeValue("scope-group-id")); groupIds.put(oldScopeGroupId, scopeGroup.getGroupId()); } } catch (PortalException pe) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(pe, pe); } } catch (Exception e) { _log.error(e, e); } }
From source file:com.liferay.exportimport.lar.ExportImportHelperImpl.java
License:Open Source License
protected MissingReference validateMissingReference(PortletDataContext portletDataContext, Element element) { // Missing reference is exported after added as missing if (Validator.isNotNull(element.attributeValue("element-path"))) { return null; }/*from ww w.j a v a2 s. c o m*/ String className = element.attributeValue("class-name"); StagedModelDataHandler<?> stagedModelDataHandler = StagedModelDataHandlerRegistryUtil .getStagedModelDataHandler(className); if (!stagedModelDataHandler.validateReference(portletDataContext, element)) { MissingReference missingReference = new MissingReference(element); Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class); long groupId = MapUtil.getLong(groupIds, GetterUtil.getLong(element.attributeValue("group-id"))); missingReference.setGroupId(groupId); return missingReference; } return null; }
From source file:com.liferay.exportimport.lar.PermissionImporter.java
License:Open Source License
public void readPortletDataPermissions(PortletDataContext portletDataContext) throws Exception { String xml = portletDataContext.getZipEntryAsString( ExportImportPathUtil.getSourceRootPath(portletDataContext) + "/portlet-data-permissions.xml"); if (xml == null) { return;//from ww w . j a v a 2s.c o m } Document document = SAXReaderUtil.read(xml); Element rootElement = document.getRootElement(); List<Element> portletDataElements = rootElement.elements("portlet-data"); for (Element portletDataElement : portletDataElements) { String resourceName = portletDataElement.attributeValue("resource-name"); long resourcePK = GetterUtil.getLong(portletDataElement.attributeValue("resource-pk")); List<KeyValuePair> permissions = new ArrayList<>(); List<Element> permissionsElements = portletDataElement.elements("permissions"); for (Element permissionsElement : permissionsElements) { String roleName = permissionsElement.attributeValue("role-name"); String actions = permissionsElement.attributeValue("actions"); KeyValuePair permission = new KeyValuePair(roleName, actions); permissions.add(permission); } portletDataContext.addPermissions(resourceName, resourcePK, permissions); } }
From source file:com.liferay.exportimport.lar.PermissionImporter.java
License:Open Source License
protected Role checkRole(LayoutCache layoutCache, long companyId, long groupId, long userId, Element roleElement) throws Exception { String name = roleElement.attributeValue("name"); Role role = null;// w ww . j a v a2 s . com if (ExportImportPermissionUtil.isTeamRoleName(name)) { name = name.substring(ExportImportPermissionUtil.ROLE_TEAM_PREFIX.length()); String description = roleElement.attributeValue("description"); Team team = null; try { team = TeamLocalServiceUtil.getTeam(groupId, name); } catch (NoSuchTeamException nste) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(nste, nste); } team = TeamLocalServiceUtil.addTeam(userId, groupId, name, description, new ServiceContext()); } role = RoleLocalServiceUtil.getTeamRole(companyId, team.getTeamId()); return role; } String uuid = roleElement.attributeValue("uuid"); role = layoutCache.getUuidRole(companyId, uuid); if (role == null) { role = layoutCache.getNameRole(companyId, name); } if ((role != null) || MergeLayoutPrototypesThreadLocal.isInProgress()) { return role; } String title = roleElement.attributeValue("title"); Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(title); String description = roleElement.attributeValue("description"); Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(description); int type = GetterUtil.getInteger(roleElement.attributeValue("type")); String subtype = roleElement.attributeValue("subtype"); ServiceContext serviceContext = new ServiceContext(); serviceContext.setUuid(uuid); role = RoleLocalServiceUtil.addRole(userId, null, 0, name, titleMap, descriptionMap, type, subtype, serviceContext); return role; }
From source file:com.liferay.exportimport.lar.PortletDataContextFactoryImpl.java
License:Open Source License
protected void readXML(PortletDataContext portletDataContext) throws PortletDataException { String xml = portletDataContext.getZipEntryAsString("/manifest.xml"); Element rootElement = null;/* w w w . java 2 s . c o m*/ try { Document document = SAXReaderUtil.read(xml); rootElement = document.getRootElement(); } catch (Exception e) { throw new PortletDataException("Unable to create portlet data context for the import " + "process because of an invalid LAR manifest", e); } portletDataContext.setImportDataRootElement(rootElement); Element headerElement = rootElement.element("header"); long sourceCompanyId = GetterUtil.getLong(headerElement.attributeValue("company-id")); portletDataContext.setSourceCompanyId(sourceCompanyId); long sourceCompanyGroupId = GetterUtil.getLong(headerElement.attributeValue("company-group-id")); portletDataContext.setSourceCompanyGroupId(sourceCompanyGroupId); long sourceGroupId = GetterUtil.getLong(headerElement.attributeValue("group-id")); portletDataContext.setSourceGroupId(sourceGroupId); long sourceUserPersonalSiteGroupId = GetterUtil .getLong(headerElement.attributeValue("user-personal-site-group-id")); portletDataContext.setSourceUserPersonalSiteGroupId(sourceUserPersonalSiteGroupId); Element missingReferencesElement = rootElement.element("missing-references"); if (missingReferencesElement != null) { portletDataContext.setMissingReferencesElement(missingReferencesElement); } }
From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java
License:Open Source License
@Override public boolean isMissingReference(Element referenceElement) { Attribute missingAttribute = referenceElement.attribute("missing"); if ((missingAttribute != null) && !GetterUtil.getBoolean(referenceElement.attributeValue("missing"))) { return false; }//from w w w. ja v a 2s . co m if (_missingReferences.isEmpty()) { List<Element> missingReferenceElements = _missingReferencesElement.elements(); for (Element missingReferenceElement : missingReferenceElements) { if (Validator.isNotNull(missingReferenceElement.attributeValue("element-path"))) { continue; } String missingReferenceClassName = missingReferenceElement.attributeValue("class-name"); String missingReferenceClassPK = missingReferenceElement.attributeValue("class-pk"); String missingReferenceKey = getReferenceKey(missingReferenceClassName, missingReferenceClassPK); _missingReferences.add(missingReferenceKey); } } String className = referenceElement.attributeValue("class-name"); String classPK = referenceElement.attributeValue("class-pk"); String referenceKey = getReferenceKey(className, classPK); return _missingReferences.contains(referenceKey); }
From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java
License:Open Source License
protected ServiceContext createServiceContext(Element element, String path, ClassedModel classedModel, Class<?> clazz) {//w ww.j a va2 s . c o m ServiceContext serviceContext = new ServiceContext(); // Theme display serviceContext.setCompanyId(getCompanyId()); serviceContext.setScopeGroupId(getScopeGroupId()); // Dates if (classedModel instanceof AuditedModel) { AuditedModel auditedModel = (AuditedModel) classedModel; serviceContext.setUserId(getUserId(auditedModel)); serviceContext.setCreateDate(auditedModel.getCreateDate()); serviceContext.setModifiedDate(auditedModel.getModifiedDate()); } // Permissions if (!MapUtil.getBoolean(_parameterMap, PortletDataHandlerKeys.PERMISSIONS)) { serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); } // Asset if (isResourceMain(classedModel)) { Serializable classPKObj = ExportImportClassedModelUtil.getPrimaryKeyObj(classedModel); long[] assetCategoryIds = getAssetCategoryIds(clazz, classPKObj); serviceContext.setAssetCategoryIds(assetCategoryIds); String[] assetTagNames = getAssetTagNames(clazz, classPKObj); serviceContext.setAssetTagNames(assetTagNames); } if (element != null) { Attribute assetPriorityAttribute = element.attribute("asset-entry-priority"); if (assetPriorityAttribute != null) { double assetPriority = GetterUtil.getDouble(assetPriorityAttribute.getValue()); serviceContext.setAssetPriority(assetPriority); } } // Expando String expandoPath = null; if (element != null) { expandoPath = element.attributeValue("expando-path"); } else { expandoPath = ExportImportPathUtil.getExpandoPath(path); } if (Validator.isNotNull(expandoPath)) { try { Map<String, Serializable> expandoBridgeAttributes = (Map<String, Serializable>) getZipEntryAsObject( expandoPath); if (expandoBridgeAttributes != null) { serviceContext.setExpandoBridgeAttributes(expandoBridgeAttributes); } } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e, e); } } } // Workflow if (classedModel instanceof WorkflowedModel) { WorkflowedModel workflowedModel = (WorkflowedModel) classedModel; if (workflowedModel.getStatus() == WorkflowConstants.STATUS_APPROVED) { serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); } else if (workflowedModel.getStatus() == WorkflowConstants.STATUS_DRAFT) { serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); } } return serviceContext; }
From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java
License:Open Source License
protected List<Element> getReferenceDataElements(List<Element> referenceElements, Class<?> clazz) { List<Element> referenceDataElements = new ArrayList<>(); for (Element referenceElement : referenceElements) { Element referenceDataElement = null; String path = referenceElement.attributeValue("path"); if (Validator.isNotNull(path)) { referenceDataElement = getImportDataElement(clazz.getSimpleName(), "path", path); } else {// ww w .j a va2 s .c om String groupId = referenceElement.attributeValue("group-id"); String uuid = referenceElement.attributeValue("uuid"); StringBuilder sb = new StringBuilder(5); sb.append("staged-model[@uuid="); sb.append(HtmlUtil.escapeXPathAttribute(uuid)); if (groupId != null) { sb.append(" and @group-id="); sb.append(HtmlUtil.escapeXPathAttribute(groupId)); } sb.append(StringPool.CLOSE_BRACKET); XPath xPath = SAXReaderUtil.createXPath(sb.toString()); Element groupElement = getImportDataGroupElement(clazz.getSimpleName()); referenceDataElement = (Element) xPath.selectSingleNode(groupElement); } if (referenceDataElement == null) { continue; } referenceDataElements.add(referenceDataElement); } return referenceDataElements; }