Example usage for org.apache.commons.configuration ConversionException toString

List of usage examples for org.apache.commons.configuration ConversionException toString

Introduction

In this page you can find the example usage for org.apache.commons.configuration ConversionException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:de.ingrid.portal.portlets.admin.AdminPortalProfilePortlet.java

/**
 * @see org.apache.portals.bridges.velocity.GenericVelocityPortlet#processAction(javax.portlet.ActionRequest,
 *      javax.portlet.ActionResponse)/*from  w  w  w  .  j  av  a2  s .c  o  m*/
 */
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {

    String action = request.getParameter("action");

    if (action != null && action.equals("switchProfile")) {
        String profileName = request.getParameter("profile");
        String databasePostfix = "_mysql";
        if (UtilsDB.isOracle()) {
            databasePostfix = "_oracle";
        }
        String profileDescriptor = getPortletConfig().getPortletContext()
                .getRealPath("/profiles/" + profileName + "/profile" + databasePostfix + ".xml");
        String pageName = null;
        try {
            XMLConfiguration profile = new XMLConfiguration(profileDescriptor);
            // set page configurations
            // this info will be held in the database
            List pages = profile.getList("pages.page.name");
            for (int i = 0; i < pages.size(); i++) {
                pageName = (String) pages.get(i);

                // set visibility of the page
                boolean hidden;
                Page p = pageManager.getPage(Folder.PATH_SEPARATOR + pageName);
                try {
                    hidden = profile.getBoolean("pages.page(" + i + ").hidden");
                    p.setHidden(hidden);
                } catch (ConversionException e) {
                    log.warn("No tag 'hidden' found for page '" + pageName + "'", e);
                }
                pageManager.updatePage(p);

                // set page layout configuration
                List portletNames = profile.getList("pages.page(" + i + ").portlets.portlet.name");
                if (portletNames != null && portletNames.size() > 0) {
                    // defragmentation
                    UtilsPageLayout.defragmentLayoutColumn((Fragment) p.getRootFragment(), 0);
                    UtilsPageLayout.defragmentLayoutColumn((Fragment) p.getRootFragment(), 1);
                    // remove all fragments
                    UtilsPageLayout.removeAllFragmentsInColumn(p, (Fragment) p.getRootFragment(), 0);
                    UtilsPageLayout.removeAllFragmentsInColumn(p, (Fragment) p.getRootFragment(), 1);
                    for (int j = 0; j < portletNames.size(); j++) {
                        String portletName = (String) portletNames.get(j);
                        //portletRegistry.getPortletDefinitionByIdentifier("IngridInformPortlet").getPreferenceSet();//portletRegistry.getAllPortletDefinitions();
                        try {
                            List portletPrefsNames = null;
                            List<FragmentPreference> prefs = new ArrayList<FragmentPreference>();

                            int row = profile.getInt("pages.page(" + i + ").portlets.portlet(" + j + ")[@row]");
                            int col = profile.getInt("pages.page(" + i + ").portlets.portlet(" + j + ")[@col]");
                            try {
                                // get the hidden information if it is available
                                portletPrefsNames = profile.getList(
                                        "pages.page(" + i + ").portlets.portlet(" + j + ").preference[@name]");
                                for (int k = 0; k < portletPrefsNames.size(); k++) {
                                    FragmentPreference f = pageManager.newFragmentPreference();
                                    // set the name of the preference
                                    f.setName((String) portletPrefsNames.get(k));
                                    // get the values for this preference
                                    List<String> pl = (List<String>) (List<?>) profile.getList("pages.page(" + i
                                            + ").portlets.portlet(" + j + ").preference(" + k + ").value");
                                    f.setValueList(pl);
                                    prefs.add(f);
                                }
                            } catch (Exception e) {
                                log.error(e.toString());
                            }
                            UtilsPageLayout.positionPortletOnPage(pageManager, p,
                                    (Fragment) p.getRootFragment(), portletName, row, col, prefs);
                        } catch (ConversionException e) {
                            log.warn("No 'x' or 'y' attribute found for portlet '" + portletName + "' on page '"
                                    + pageName + "'", e);
                        }
                    }
                    pageManager.updatePage(p);
                }
            }

            // process files copy actions
            List fileActions = profile.getList("files.file.action");
            for (int i = 0; i < fileActions.size(); i++) {
                String actionName = (String) fileActions.get(i);
                String src = profile.getString("files.file(" + i + ").src");
                String dst = profile.getString("files.file(" + i + ").dst");
                if (dst == null) {
                    dst = src;
                }
                String srcFileName = getPortletConfig().getPortletContext()
                        .getRealPath("/profiles/" + profileName + "/" + src);
                String dstContext = dst.substring(0, dst.indexOf("/"));
                String dstPath = dst.substring(dst.indexOf("/") + 1);
                String dstFileName = ((RequestContext) request.getAttribute(RequestContext.REQUEST_PORTALENV))
                        .getConfig().getServletContext().getContext("/" + dstContext).getRealPath(dstPath);

                if (actionName.equalsIgnoreCase("copy")) {
                    if (!srcFileName.equals(dstFileName)) {
                        copy(srcFileName, dstFileName);
                    }
                } else if (actionName.equalsIgnoreCase("copy-dir")) {
                    if (!srcFileName.equals(dstFileName)) {
                        copyDir(srcFileName, dstFileName);
                    }
                }
            }

            // process sql actions
            List sqlActions = profile.getList("sql.execute");
            for (int i = 0; i < sqlActions.size(); i++) {
                String sqlAction = (String) sqlActions.get(i);
                UtilsDB.executeRawUpdateSQL(sqlAction);
            }

            response.setRenderParameter("switchedToProfile", profileName);

        } catch (ConfigurationException e) {
            log.error("Error reading profile configuration (" + profileDescriptor + ")", e);
        } catch (PageNotFoundException e) {
            log.error("Page not found from  (" + Folder.PATH_SEPARATOR + pageName + ")", e);
        } catch (NodeException e) {
            log.error("Error reading page (" + Folder.PATH_SEPARATOR + pageName + ")", e);
        }
    }
}