throw new FenixServiceException();
throw new FenixServiceException(e1);
    public Boolean run(final Integer sectionCode, InfoWebSiteItem lastInfoWebSiteItem)            throws FenixServiceException {        try {            ISuportePersistente persistentSupport = PersistenceSupportFactory.getDefaultPersistenceSupport();            IPersistentWebSiteSection persistentWebSiteSection = persistentSupport                    .getIPersistentWebSiteSection();            IPersistentWebSiteItem persistentWebSiteItem = persistentSupport.getIPersistentWebSiteItem();            List sections = new ArrayList();            if (sectionCode == null) {                // in case of configuration we have to update all sections                sections = persistentWebSiteSection.readAll();            } else {                IWebSiteSection webSiteSectionTmp;                webSiteSectionTmp = (IWebSiteSection) persistentWebSiteSection.readByOID(                        WebSiteSection.class, sectionCode);                sections.add(webSiteSectionTmp);            }            Iterator iterSections = sections.iterator();            while (iterSections.hasNext()) {                IWebSiteSection webSiteSection = (IWebSiteSection) iterSections.next();                List webSiteItems = persistentWebSiteItem                        .readPublishedWebSiteItemsByWebSiteSection(webSiteSection);                List infoWebSiteItems = (List) CollectionUtils.collect(webSiteItems, new Transformer() {                    public Object transform(Object arg0) {                        IWebSiteItem webSiteItem = (IWebSiteItem) arg0;                        InfoWebSiteItem infoWebSiteItem = Cloner                                .copyIWebSiteItem2InfoWebSiteItem(webSiteItem);                        return infoWebSiteItem;                    }                });                InfoWebSiteSection infoWebSiteSection = Cloner                        .copyIWebSiteSection2InfoWebSiteSection(webSiteSection);                infoWebSiteSection.setInfoItemsList(infoWebSiteItems);                BeanComparator beanComparator = getBeanComparator(infoWebSiteSection);                Collections.sort(infoWebSiteSection.getInfoItemsList(), beanComparator);                if (infoWebSiteSection.getSortingOrder().equals("descendent")) {                    Collections.reverse(infoWebSiteSection.getInfoItemsList());                }                Calendar currentMonth = Calendar.getInstance();                String currentMonthFileName = infoWebSiteSection.getFtpName() + ".html";                //------------------------------------------------//-------------------------------------------------                // create excerpts file; this file has those items whose                // publication                // date has today's date                // and the number of items to show is limited by size of section                List excerptsList = new ArrayList();                excerptsList.addAll(infoWebSiteSection.getInfoItemsList());                // beginning of file                String excerptsFile = new String();                if (excerptsList.size() == 0) {                    // build no items file                    excerptsFile = excerptsFile.concat("<p>\n\t\t");                    excerptsFile = excerptsFile.concat("No existem " + infoWebSiteSection.getName()                            + "\n");                    excerptsFile = excerptsFile.concat("</p>\n");                } else {                    // limits number of items to mandatory section size in                    // website                    if (excerptsList.size() > infoWebSiteSection.getSize().intValue()) {                        Calendar today = Calendar.getInstance();                        List limitedList = new ArrayList();                        int i = 0;                        ListIterator iterItems = excerptsList.listIterator();                        while (i < infoWebSiteSection.getSize().intValue() && iterItems.hasNext()) {                            InfoWebSiteItem infoWebSiteItem = (InfoWebSiteItem) iterItems.next();                            // show only published items that have to be                            // published                            // today: according to online begin and end day                            if (!infoWebSiteItem.getOnlineBeginDay().after(today.getTime())                                    && !infoWebSiteItem.getOnlineEndDay().before(today.getTime())) {                                limitedList.add(infoWebSiteItem);                                i++;                            }                        }                        excerptsList = (ArrayList) limitedList;                        // be sure that we have at least one excerpt                        if (excerptsList.size() == 0) {                            excerptsList.add(infoWebSiteSection.getInfoItemsList().get(0));                        }                    }                    Iterator iterItems = excerptsList.iterator();                    while (iterItems.hasNext()) {                        InfoWebSiteItem infoWebSiteItem = (InfoWebSiteItem) iterItems.next();                        excerptsFile = putBegginingOfItem(excerptsFile, infoWebSiteItem);                        excerptsFile = putExcerpt(infoWebSiteSection, excerptsFile, infoWebSiteItem,                                currentMonth, currentMonthFileName);                    }                }                // build file                File excerpts;                try {                    excerpts = buildFile(excerptsFile, infoWebSiteSection.getFtpName()                            + "_excerpts.html");                } catch (Exception e) {                    e.printStackTrace();                    return Boolean.FALSE;                }                try {                    // send file to server by ftp                    //                    Ftp.enviarFicheiro("/IstFtpServerConfig.properties",                    // excerpts.getName(),                    //                            infoWebSiteSection.getFtpName() + "/");                    Ftp.enviarFicheiroScp("/IstFtpServerConfig.properties", excerpts.getName(),                            infoWebSiteSection.getFtpName() + "/");                } catch (IOException e1) {                    throw new FenixServiceException();                }                // delete created file                excerpts.delete();                //------------------------------------------------//-------------------------------------------------                // create file of month corresponding to item created or                // create all files in case this item is from a new month or in                // case                // some item was deleted                List items = new ArrayList();                items.addAll(infoWebSiteSection.getInfoItemsList());                List monthList = new ArrayList();                HashMap monthsToCreateLinks = new HashMap();                HashMap monthsToCreateFiles = new HashMap();                Calendar calendarCycle = Calendar.getInstance();                Calendar calendarLast = Calendar.getInstance();                if (lastInfoWebSiteItem != null) {                    // need to know what to sort                    calendarLast.setTime(dateToSort(infoWebSiteSection, lastInfoWebSiteItem));                    // get items with the same month as last inserted                    Iterator iterItems = infoWebSiteSection.getInfoItemsList().iterator();                    while (iterItems.hasNext()) {                        InfoWebSiteItem infoWebSiteItem = (InfoWebSiteItem) iterItems.next();                        calendarCycle.clear();                        calendarCycle.setTime(dateToSort(infoWebSiteSection, infoWebSiteItem));                        if (calendarCycle.get(Calendar.MONTH) == calendarLast.get(Calendar.MONTH)                                && calendarCycle.get(Calendar.YEAR) == calendarLast.get(Calendar.YEAR)) {                            monthList.add(infoWebSiteItem);                        }                        findMonthsForArchive(monthsToCreateLinks, calendarCycle);                    }                    if (monthList.size() > 1) {                        // file already exists so only this file needs to be                        // refreshed                        List monthToRefresh = new ArrayList();                        monthToRefresh.add(new Integer(calendarLast.get(Calendar.MONTH)));                        monthsToCreateFiles.put(new Integer(calendarLast.get(Calendar.YEAR)),                                monthToRefresh);                        items = monthList;                    } else {                        // there is a new month to send to server, so build file                        // and                        // refresh links on other files                        copyNewHashmapForFiles(monthsToCreateLinks, monthsToCreateFiles);                    }                } else {                    Iterator iterItems = infoWebSiteSection.getInfoItemsList().iterator();                    while (iterItems.hasNext()) {                        InfoWebSiteItem infoWebSiteItem = (InfoWebSiteItem) iterItems.next();                        calendarCycle.clear();                        calendarCycle.setTime(dateToSort(infoWebSiteSection, infoWebSiteItem));                        findMonthsForArchive(monthsToCreateLinks, calendarCycle);                    }                    copyNewHashmapForFiles(monthsToCreateLinks, monthsToCreateFiles);                }                List monthLinks = null;                Integer year = null;                Iterator iterYears = monthsToCreateFiles.entrySet().iterator();                while (iterYears.hasNext()) {                    Map.Entry monthMap = (Map.Entry) iterYears.next();                    year = (Integer) monthMap.getKey();                    monthLinks = (List) monthMap.getValue();                    Iterator iterLinks = monthLinks.iterator();                    while (iterLinks.hasNext()) {                        Integer monthLink = (Integer) iterLinks.next();                        //Mes thisMonthString = new Mes(monthLink.intValue() +                        // 1);                        String fileName = infoWebSiteSection.getFtpName() + year.toString() + "_"                                + new Integer(monthLink.intValue() + 1).toString() + ".html";                        List thisMonthList = new ArrayList();                        // if month of last item is new we have to recreate all                        // files for other months                        if (monthList.size() <= 1) {                            Iterator iterAllItems = items.iterator();                            while (iterAllItems.hasNext()) {                                InfoWebSiteItem infoWebSiteItem = (InfoWebSiteItem) iterAllItems.next();                                calendarCycle.clear();                                calendarCycle.setTime(dateToSort(infoWebSiteSection, infoWebSiteItem));                                if (calendarCycle.get(Calendar.MONTH) == monthLink.intValue()                                        && calendarCycle.get(Calendar.YEAR) == year.intValue()) {                                    thisMonthList.add(infoWebSiteItem);                                }                            }                        } else {                            thisMonthList = monthList;                        }                        String keywordsList = createKeywordsList(thisMonthList);                        // build body for items                        String itemsFile = new String();                        itemsFile = putBegginingOfItemFile(itemsFile, infoWebSiteSection, keywordsList);                        itemsFile = itemsFile.concat("<h1>" + infoWebSiteSection.getName() + "</h1>");                        itemsFile = itemsFile.concat("\n<br />\n");                        Iterator iterItemsForFile = thisMonthList.iterator();                        while (iterItemsForFile.hasNext()) {                            InfoWebSiteItem infoWebSiteItem = (InfoWebSiteItem) iterItemsForFile.next();                            itemsFile = putBegginingOfItem(itemsFile, infoWebSiteItem);                            itemsFile = putItem(itemsFile, infoWebSiteItem);                        }                        itemsFile = itemsFile.concat("<p>\n\t");                        itemsFile = itemsFile.concat("<span class=\"greytxt\">");                        itemsFile = itemsFile                                .concat("Eventuais incoerncias nesta pgina devero ser comunicadas afim de se efectuar a respectiva correco.");                        itemsFile = itemsFile.concat("</span>");                        itemsFile = itemsFile.concat("\n</p>\n");                        itemsFile = itemsFile.concat("<h2>Arquivo de " + infoWebSiteSection.getName()                                + "</h2>\n<p>\n");                        itemsFile = buildLinksForArchive(infoWebSiteSection, currentMonth,                                currentMonthFileName, monthsToCreateLinks, year, monthLink, itemsFile);                        itemsFile = itemsFile.concat("</p>");                        itemsFile = putEndOfItemFile(itemsFile);                        // prepare file for transfer                        File itemsFileToTransfer;                        try {                            if (monthLink.intValue() == currentMonth.get(Calendar.MONTH)                                    && year.intValue() == currentMonth.get(Calendar.YEAR)) {                                itemsFileToTransfer = buildFile(itemsFile, currentMonthFileName);                            } else {                                itemsFileToTransfer = buildFile(itemsFile, fileName);                            }                        } catch (Exception e) {                            e.printStackTrace();                            return Boolean.FALSE;                        }                        try {                            //                            Ftp.enviarFicheiro("/IstFtpServerConfig.properties",                            // itemsFileToTransfer                            //                                    .getName(), infoWebSiteSection.getFtpName() +                            // "/");                            Ftp.enviarFicheiroScp("/IstFtpServerConfig.properties", itemsFileToTransfer                                    .getName(), infoWebSiteSection.getFtpName() + "/");                        } catch (IOException e2) {                            throw new FenixServiceException(e2);                        }                        // delete created file                        itemsFileToTransfer.delete();                    }                }            }        } catch (ExcepcaoPersistencia excepcaoPersistencia) {            throw new FenixServiceException(excepcaoPersistencia);        }        return Boolean.TRUE;    }