use of com.liferay.portal.kernel.xml.Element in project liferay-ide by liferay.
the class AdminPortletDataHandler method doImportData.
@Override
protected PortletPreferences doImportData(PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences, String data) throws Exception {
portletDataContext.importPortletPermissions(GadgetPermission.RESOURCE_NAME);
Element gadgetsElement = portletDataContext.getImportDataGroupElement(Gadget.class);
List<Element> gadgetElements = gadgetsElement.elements();
for (Element gadgetElement : gadgetElements) {
StagedModelDataHandlerUtil.importStagedModel(portletDataContext, gadgetElement);
}
return null;
}
use of com.liferay.portal.kernel.xml.Element in project liferay-ide by liferay.
the class GadgetStagedModelDataHandler method doExportStagedModel.
@Override
protected void doExportStagedModel(PortletDataContext portletDataContext, Gadget gadget) throws Exception {
Element gadgetElement = portletDataContext.getExportDataElement(gadget);
portletDataContext.addClassedModel(gadgetElement, ExportImportPathUtil.getModelPath(gadget), gadget);
}
use of com.liferay.portal.kernel.xml.Element in project liferay-ide by liferay.
the class MediaWikiImporter method importPages.
@Override
public void importPages(long userId, WikiNode node, InputStream[] inputStreams, Map<String, String[]> options) throws PortalException {
if ((inputStreams.length < 1) || (inputStreams[0] == null)) {
throw new PortalException("The pages file is mandatory");
}
InputStream pagesInputStream = inputStreams[0];
InputStream usersInputStream = inputStreams[1];
InputStream imagesInputStream = inputStreams[2];
try {
Document document = SAXReaderUtil.read(pagesInputStream);
Map<String, String> usersMap = readUsersFile(usersInputStream);
Element rootElement = document.getRootElement();
List<String> specialNamespaces = readSpecialNamespaces(rootElement);
processSpecialPages(userId, node, rootElement, specialNamespaces);
processRegularPages(userId, node, rootElement, specialNamespaces, usersMap, imagesInputStream, options);
processImages(userId, node, imagesInputStream);
moveFrontPage(userId, node, options);
} catch (DocumentException de) {
throw new ImportFilesException("Invalid XML file provided");
} catch (IOException ioe) {
throw new ImportFilesException("Error reading the files provided");
} catch (PortalException pe) {
throw pe;
} catch (Exception e) {
throw new PortalException(e);
}
}
use of com.liferay.portal.kernel.xml.Element in project liferay-ide by liferay.
the class MediaWikiImporter method processRegularPages.
protected void processRegularPages(long userId, WikiNode node, Element rootElement, List<String> specialNamespaces, Map<String, String> usersMap, InputStream imagesInputStream, Map<String, String[]> options) {
boolean importLatestVersion = MapUtil.getBoolean(options, WikiImporterKeys.OPTIONS_IMPORT_LATEST_VERSION);
boolean strictImportMode = MapUtil.getBoolean(options, WikiImporterKeys.OPTIONS_STRICT_IMPORT_MODE);
ProgressTracker progressTracker = ProgressTrackerThreadLocal.getProgressTracker();
int count = 0;
int percentage = 10;
int maxPercentage = 50;
if (imagesInputStream == null) {
maxPercentage = 99;
}
List<Element> pageElements = rootElement.elements("page");
for (int i = 0; i < pageElements.size(); i++) {
Element pageElement = pageElements.get(i);
String title = pageElement.elementText("title");
if (isSpecialMediaWikiPage(title, specialNamespaces)) {
continue;
}
title = normalizeTitle(title);
percentage = Math.min(10 + (i * (maxPercentage - percentage)) / pageElements.size(), maxPercentage);
progressTracker.setPercent(percentage);
List<Element> revisionElements = pageElement.elements("revision");
if (importLatestVersion) {
Element lastRevisionElement = revisionElements.get(revisionElements.size() - 1);
revisionElements = new ArrayList<Element>();
revisionElements.add(lastRevisionElement);
}
for (Element revisionElement : revisionElements) {
Element contributorElement = revisionElement.element("contributor");
String author = contributorElement.elementText("username");
String content = revisionElement.elementText("text");
String summary = revisionElement.elementText("comment");
try {
importPage(userId, author, node, title, content, summary, usersMap, strictImportMode);
} catch (Exception e) {
if (_log.isWarnEnabled()) {
_log.warn("Page with title " + title + " could not be imported", e);
}
}
}
count++;
}
if (_log.isInfoEnabled()) {
_log.info("Imported " + count + " pages into " + node.getName());
}
}
use of com.liferay.portal.kernel.xml.Element in project liferay-ide by liferay.
the class AlbumStagedModelDataHandler method doExportStagedModel.
@Override
protected void doExportStagedModel(PortletDataContext portletDataContext, Album album) throws Exception {
Artist artist = ArtistLocalServiceUtil.getArtist(album.getArtistId());
Element albumElement = portletDataContext.getExportDataElement(album);
if (portletDataContext.getBooleanParameter(JukeboxPortletDataHandler.NAMESPACE, "artists")) {
// Artists are selected to export, making sure this album's artist
// is going to be exported as well
StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, album, artist, PortletDataContext.REFERENCE_TYPE_DEPENDENCY);
} else {
// Artists are not exported - adding missing reference element to
// validate
portletDataContext.addReferenceElement(album, albumElement, artist, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true);
}
if (album.hasCustomImage()) {
FileEntry fileEntry = album.getCustomImage();
StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, album, Album.class, fileEntry, FileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK);
}
portletDataContext.addClassedModel(albumElement, ExportImportPathUtil.getModelPath(album), album);
}
Aggregations