Search in sources :

Example 6 with Element

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;
}
Also used : Element(com.liferay.portal.kernel.xml.Element)

Example 7 with Element

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);
}
Also used : Element(com.liferay.portal.kernel.xml.Element)

Example 8 with Element

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);
    }
}
Also used : InputStream(java.io.InputStream) ImportFilesException(com.liferay.portlet.wiki.ImportFilesException) Element(com.liferay.portal.kernel.xml.Element) DocumentException(com.liferay.portal.kernel.xml.DocumentException) PortalException(com.liferay.portal.kernel.exception.PortalException) IOException(java.io.IOException) Document(com.liferay.portal.kernel.xml.Document) NoSuchPageException(com.liferay.portlet.wiki.NoSuchPageException) ImportFilesException(com.liferay.portlet.wiki.ImportFilesException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) DocumentException(com.liferay.portal.kernel.xml.DocumentException) IOException(java.io.IOException) NoSuchTagException(com.liferay.portlet.asset.NoSuchTagException)

Example 9 with Element

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());
    }
}
Also used : ProgressTracker(com.liferay.portal.kernel.util.ProgressTracker) Element(com.liferay.portal.kernel.xml.Element) NoSuchPageException(com.liferay.portlet.wiki.NoSuchPageException) ImportFilesException(com.liferay.portlet.wiki.ImportFilesException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) DocumentException(com.liferay.portal.kernel.xml.DocumentException) IOException(java.io.IOException) NoSuchTagException(com.liferay.portlet.asset.NoSuchTagException)

Example 10 with Element

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);
}
Also used : Artist(org.liferay.jukebox.model.Artist) Element(com.liferay.portal.kernel.xml.Element) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry)

Aggregations

Element (com.liferay.portal.kernel.xml.Element)22 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)5 DLFileEntry (com.liferay.portlet.documentlibrary.model.DLFileEntry)5 ServiceContext (com.liferay.portal.service.ServiceContext)4 InputStream (java.io.InputStream)4 ActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)3 SystemException (com.liferay.portal.kernel.exception.SystemException)3 UnsyncByteArrayInputStream (com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream)3 NoSuchTagException (com.liferay.portlet.asset.NoSuchTagException)3 ImportFilesException (com.liferay.portlet.wiki.ImportFilesException)3 Artist (org.liferay.jukebox.model.Artist)3 KBArticle (com.liferay.knowledgebase.model.KBArticle)2 KBFolder (com.liferay.knowledgebase.model.KBFolder)2 PortalException (com.liferay.portal.kernel.exception.PortalException)2 ProgressTracker (com.liferay.portal.kernel.util.ProgressTracker)2 Document (com.liferay.portal.kernel.xml.Document)2 DocumentException (com.liferay.portal.kernel.xml.DocumentException)2 NoSuchFileException (com.liferay.portlet.documentlibrary.NoSuchFileException)2 NoSuchPageException (com.liferay.portlet.wiki.NoSuchPageException)2 IOException (java.io.IOException)2