/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.dspace.app.xmlui.aspect.journal.landing;

import org.apache.log4j.Logger;

import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;

import org.dspace.app.xmlui.wing.Message;
import org.dspace.app.xmlui.wing.element.Body;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.Para;
import static org.dspace.app.xmlui.aspect.journal.landing.Const.*;

import java.io.IOException;
import java.sql.SQLException;
import org.apache.avalon.framework.parameters.ParameterException;
import org.dspace.app.xmlui.utils.UIException;
import org.dspace.app.xmlui.wing.WingException;
import org.dspace.authorize.AuthorizeException;
import org.xml.sax.SAXException;

/**
 *
 * @author Nathan Day
 */
public class Banner extends AbstractDSpaceTransformer {

    private static final Logger log = Logger.getLogger(Banner.class);

    private static final Message T_Member = message("xmlui.JournalLandingPage.Banner.mem");
    private static final Message T_Payment = message("xmlui.JournalLandingPage.Banner.pay");
    private static final Message T_Integration = message("xmlui.JournalLandingPage.Banner.int");
    private static final Message T_Authors = message("xmlui.JournalLandingPage.Banner.aut");
    private static final Message T_Embargo = message("xmlui.JournalLandingPage.Banner.dat");
    private static final Message T_Hidden = message("xmlui.JournalLandingPage.Banner.met");

    @Override
    public void addBody(Body body) throws SAXException, WingException,
            UIException, SQLException, IOException, AuthorizeException
    {
        String journalName;
        try {
            journalName = this.parameters.getParameter(PARAM_JOURNAL_NAME);
        } catch (ParameterException ex) {
            log.error("Failed to retrieve journal metadata from parameters");
            return;
        }
        Division outer = body.addDivision(BANNER_DIV_OUTER);
        Division inner = outer.addDivision(BANNER_DIV_INNER);
        inner.setHead(journalName);

        String journalDescr = "Journal description";
        inner.addPara().addContent(journalDescr);

        Para pMem = inner.addPara(BANNER_MEM, BANNER_MEM);
        pMem.addHighlight(null).addContent(T_Member);
        String journalMemberInfo = "lorem ipsum";
        pMem.addContent(": " + journalMemberInfo);

        Para pPay = inner.addPara(BANNER_PAY, BANNER_PAY);
        pPay.addHighlight(null).addContent(T_Payment);
        String journalPaymentPlanInfo = "lorem ipsum";
        pPay.addContent(": " + journalPaymentPlanInfo);

        Para pInt = inner.addPara(BANNER_INT, BANNER_INT);
        pInt.addHighlight(null).addContent(T_Integration);
        String journalIntegrationInfo = "lorem ipsum";
        pInt.addContent(": " + journalIntegrationInfo);

        Para pAut = inner.addPara(BANNER_AUT, BANNER_AUT);
        pAut.addHighlight(null).addContent(T_Authors);
        String journalAuthorSubmit = "lorem ipsum";
        pAut.addContent(": " + journalAuthorSubmit);

        Para pDat = inner.addPara(BANNER_DAT, BANNER_DAT);
        pDat.addHighlight(null).addContent(T_Embargo);
        String journalDataEmbargo = "lorem ipsum";
        pDat.addContent(": " + journalDataEmbargo);

        Para pMet = inner.addPara(BANNER_MET, BANNER_MET);
        pMet.addHighlight(null).addContent(T_Hidden);
        String journalMetadataInfo = "lorem ipsum";
        pMet.addContent(": " + journalMetadataInfo);

    }
}

@@ -633,32 +633,54 @@
 l.SQLException;%0A
+import java.util.Map;%0A
 import org.apach
@@ -718,25 +718,155 @@
 arameter
-Exception
+s;%0Aimport org.apache.cocoon.ProcessingException;%0Aimport org.apache.cocoon.environment.SourceResolver;%0Aimport org.datadryad.api.DryadJournal
 ;%0Aimport
@@ -1761,122 +1761,317 @@
 %22);%0A
-%0A
     
-@Override%0A    public void addBody(Body body) throws SAXException, WingException,%0A            UIException, SQL
+private static final Message T_packages = message(%22xmlui.JournalLandingPage.Banner.pac%22);%0A%0A    private String journalName;%0A    private DryadJournal dryadJournal;%0A%0A    @Override%0A    public void setup(SourceResolver resolver, Map objectModel, String src,%0A            Parameters parameters) throws Processing
 Exce
@@ -2077,18 +2077,19 @@
 eption, 
-IO
+SAX
 Exceptio
@@ -2094,18 +2094,23 @@
 ion,
- Authorize
+%0A            IO
 Exce
@@ -2129,34 +2129,67 @@
         
-String journalName
+super.setup(resolver, objectModel, src, parameters)
 ;%0A      
@@ -2226,13 +2226,8 @@
 e = 
-this.
 para
@@ -2284,25 +2284,16 @@
  catch (
-Parameter
 Exceptio
@@ -2326,93 +2326,505 @@
 ror(
-%22Failed to retrieve journal metadata from parameters%22);%0A            return;%0A        %7D
+ex);%0A            throw(new ProcessingException(%22Bad access of journal name%22));%0A        %7D%0A        try %7B%0A            dryadJournal = new DryadJournal(context, journalName);%0A        %7D catch (Exception ex) %7B%0A            log.error(ex);%0A            throw(new ProcessingException(%22Failed to make handler for %22 + journalName));%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void addBody(Body body) throws SAXException, WingException,%0A            UIException, SQLException, IOException, AuthorizeException%0A    %7B
 %0A   
@@ -4408,20 +4408,283 @@
 dataInfo);%0A%0A
+        Para pPac = inner.addPara(BANNER_PAC, BANNER_PAC);%0A        pPac.addHighlight(null).addContent(T_packages);%0A        int archivedPackageCount = dryadJournal.getArchivedPackagesCount();%0A        pPac.addContent(%22: %22 + Integer.toString(archivedPackageCount));%0A
     %7D%0A%7D%0A

add package count to journal-landing banner panel