Search in sources :

Example 1 with ImportFilesException

use of com.liferay.portlet.wiki.ImportFilesException 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 2 with ImportFilesException

use of com.liferay.portlet.wiki.ImportFilesException in project liferay-ide by liferay.

the class MediaWikiImporter method readSpecialNamespaces.

protected List<String> readSpecialNamespaces(Element root) throws ImportFilesException {
    List<String> namespaces = new ArrayList<String>();
    Element siteinfoElement = root.element("siteinfo");
    if (siteinfoElement == null) {
        throw new ImportFilesException("Invalid pages XML file");
    }
    Element namespacesElement = siteinfoElement.element("namespaces");
    List<Element> namespaceElements = namespacesElement.elements("namespace");
    for (Element namespaceElement : namespaceElements) {
        Attribute attribute = namespaceElement.attribute("key");
        String value = attribute.getValue();
        if (!value.equals("0")) {
            namespaces.add(namespaceElement.getText());
        }
    }
    return namespaces;
}
Also used : Attribute(com.liferay.portal.kernel.xml.Attribute) ImportFilesException(com.liferay.portlet.wiki.ImportFilesException) Element(com.liferay.portal.kernel.xml.Element) ArrayList(java.util.ArrayList)

Aggregations

Element (com.liferay.portal.kernel.xml.Element)2 ImportFilesException (com.liferay.portlet.wiki.ImportFilesException)2 PortalException (com.liferay.portal.kernel.exception.PortalException)1 SystemException (com.liferay.portal.kernel.exception.SystemException)1 Attribute (com.liferay.portal.kernel.xml.Attribute)1 Document (com.liferay.portal.kernel.xml.Document)1 DocumentException (com.liferay.portal.kernel.xml.DocumentException)1 NoSuchTagException (com.liferay.portlet.asset.NoSuchTagException)1 NoSuchPageException (com.liferay.portlet.wiki.NoSuchPageException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1