List of usage examples for com.liferay.portal.kernel.xml Element attributeValue
public String attributeValue(String name);
From source file:com.liferay.portlet.documentlibrary.lar.DLPortletDataHandlerImpl.java
License:Open Source License
protected static void importFileShortcut(PortletDataContext portletDataContext, Element fileShortcutElement) throws Exception { String path = fileShortcutElement.attributeValue("path"); if (!portletDataContext.isPathNotProcessed(path)) { return;// ww w .j av a2 s. c o m } DLFileShortcut fileShortcut = (DLFileShortcut) portletDataContext.getZipEntryAsObject(path); importFileShortcut(portletDataContext, fileShortcutElement, fileShortcut); }
From source file:com.liferay.portlet.documentlibrary.lar.DLPortletDataHandlerImpl.java
License:Open Source License
protected static void importFileShortcut(PortletDataContext portletDataContext, Element fileShortcutElement, DLFileShortcut fileShortcut) throws Exception { long userId = portletDataContext.getUserId(fileShortcut.getUserUuid()); Map<Long, Long> folderIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(DLFolder.class); long folderId = MapUtil.getLong(folderIds, fileShortcut.getFolderId(), fileShortcut.getFolderId()); long groupId = portletDataContext.getScopeGroupId(); if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { Folder folder = FolderUtil.findByPrimaryKey(folderId); groupId = folder.getRepositoryId(); }/*from ww w . j a va 2 s.co m*/ String fileEntryUuid = fileShortcutElement.attributeValue("file-entry-uuid"); FileEntry fileEntry = FileEntryUtil.fetchByUUID_R(fileEntryUuid, groupId); if (fileEntry == null) { if (_log.isWarnEnabled()) { _log.warn("Unable to fetch file entry {uuid=" + fileEntryUuid + ", groupId=" + groupId + "}"); } return; } long fileEntryId = fileEntry.getFileEntryId(); ServiceContext serviceContext = portletDataContext.createServiceContext(fileShortcutElement, fileShortcut, _NAMESPACE); DLFileShortcut importedFileShortcut = null; if (portletDataContext.isDataStrategyMirror()) { DLFileShortcut existingFileShortcut = DLFileShortcutUtil.fetchByUUID_G(fileShortcut.getUuid(), portletDataContext.getScopeGroupId()); if (existingFileShortcut == null) { serviceContext.setUuid(fileShortcut.getUuid()); importedFileShortcut = DLAppLocalServiceUtil.addFileShortcut(userId, groupId, folderId, fileEntryId, serviceContext); } else { importedFileShortcut = DLAppLocalServiceUtil.updateFileShortcut(userId, existingFileShortcut.getFileShortcutId(), folderId, fileEntryId, serviceContext); } } else { importedFileShortcut = DLAppLocalServiceUtil.addFileShortcut(userId, groupId, folderId, fileEntryId, serviceContext); } portletDataContext.importClassedModel(fileShortcut, importedFileShortcut, _NAMESPACE); }
From source file:com.liferay.portlet.documentlibrary.lar.DLPortletDataHandlerImpl.java
License:Open Source License
protected static void importFolderFileEntryTypes(PortletDataContext portletDataContext, Element folderElement, Folder folder, ServiceContext serviceContext) throws Exception { String[] fileEntryTypeUuids = StringUtil.split(folderElement.attributeValue("fileEntryTypeUuids")); List<Long> fileEntryTypeIds = new ArrayList<Long>(); String defaultFileEntryTypeUuid = GetterUtil .getString(folderElement.attributeValue("defaultFileEntryTypeUuid")); long defaultFileEntryTypeId = 0; for (String fileEntryTypeUuid : fileEntryTypeUuids) { DLFileEntryType dlFileEntryType = DLFileEntryTypeUtil.fetchByUUID_G(fileEntryTypeUuid, portletDataContext.getScopeGroupId()); if (dlFileEntryType == null) { continue; }/* w ww .java 2 s . c o m*/ fileEntryTypeIds.add(dlFileEntryType.getFileEntryTypeId()); if (defaultFileEntryTypeUuid.equals(dlFileEntryType.getUuid())) { defaultFileEntryTypeId = dlFileEntryType.getFileEntryTypeId(); } } DLFileEntryTypeLocalServiceUtil.updateFolderFileEntryTypes((DLFolder) folder.getModel(), fileEntryTypeIds, defaultFileEntryTypeId, serviceContext); }
From source file:com.liferay.portlet.documentlibrary.lar.DLPortletDataHandlerImpl.java
License:Open Source License
protected static void importMetaData(PortletDataContext portletDataContext, Element fileEntryElement, ServiceContext serviceContext) throws Exception { String fileEntryTypeUuid = fileEntryElement.attributeValue("fileEntryTypeUuid"); if (Validator.isNull(fileEntryTypeUuid)) { return;//from ww w. j ava 2 s.co m } DLFileEntryType dlFileEntryType = DLFileEntryTypeUtil.fetchByUUID_G(fileEntryTypeUuid, portletDataContext.getScopeGroupId()); if (dlFileEntryType == null) { serviceContext.setAttribute("fileEntryTypeId", -1); return; } serviceContext.setAttribute("fileEntryTypeId", dlFileEntryType.getFileEntryTypeId()); List<DDMStructure> ddmStructures = dlFileEntryType.getDDMStructures(); for (DDMStructure ddmStructure : ddmStructures) { Element structureFieldsElement = (Element) fileEntryElement.selectSingleNode( "structure-fields[@structureUuid='".concat(ddmStructure.getUuid()).concat("']")); if (structureFieldsElement == null) { continue; } String path = structureFieldsElement.attributeValue("path"); Fields fields = (Fields) portletDataContext.getZipEntryAsObject(path); serviceContext.setAttribute(Fields.class.getName() + ddmStructure.getStructureId(), fields); } }
From source file:com.liferay.portlet.documentlibrary.lar.DLPortletDataHandlerImpl.java
License:Open Source License
@Override protected PortletPreferences doImportData(PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences, String data) throws Exception { portletDataContext.importPermissions("com.liferay.portlet.documentlibrary", portletDataContext.getSourceGroupId(), portletDataContext.getScopeGroupId()); Document document = SAXReaderUtil.read(data); Element rootElement = document.getRootElement(); Element repositoriesElement = rootElement.element("repositories"); if (repositoriesElement != null) { List<Element> repositoryElements = repositoriesElement.elements("repository"); for (Element repositoryElement : repositoryElements) { importRepository(portletDataContext, repositoryElement); }/* w w w . j a v a 2s . c om*/ } Element repositoryEntriesElement = rootElement.element("repository-entries"); List<Element> repositoryEntryElements = repositoryEntriesElement.elements("repository-entry"); for (Element repositoryEntryElement : repositoryEntryElements) { importRepositoryEntry(portletDataContext, repositoryEntryElement); } Element fileEntryTypesElement = rootElement.element("file-entry-types"); List<Element> fileEntryTypeElements = fileEntryTypesElement.elements("file-entry-type"); for (Element fileEntryTypeElement : fileEntryTypeElements) { importFileEntryType(portletDataContext, fileEntryTypeElement); } Element foldersElement = rootElement.element("folders"); List<Element> folderElements = foldersElement.elements("folder"); for (Element folderElement : folderElements) { importFolder(portletDataContext, folderElement); } Element fileEntriesElement = rootElement.element("file-entries"); List<Element> fileEntryElements = fileEntriesElement.elements("file-entry"); for (Element fileEntryElement : fileEntryElements) { importFileEntry(portletDataContext, fileEntryElement); } if (portletDataContext.getBooleanParameter(_NAMESPACE, "shortcuts")) { List<Element> fileShortcutElements = rootElement.element("file-shortcuts").elements("file-shortcut"); for (Element fileShortcutElement : fileShortcutElements) { importFileShortcut(portletDataContext, fileShortcutElement); } } if (portletDataContext.getBooleanParameter(_NAMESPACE, "ranks")) { Element fileRanksElement = rootElement.element("file-ranks"); List<Element> fileRankElements = fileRanksElement.elements("file-rank"); for (Element fileRankElement : fileRankElements) { importFileRank(portletDataContext, fileRankElement); } } long rootFolderId = GetterUtil.getLong(rootElement.attributeValue("root-folder-id")); if (rootFolderId > 0) { Map<Long, Long> folderIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(DLFolder.class); rootFolderId = MapUtil.getLong(folderIds, rootFolderId, rootFolderId); portletPreferences.setValue("rootFolderId", String.valueOf(rootFolderId)); } return portletPreferences; }
From source file:com.liferay.portlet.documentlibrary.util.DLPreviewableProcessor.java
License:Open Source License
protected void importPreviewFromLAR(PortletDataContext portletDataContext, FileEntry fileEntry, Element fileEntryElement, String binPathSuffix, String previewType, int fileIndex) throws Exception { FileVersion fileVersion = fileEntry.getFileVersion(); String binPathSegment = null; if (fileIndex < 0) { binPathSegment = previewType;/*from ww w . j av a 2s . c o m*/ } else { binPathSegment = Integer.toString(fileIndex + 1); } StringBundler sb = new StringBundler(4); sb.append("bin-path-preview-"); sb.append(binPathSegment); sb.append("-"); sb.append(binPathSuffix); String binPathName = sb.toString(); String binPath = fileEntryElement.attributeValue(binPathName); InputStream is = null; try { is = portletDataContext.getZipEntryAsInputStream(binPath); if (is == null) { return; } String previewFilePath = null; if (fileIndex < 0) { previewFilePath = getPreviewFilePath(fileVersion, previewType); } else { previewFilePath = getPreviewFilePath(fileVersion, fileIndex + 1); } addFileToStore(portletDataContext.getCompanyId(), PREVIEW_PATH, previewFilePath, is); } finally { StreamUtil.cleanUp(is); } }
From source file:com.liferay.portlet.documentlibrary.util.DLPreviewableProcessor.java
License:Open Source License
protected void importThumbnailFromLAR(PortletDataContext portletDataContext, FileEntry fileEntry, Element fileEntryElement, String binPathName, int index) throws Exception { FileVersion fileVersion = fileEntry.getFileVersion(); String binPath = fileEntryElement.attributeValue(binPathName); InputStream is = null;/* ww w. j a v a 2s .c o m*/ try { is = portletDataContext.getZipEntryAsInputStream(binPath); if (is == null) { return; } String thumbnailFilePath = getThumbnailFilePath(fileVersion, getThumbnailType(fileVersion), index); addFileToStore(portletDataContext.getCompanyId(), THUMBNAIL_PATH, thumbnailFilePath, is); } finally { StreamUtil.cleanUp(is); } }
From source file:com.liferay.portlet.dynamicdatamapping.lar.DDMPortletDataHandlerImpl.java
License:Open Source License
public static void importStructure(PortletDataContext portletDataContext, Element structureElement) throws Exception { String path = structureElement.attributeValue("path"); if (!portletDataContext.isPathNotProcessed(path)) { return;//from ww w . j a va2s. com } DDMStructure structure = (DDMStructure) portletDataContext.getZipEntryAsObject(path); long userId = portletDataContext.getUserId(structure.getUserUuid()); ServiceContext serviceContext = portletDataContext.createServiceContext(structureElement, structure, _NAMESPACE); DDMStructure importedStructure = null; if (portletDataContext.isDataStrategyMirror()) { DDMStructure existingStructure = DDMStructureUtil.fetchByUUID_G(structure.getUuid(), portletDataContext.getScopeGroupId()); if (existingStructure == null) { serviceContext.setUuid(structure.getUuid()); importedStructure = DDMStructureLocalServiceUtil.addStructure(userId, portletDataContext.getScopeGroupId(), structure.getClassNameId(), structure.getStructureKey(), structure.getNameMap(), structure.getDescriptionMap(), structure.getXsd(), structure.getStorageType(), structure.getType(), serviceContext); } else { importedStructure = DDMStructureLocalServiceUtil.updateStructure(existingStructure.getStructureId(), structure.getNameMap(), structure.getDescriptionMap(), structure.getXsd(), serviceContext); } } else { importedStructure = DDMStructureLocalServiceUtil.addStructure(userId, portletDataContext.getScopeGroupId(), structure.getClassNameId(), structure.getStructureKey(), structure.getNameMap(), structure.getDescriptionMap(), structure.getXsd(), structure.getStorageType(), structure.getType(), serviceContext); } portletDataContext.importClassedModel(structure, importedStructure, _NAMESPACE); }
From source file:com.liferay.portlet.dynamicdatamapping.lar.DDMPortletDataHandlerImpl.java
License:Open Source License
protected static void importTemplate(PortletDataContext portletDataContext, Element templateElement) throws Exception { String path = templateElement.attributeValue("path"); if (!portletDataContext.isPathNotProcessed(path)) { return;/*ww w . ja v a2 s. c om*/ } DDMTemplate template = (DDMTemplate) portletDataContext.getZipEntryAsObject(path); long userId = portletDataContext.getUserId(template.getUserUuid()); Map<Long, Long> structureIds = (Map<Long, Long>) portletDataContext .getNewPrimaryKeysMap(DDMStructure.class); long structureId = MapUtil.getLong(structureIds, template.getStructureId(), template.getStructureId()); ServiceContext serviceContext = portletDataContext.createServiceContext(templateElement, template, _NAMESPACE); DDMTemplate importedTemplate = null; if (portletDataContext.isDataStrategyMirror()) { DDMTemplate existingTemplate = DDMTemplateUtil.fetchByUUID_G(template.getUuid(), portletDataContext.getScopeGroupId()); if (existingTemplate == null) { serviceContext.setUuid(template.getUuid()); importedTemplate = DDMTemplateLocalServiceUtil.addTemplate(userId, portletDataContext.getScopeGroupId(), structureId, template.getNameMap(), template.getDescriptionMap(), template.getType(), template.getMode(), template.getLanguage(), template.getScript(), serviceContext); } else { importedTemplate = DDMTemplateLocalServiceUtil.updateTemplate(existingTemplate.getTemplateId(), template.getNameMap(), template.getDescriptionMap(), template.getType(), template.getMode(), template.getLanguage(), template.getScript(), serviceContext); } } else { importedTemplate = DDMTemplateLocalServiceUtil.addTemplate(userId, portletDataContext.getScopeGroupId(), structureId, template.getNameMap(), template.getDescriptionMap(), template.getType(), template.getMode(), template.getLanguage(), template.getScript(), serviceContext); } portletDataContext.importClassedModel(template, importedTemplate, _NAMESPACE); }
From source file:com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureImpl.java
License:Open Source License
public List<String> getAvailableLocales() { Document document = getDocument(); Element rootElement = document.getRootElement(); String availableLocales = rootElement.attributeValue("available-locales"); return ListUtil.fromArray(StringUtil.split(availableLocales)); }