From 8da2548025d4e0cc8a498ce3ef0b95cf6c1db0c8 Mon Sep 17 00:00:00 2001 From: Fernando Pietchaki Domingues <fpd09@c3sl.ufpr.br> Date: Mon, 2 Sep 2013 19:15:16 -0300 Subject: [PATCH] Arrumado seletor de linguagem. Arrumado mais elementos visuais. --- .../app/xmlui/aspect/eperson/EditProfile.java | 3 +- .../aspect/viewArtifacts/Navigation.java | 16 - .../app/xmlui/cocoon/DSpaceLocaleAction.java | 31 +- dspace/config/news-xmlui.xml | 6 +- .../app/xmlui/aspect/eperson/EditProfile.java | 497 ++++++++++++++++++ .../aspect/viewArtifacts/Navigation.java | 164 ++++++ .../app/xmlui/cocoon/DSpaceLocaleAction.java | 198 +++++++ .../themes/Participatorio/lib/css/style.css | 15 +- .../lib/xsl/core/page-structure.xsl | 60 +-- 9 files changed, 906 insertions(+), 84 deletions(-) create mode 100644 dspace/modules/xmlui/src/main/java/org/dspace/app/xmlui/aspect/eperson/EditProfile.java create mode 100644 dspace/modules/xmlui/src/main/java/org/dspace/app/xmlui/aspect/viewArtifacts/Navigation.java create mode 100644 dspace/modules/xmlui/src/main/java/org/dspace/app/xmlui/cocoon/DSpaceLocaleAction.java diff --git a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/eperson/EditProfile.java b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/eperson/EditProfile.java index bbf00c4..e7674ef 100644 --- a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/eperson/EditProfile.java +++ b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/eperson/EditProfile.java @@ -481,8 +481,7 @@ public class EditProfile extends AbstractDSpaceTransformer */ private static Locale[] getSupportedLocales() { -// ############################################################################################# - String ll = ConfigurationManager.getProperty("webui.supported.locales"); + String ll = ConfigurationManager.getProperty("xmlui.supported.locales"); if (ll != null) { return I18nUtil.parseLocales(ll); diff --git a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/viewArtifacts/Navigation.java b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/viewArtifacts/Navigation.java index ac12e95..ff4ba4e 100644 --- a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/viewArtifacts/Navigation.java +++ b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/viewArtifacts/Navigation.java @@ -26,13 +26,11 @@ import org.dspace.content.Community; import org.dspace.content.DSpaceObject; import org.dspace.content.Item; import org.dspace.core.ConfigurationManager; -import org.dspace.core.I18nUtil; import org.xml.sax.SAXException; import java.io.IOException; import java.io.Serializable; import java.sql.SQLException; -import java.util.Locale; /** * This transform applies the basic navigational links that should be available @@ -130,20 +128,6 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr pageMeta.addMetadata("page","contactURL").addContent(contextPath + "/contact"); pageMeta.addMetadata("page","feedbackURL").addContent(contextPath + "/feedback"); - -// ############################################################################################# - // Add the locale meta data including language dependant labels - Locale[] locales = I18nUtil.getSupportedLocales(); - for (int i=0; i < locales.length; i++) - { - pageMeta.addMetadata("page", "supportedLocale").addContent(locales[i].toString()); - // now add the appropriate labels - pageMeta.addMetadata("supportedLocale", locales[i].toString()).addContent(locales[i].getDisplayName(locales[i])); - } - pageMeta.addMetadata("page","currentLocale").addContent(context.getCurrentLocale().toString()); -// ############################################################################################# - - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); if (dso != null) { diff --git a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/cocoon/DSpaceLocaleAction.java b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/cocoon/DSpaceLocaleAction.java index e9980e6..814f1f5 100644 --- a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/cocoon/DSpaceLocaleAction.java +++ b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/cocoon/DSpaceLocaleAction.java @@ -17,9 +17,7 @@ import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.i18n.I18nUtils; import org.apache.cocoon.i18n.I18nUtils.LocaleValidator; -import org.dspace.app.xmlui.utils.ContextUtil; import org.dspace.core.ConfigurationManager; -import org.dspace.core.Context; import org.dspace.core.I18nUtil; import java.util.ArrayList; @@ -99,24 +97,13 @@ public class DSpaceLocaleAction extends ServiceableAction implements Configurabl getLogger().debug("Found locale: " + localeStr); } -// ############################################################################################# -// I18nUtils.storeLocale(objectModel, -// "locale-attribute", -// localeStr, -// false, -// false, -// false, -// false); I18nUtils.storeLocale(objectModel, - "locale-attribute", - localeStr, - false, - true, - false, - false); - Context context = ContextUtil.obtainContext(objectModel); - context.setCurrentLocale(locale); -// ############################################################################################# + "locale-attribute", + localeStr, + false, + false, + false, + false); // Set up a map for sitemap parameters Map<String, String> map = new HashMap<String, String>(); @@ -143,13 +130,11 @@ public class DSpaceLocaleAction extends ServiceableAction implements Configurabl */ public DSpaceLocaleValidator() { -// ############################################################################################# - if (ConfigurationManager.getProperty("webui.supported.locales") != null) + if (ConfigurationManager.getProperty("xmlui.supported.locales") != null) { supportedLocales = new ArrayList<Locale>(); -// ############################################################################################# - String supportedLocalesConfig = ConfigurationManager.getProperty("webui.supported.locales"); + String supportedLocalesConfig = ConfigurationManager.getProperty("xmlui.supported.locales"); String[] parts = supportedLocalesConfig.split(","); diff --git a/dspace/config/news-xmlui.xml b/dspace/config/news-xmlui.xml index 138b1eb..bc482f2 100644 --- a/dspace/config/news-xmlui.xml +++ b/dspace/config/news-xmlui.xml @@ -3,15 +3,15 @@ version="1.1"> <body> <div id="file.news.div.news" n="news" rend="primary"> - <head>BIBLIOTECA DIGITAL DO PARTICIPATÓRIO</head> + <head>Biblioteca Digital do Participatório</head> <p>A Biblioteca Digital do Participatório está inserida no movimento mundial de acesso aberto à produção técnica-científica. A adoção desse novo modelo de gestão para documentos eletrônicos possibilitará uma melhor disseminação e acesso às publicações sobre juventude e políticas públicas, seja da própria Secretaria Nacional de Juventude (SNJ), quanto de outros acervos institucionais ligados à temática.</p> </div> <div id="file.news.div.news" n="news" rend="primary"> - <head>MISSÃO</head> + <head>Missão</head> <p>Armazenar, preservar, divulgar e dar amplo acesso à produção institucional da Secretaria Nacional de Juventude – SNJ e de outros acervos relacionados com a a área de políticas públicas de juventude. </p> </div> <div id="file.news.div.news" n="news" rend="primary"> - <head>OBJETIVO</head> + <head>Objetivo</head> <p>Reunir num único local virtual a produção institucional da SNJ, contribuindo para a preservação da memória institucional e para a maior visibilidade da temática de políticas públicas de juventude. </p> </div> </body> diff --git a/dspace/modules/xmlui/src/main/java/org/dspace/app/xmlui/aspect/eperson/EditProfile.java b/dspace/modules/xmlui/src/main/java/org/dspace/app/xmlui/aspect/eperson/EditProfile.java new file mode 100644 index 0000000..bbf00c4 --- /dev/null +++ b/dspace/modules/xmlui/src/main/java/org/dspace/app/xmlui/aspect/eperson/EditProfile.java @@ -0,0 +1,497 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE and NOTICE files at the root of the source + * tree and available online at + * + * http://www.dspace.org/license/ + */ +package org.dspace.app.xmlui.aspect.eperson; + +import java.io.IOException; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.Locale; +import java.util.Map; + +import org.apache.avalon.framework.parameters.Parameters; +import org.apache.cocoon.ProcessingException; +import org.apache.cocoon.environment.ObjectModelHelper; +import org.apache.cocoon.environment.Request; +import org.apache.cocoon.environment.SourceResolver; +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.WingException; +import org.dspace.app.xmlui.wing.element.Body; +import org.dspace.app.xmlui.wing.element.Button; +import org.dspace.app.xmlui.wing.element.Division; +import org.dspace.app.xmlui.wing.element.Field; +import org.dspace.app.xmlui.wing.element.List; +import org.dspace.app.xmlui.wing.element.PageMeta; +import org.dspace.app.xmlui.wing.element.Select; +import org.dspace.app.xmlui.wing.element.Text; +import org.dspace.content.Collection; +import org.dspace.core.ConfigurationManager; +import org.dspace.core.I18nUtil; +import org.dspace.core.LogManager; +import org.dspace.eperson.Group; +import org.dspace.eperson.Subscribe; +import org.xml.sax.SAXException; + +/** + * Display a form that allows the user to edit their profile. + * There are two cases in which this can be used: 1) when an + * existing user is attempting to edit their own profile, and + * 2) when a new user is registering for the first time. + * + * There are several parameters this transformer accepts: + * + * email - The email address of the user registering for the first time. + * + * registering - A boolean value to indicate whether the user is registering for the first time. + * + * retryInformation - A boolean value to indicate whether there was an error with the user's profile. + * + * retryPassword - A boolean value to indicate whether there was an error with the user's password. + * + * allowSetPassword - A boolean value to indicate whether the user is allowed to set their own password. + * + * @author Scott Phillips + */ +public class EditProfile extends AbstractDSpaceTransformer +{ + private static Logger log = Logger.getLogger(EditProfile.class); + + /** Language string used: */ + private static final Message T_title_create = + message("xmlui.EPerson.EditProfile.title_create"); + + private static final Message T_title_update = + message("xmlui.EPerson.EditProfile.title_update"); + + private static final Message T_dspace_home = + message("xmlui.general.dspace_home"); + + private static final Message T_trail_new_registration = + message("xmlui.EPerson.trail_new_registration"); + + private static final Message T_trail_update = + message("xmlui.EPerson.EditProfile.trail_update"); + + private static final Message T_head_create = + message("xmlui.EPerson.EditProfile.head_create"); + + private static final Message T_head_update = + message("xmlui.EPerson.EditProfile.head_update"); + + private static final Message T_email_address = + message("xmlui.EPerson.EditProfile.email_address"); + + private static final Message T_first_name = + message("xmlui.EPerson.EditProfile.first_name"); + + private static final Message T_error_required = + message("xmlui.EPerson.EditProfile.error_required"); + + private static final Message T_last_name = + message("xmlui.EPerson.EditProfile.last_name"); + + private static final Message T_telephone = + message("xmlui.EPerson.EditProfile.telephone"); + + private static final Message T_language = + message("xmlui.EPerson.EditProfile.Language"); + + private static final Message T_create_password_instructions = + message("xmlui.EPerson.EditProfile.create_password_instructions"); + + private static final Message T_update_password_instructions = + message("xmlui.EPerson.EditProfile.update_password_instructions"); + + private static final Message T_password = + message("xmlui.EPerson.EditProfile.password"); + + private static final Message T_error_invalid_password = + message("xmlui.EPerson.EditProfile.error_invalid_password"); + + private static final Message T_confirm_password = + message("xmlui.EPerson.EditProfile.confirm_password"); + + private static final Message T_error_unconfirmed_password = + message("xmlui.EPerson.EditProfile.error_unconfirmed_password"); + + private static final Message T_submit_update = + message("xmlui.EPerson.EditProfile.submit_update"); + + private static final Message T_submit_create = + message("xmlui.EPerson.EditProfile.submit_create"); + + private static final Message T_subscriptions = + message("xmlui.EPerson.EditProfile.subscriptions"); + + private static final Message T_subscriptions_help = + message("xmlui.EPerson.EditProfile.subscriptions_help"); + + private static final Message T_email_subscriptions = + message("xmlui.EPerson.EditProfile.email_subscriptions"); + + private static final Message T_select_collection = + message("xmlui.EPerson.EditProfile.select_collection"); + + private static final Message T_head_auth = + message("xmlui.EPerson.EditProfile.head_auth"); + + private static final Message T_head_identify = + message("xmlui.EPerson.EditProfile.head_identify"); + + private static final Message T_head_security = + message("xmlui.EPerson.EditProfile.head_security"); + + private static Locale[] supportedLocales = getSupportedLocales(); + static + { + Arrays.sort(supportedLocales, new Comparator<Locale>() { + public int compare(Locale a, Locale b) + { + return a.getDisplayName().compareTo(b.getDisplayName()); + } + }); + } + + /** The email address of the user registering for the first time.*/ + private String email; + + /** Determine if the user is registering for the first time */ + private boolean registering; + + /** Determine if the user is allowed to set their own password */ + private boolean allowSetPassword; + + /** A list of fields in error */ + private java.util.List<String> errors; + + public void setup(SourceResolver resolver, Map objectModel, String src, + Parameters parameters) throws ProcessingException, SAXException, + IOException + { + super.setup(resolver,objectModel,src,parameters); + + this.email = parameters.getParameter("email","unknown"); + this.registering = parameters.getParameterAsBoolean("registering",false); + this.allowSetPassword = parameters.getParameterAsBoolean("allowSetPassword",false); + + String errors = parameters.getParameter("errors",""); + if (errors.length() > 0) + { + this.errors = Arrays.asList(errors.split(",")); + } + else + { + this.errors = new ArrayList<String>(); + } + + // Ensure that the email variable is set. + if (eperson != null) + { + this.email = eperson.getEmail(); + } + } + + public void addPageMeta(PageMeta pageMeta) throws WingException + { + // Set the page title + if (registering) + { + pageMeta.addMetadata("title").addContent(T_title_create); + } + else + { + pageMeta.addMetadata("title").addContent(T_title_update); + } + + pageMeta.addTrailLink(contextPath + "/",T_dspace_home); + if (registering) + { + pageMeta.addTrail().addContent(T_trail_new_registration); + } + else + { + pageMeta.addTrail().addContent(T_trail_update); + } + } + + + public void addBody(Body body) throws WingException, SQLException + { + // Log that we are viewing a profile + log.info(LogManager.getHeader(context, "view_profile", "")); + + Request request = ObjectModelHelper.getRequest(objectModel); + + String defaultFirstName="",defaultLastName="",defaultPhone=""; + String defaultLanguage=null; + if (request.getParameter("submit") != null) + { + defaultFirstName = request.getParameter("first_name"); + defaultLastName = request.getParameter("last_name"); + defaultPhone = request.getParameter("phone"); + defaultLanguage = request.getParameter("language"); + } + else if (eperson != null) + { + defaultFirstName = eperson.getFirstName(); + defaultLastName = eperson.getLastName(); + defaultPhone = eperson.getMetadata("phone"); + defaultLanguage = eperson.getLanguage(); + } + + String action = contextPath; + if (registering) + { + action += "/register"; + } + else + { + action += "/profile"; + } + + + + + Division profile = body.addInteractiveDivision("information", + action,Division.METHOD_POST,"primary"); + + if (registering) + { + profile.setHead(T_head_create); + } + else + { + profile.setHead(T_head_update); + } + + // Add the progress list if we are registering a new user + if (registering) + { + EPersonUtils.registrationProgressList(profile, 2); + } + + + + + + List form = profile.addList("form",List.TYPE_FORM); + + List identity = form.addList("identity",List.TYPE_FORM); + identity.setHead(T_head_identify); + + // Email + identity.addLabel(T_email_address); + identity.addItem(email); + + // First name + Text firstName = identity.addItem().addText("first_name"); + firstName.setAutofocus("autofocus"); + firstName.setRequired(); + firstName.setLabel(T_first_name); + firstName.setValue(defaultFirstName); + if (errors.contains("first_name")) + { + firstName.addError(T_error_required); + } + if (!registering && !ConfigurationManager.getBooleanProperty("xmlui.user.editmetadata", true)) + { + firstName.setDisabled(); + } + + // Last name + Text lastName = identity.addItem().addText("last_name"); + lastName.setRequired(); + lastName.setLabel(T_last_name); + lastName.setValue(defaultLastName); + if (errors.contains("last_name")) + { + lastName.addError(T_error_required); + } + if (!registering &&!ConfigurationManager.getBooleanProperty("xmlui.user.editmetadata", true)) + { + lastName.setDisabled(); + } + + // Phone + Text phone = identity.addItem().addText("phone"); + phone.setLabel(T_telephone); + phone.setValue(defaultPhone); + if (errors.contains("phone")) + { + phone.addError(T_error_required); + } + if (!registering && !ConfigurationManager.getBooleanProperty("xmlui.user.editmetadata", true)) + { + phone.setDisabled(); + } + + // Language + Select lang = identity.addItem().addSelect("language"); + lang.setLabel(T_language); + if (supportedLocales.length > 0) + { + for (Locale lc : supportedLocales) + { + lang.addOption(lc.toString(), lc.getDisplayName()); + } + } + else + { + lang.addOption(I18nUtil.DEFAULTLOCALE.toString(), I18nUtil.DEFAULTLOCALE.getDisplayName()); + } + lang.setOptionSelected((defaultLanguage == null || defaultLanguage.equals("")) ? + I18nUtil.DEFAULTLOCALE.toString() : defaultLanguage); + if (!registering && !ConfigurationManager.getBooleanProperty("xmlui.user.editmetadata", true)) + { + lang.setDisabled(); + } + + // Subscriptions + if (!registering) + { + List subscribe = form.addList("subscriptions",List.TYPE_FORM); + subscribe.setHead(T_subscriptions); + + subscribe.addItem(T_subscriptions_help); + + Collection[] currentList = Subscribe.getSubscriptions(context, context.getCurrentUser()); + Collection[] possibleList = Collection.findAll(context); + + Select subscriptions = subscribe.addItem().addSelect("subscriptions"); + subscriptions.setLabel(T_email_subscriptions); + subscriptions.setHelp(""); + subscriptions.enableAddOperation(); + subscriptions.enableDeleteOperation(); + + subscriptions.addOption(-1,T_select_collection); + for (Collection possible : possibleList) + { + String name = possible.getMetadata("name"); + if (name.length() > 50) + { + name = name.substring(0, 47) + "..."; + } + subscriptions.addOption(possible.getID(), name); + } + + for (Collection collection: currentList) + { + subscriptions.addInstance().setOptionSelected(collection.getID()); + } + } + + + if (allowSetPassword) + { + List security = form.addList("security",List.TYPE_FORM); + security.setHead(T_head_security); + + if (registering) + { + security.addItem().addContent(T_create_password_instructions); + } + else + { + security.addItem().addContent(T_update_password_instructions); + } + + + Field password = security.addItem().addPassword("password"); + password.setLabel(T_password); + if (registering) + { + password.setRequired(); + } + if (errors.contains("password")) + { + password.addError(T_error_invalid_password); + } + + Field passwordConfirm = security.addItem().addPassword("password_confirm"); + passwordConfirm.setLabel(T_confirm_password); + if (registering) + { + passwordConfirm.setRequired(); + } + if (errors.contains("password_confirm")) + { + passwordConfirm.addError(T_error_unconfirmed_password); + } + } + + Button submit = form.addItem().addButton("submit"); + if (registering) + { + submit.setValue(T_submit_update); + } + else + { + submit.setValue(T_submit_create); + } + + profile.addHidden("eperson-continue").setValue(knot.getId()); + + + + if (!registering) + { + // Add a list of groups that this user is apart of. + Group[] memberships = Group.allMemberGroups(context, context.getCurrentUser()); + + + // Not a member of any groups then don't do anything. + if (!(memberships.length > 0)) + { + return; + } + + List list = profile.addList("memberships"); + list.setHead(T_head_auth); + for (Group group: memberships) + { + list.addItem(group.getName()); + } + } + } + + /** + * Recycle + */ + public void recycle() + { + this.email = null; + this.errors = null; + super.recycle(); + } + + /** + * get the available Locales for the User Interface as defined in dspace.cfg + * property xmlui.supported.locales + * returns an array of Locales or null + * + * @return an array of supported Locales or null + */ + private static Locale[] getSupportedLocales() + { +// ############################################################################################# + String ll = ConfigurationManager.getProperty("webui.supported.locales"); + if (ll != null) + { + return I18nUtil.parseLocales(ll); + } + else + { + Locale result[] = new Locale[1]; + result[0] = I18nUtil.DEFAULTLOCALE; + return result; + } + } +} diff --git a/dspace/modules/xmlui/src/main/java/org/dspace/app/xmlui/aspect/viewArtifacts/Navigation.java b/dspace/modules/xmlui/src/main/java/org/dspace/app/xmlui/aspect/viewArtifacts/Navigation.java new file mode 100644 index 0000000..ac12e95 --- /dev/null +++ b/dspace/modules/xmlui/src/main/java/org/dspace/app/xmlui/aspect/viewArtifacts/Navigation.java @@ -0,0 +1,164 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE and NOTICE files at the root of the source + * tree and available online at + * + * http://www.dspace.org/license/ + */ +package org.dspace.app.xmlui.aspect.viewArtifacts; + +import org.apache.cocoon.caching.CacheableProcessingComponent; +import org.apache.cocoon.environment.ObjectModelHelper; +import org.apache.cocoon.environment.Request; +import org.apache.cocoon.util.HashUtil; +import org.apache.excalibur.source.SourceValidity; +import org.apache.excalibur.source.impl.validity.NOPValidity; +import org.dspace.app.util.Util; +import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer; +import org.dspace.app.xmlui.utils.HandleUtil; +import org.dspace.app.xmlui.utils.UIException; +import org.dspace.app.xmlui.wing.WingException; +import org.dspace.app.xmlui.wing.element.Options; +import org.dspace.app.xmlui.wing.element.PageMeta; +import org.dspace.authorize.AuthorizeException; +import org.dspace.content.Collection; +import org.dspace.content.Community; +import org.dspace.content.DSpaceObject; +import org.dspace.content.Item; +import org.dspace.core.ConfigurationManager; +import org.dspace.core.I18nUtil; +import org.xml.sax.SAXException; + +import java.io.IOException; +import java.io.Serializable; +import java.sql.SQLException; +import java.util.Locale; + +/** + * This transform applies the basic navigational links that should be available + * on all pages generated by DSpace. + * + * @author Scott Phillips + * @author Kevin Van de Velde (kevin at atmire dot com) + * @author Mark Diggory (markd at atmire dot com) + * @author Ben Bosman (ben at atmire dot com) + */ +public class Navigation extends AbstractDSpaceTransformer implements CacheableProcessingComponent { + + /** + * Generate the unique caching key. + * This key must be unique inside the space of this component. + */ + public Serializable getKey() { + try { + Request request = ObjectModelHelper.getRequest(objectModel); + String key = request.getScheme() + request.getServerName() + request.getServerPort() + request.getSitemapURI() + request.getQueryString(); + + DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + if (dso != null) + { + key += "-" + dso.getHandle(); + } + + return HashUtil.hash(key); + } + catch (SQLException sqle) + { + // Ignore all errors and just return that the component is not cachable. + return "0"; + } + } + + /** + * Generate the cache validity object. + * + * The cache is always valid. + */ + public SourceValidity getValidity() { + return NOPValidity.SHARED_INSTANCE; + } + + public void addOptions(Options options) throws SAXException, WingException, + UIException, SQLException, IOException, AuthorizeException + { + /* Create skeleton menu structure to ensure consistent order between aspects, + * even if they are never used + */ + options.addList("browse"); + options.addList("account"); + options.addList("context"); + options.addList("administrative"); + } + + /** + * Ensure that the context path is added to the page meta. + */ + public void addPageMeta(PageMeta pageMeta) throws SAXException, + WingException, UIException, SQLException, IOException, + AuthorizeException + { + // FIXME: I don't think these should be set here, but they're needed and I'm + // not sure where else it could go. Perhaps the linkResolver? + Request request = ObjectModelHelper.getRequest(objectModel); + pageMeta.addMetadata("contextPath").addContent(contextPath); + pageMeta.addMetadata("request","queryString").addContent(request.getQueryString()); + pageMeta.addMetadata("request","scheme").addContent(request.getScheme()); + pageMeta.addMetadata("request","serverPort").addContent(request.getServerPort()); + pageMeta.addMetadata("request","serverName").addContent(request.getServerName()); + pageMeta.addMetadata("request","URI").addContent(request.getSitemapURI()); + + String dspaceVersion = Util.getSourceVersion(); + if (dspaceVersion != null) + { + pageMeta.addMetadata("dspace","version").addContent(dspaceVersion); + } + + String analyticsKey = ConfigurationManager.getProperty("xmlui.google.analytics.key"); + if (analyticsKey != null && analyticsKey.length() > 0) + { + analyticsKey = analyticsKey.trim(); + pageMeta.addMetadata("google","analytics").addContent(analyticsKey); + } + + // add metadata for OpenSearch auto-discovery links if enabled + if (ConfigurationManager.getBooleanProperty("websvc.opensearch.autolink")) + { + pageMeta.addMetadata("opensearch", "shortName").addContent( ConfigurationManager.getProperty("websvc.opensearch.shortname") ); + pageMeta.addMetadata("opensearch", "autolink").addContent( "open-search/description.xml" ); + } + + pageMeta.addMetadata("page","contactURL").addContent(contextPath + "/contact"); + pageMeta.addMetadata("page","feedbackURL").addContent(contextPath + "/feedback"); + + +// ############################################################################################# + // Add the locale meta data including language dependant labels + Locale[] locales = I18nUtil.getSupportedLocales(); + for (int i=0; i < locales.length; i++) + { + pageMeta.addMetadata("page", "supportedLocale").addContent(locales[i].toString()); + // now add the appropriate labels + pageMeta.addMetadata("supportedLocale", locales[i].toString()).addContent(locales[i].getDisplayName(locales[i])); + } + pageMeta.addMetadata("page","currentLocale").addContent(context.getCurrentLocale().toString()); +// ############################################################################################# + + + DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + if (dso != null) + { + if (dso instanceof Item) + { + pageMeta.addMetadata("focus","object").addContent("hdl:"+dso.getHandle()); + this.getObjectManager().manageObject(dso); + dso = ((Item) dso).getOwningCollection(); + } + + if (dso instanceof Collection || dso instanceof Community) + { + pageMeta.addMetadata("focus","container").addContent("hdl:"+dso.getHandle()); + this.getObjectManager().manageObject(dso); + } + } + } +} diff --git a/dspace/modules/xmlui/src/main/java/org/dspace/app/xmlui/cocoon/DSpaceLocaleAction.java b/dspace/modules/xmlui/src/main/java/org/dspace/app/xmlui/cocoon/DSpaceLocaleAction.java new file mode 100644 index 0000000..e9980e6 --- /dev/null +++ b/dspace/modules/xmlui/src/main/java/org/dspace/app/xmlui/cocoon/DSpaceLocaleAction.java @@ -0,0 +1,198 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE and NOTICE files at the root of the source + * tree and available online at + * + * http://www.dspace.org/license/ + */ +package org.dspace.app.xmlui.cocoon; + +import org.apache.avalon.framework.configuration.Configurable; +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.parameters.Parameters; + +import org.apache.cocoon.acting.ServiceableAction; +import org.apache.cocoon.environment.Redirector; +import org.apache.cocoon.environment.SourceResolver; +import org.apache.cocoon.i18n.I18nUtils; +import org.apache.cocoon.i18n.I18nUtils.LocaleValidator; + +import org.dspace.app.xmlui.utils.ContextUtil; +import org.dspace.core.ConfigurationManager; +import org.dspace.core.Context; +import org.dspace.core.I18nUtil; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +/** + * This action looks at several places to determine what locale should be used for + * this request. We use cocoon's i18nUtils find local method which will look in + * several places continuing to the next step if no local is found.: + * + * 1. HTTP Request parameter 'locale' + * 2. Session attribute 'locale' + * 3. First matching cookie parameter 'locale' within each cookie sent + * 4. Sitemap parameter "locale" + * 5. Locale setting of the requesting browser or server default + * 6. Default + * 7. Blank + * 8. Fail + * + * Only those locales which are listed in xmlui.supported.locales will be identified, + * if no acceptable locales are found then the default locale will be used. + * + * @author Scott Phillips + */ +public class DSpaceLocaleAction extends ServiceableAction implements Configurable { + + + /** A validator class which tests if a local is a supported locale */ + private static DSpaceLocaleValidator localeValidator; + + /** The default locale if no acceptable locales are identified */ + private static Locale defaultLocale; + + + /** + * Configure the action. + */ + public void configure(Configuration config) + { + if (localeValidator == null) + { + localeValidator = new DSpaceLocaleValidator(); + } + + if (defaultLocale == null) + { + defaultLocale = I18nUtil.getDefaultLocale(); + } + } + + + /** + * Action which obtains the current environments locale information, and + * places it in the objectModel (and optionally in a session/cookie). + */ + public Map act(Redirector redirector, + SourceResolver resolver, + Map objectModel, + String source, + Parameters parameters) + throws Exception { + + Locale locale = I18nUtils.findLocale(objectModel, "locale-attribute", parameters, defaultLocale, false, true, false, localeValidator); + + if (locale == null) { + if (getLogger().isDebugEnabled()) { + getLogger().debug("No locale found, using default"); + } + locale = I18nUtil.getDefaultLocale(); + } + + String localeStr = locale.toString(); + if (getLogger().isDebugEnabled()) { + getLogger().debug("Found locale: " + localeStr); + } + +// ############################################################################################# +// I18nUtils.storeLocale(objectModel, +// "locale-attribute", +// localeStr, +// false, +// false, +// false, +// false); + I18nUtils.storeLocale(objectModel, + "locale-attribute", + localeStr, + false, + true, + false, + false); + Context context = ContextUtil.obtainContext(objectModel); + context.setCurrentLocale(locale); +// ############################################################################################# + + // Set up a map for sitemap parameters + Map<String, String> map = new HashMap<String, String>(); + map.put("language", locale.getLanguage()); + map.put("country", locale.getCountry()); + map.put("variant", locale.getVariant()); + map.put("locale", localeStr); + return map; + } + + + /** + * This validator class works with cocoon's i18nutils class to test if locales are valid. + * For dspace we define a locale as valid if it is listed in xmlui.supported.locales config + * parameter. + */ + public static class DSpaceLocaleValidator implements LocaleValidator { + + /** the list of supported locales that may be used. */ + private List<Locale> supportedLocales; + + /** + * Build a list supported locales to validate against upon object construction. + */ + public DSpaceLocaleValidator() + { +// ############################################################################################# + if (ConfigurationManager.getProperty("webui.supported.locales") != null) + { + supportedLocales = new ArrayList<Locale>(); + +// ############################################################################################# + String supportedLocalesConfig = ConfigurationManager.getProperty("webui.supported.locales"); + + String[] parts = supportedLocalesConfig.split(","); + + for (String part : parts) + { + Locale supportedLocale = I18nUtils.parseLocale(part.trim(), null); + if (supportedLocale != null) + { + supportedLocales.add(supportedLocale); + } + } + } + } + + + /** + * @param name name of the locale (for debugging) + * @param test locale to test + * @return true if locale satisfies validator's criteria + */ + public boolean test(String name, Locale test) + { + // If there are no configured locales the accept them all. + if (supportedLocales == null) + { + return true; + } + + // Otherwise check if they are listed + for (Locale locale : supportedLocales) + { + if (locale.equals(test)) + { + return true; + } + } + + // Fail if not found + return false; + + } + + } + + +} diff --git a/dspace/modules/xmlui/src/main/webapp/themes/Participatorio/lib/css/style.css b/dspace/modules/xmlui/src/main/webapp/themes/Participatorio/lib/css/style.css index 7a998d1..e0a92f4 100644 --- a/dspace/modules/xmlui/src/main/webapp/themes/Participatorio/lib/css/style.css +++ b/dspace/modules/xmlui/src/main/webapp/themes/Participatorio/lib/css/style.css @@ -298,8 +298,7 @@ select.multiple { float: left; width: 665px; margin-top: 10px; - padding-top: 10px; - padding-left: 10px; + padding: 10px; background-color: #EFEFEF; border: 2px solid white; border-radius: 6px; @@ -1489,3 +1488,15 @@ table.discovery-filters th.new-filter-header .searchTime{ color: #999999; } + +h1.ds-div-head{ + font-size: 140%; + padding-bottom: 0px; +} + +#file_news_div_news +#aspect_artifactbrowser_CommunityBrowser_div_comunity-browser +#aspect_artifactbrowser_FrontPageSearch_div_front-page-search{ + margin-top: 0; + margin-bottom: 20px; +} diff --git a/dspace/modules/xmlui/src/main/webapp/themes/Participatorio/lib/xsl/core/page-structure.xsl b/dspace/modules/xmlui/src/main/webapp/themes/Participatorio/lib/xsl/core/page-structure.xsl index 3563800..87e56f0 100644 --- a/dspace/modules/xmlui/src/main/webapp/themes/Participatorio/lib/xsl/core/page-structure.xsl +++ b/dspace/modules/xmlui/src/main/webapp/themes/Participatorio/lib/xsl/core/page-structure.xsl @@ -417,44 +417,28 @@ <!-- Trail... --> - <xsl:template name="buildTrail"> - <div id="ds-trail-wrapper"> - <ul id="ds-trail"> - <!-- Seletor de linguagem pt_BR / en --> - <div id="ds-language-selection"> - <a> - <xsl:attribute name="href"> - <xsl:value-of select="concat($context-path,'/?locale-attribute=pt_BR')"/> - </xsl:attribute> - <xsl:text>Português</xsl:text> - </a> - <a> - <xsl:attribute name="href"> - <xsl:value-of select="concat($context-path,'/?locale-attribute=en')"/> - </xsl:attribute> - <xsl:text>English</xsl:text> - </a> - </div> -<!-- ############################################################################################# --> -<!-- Seletor de linguagem baseado no que está ativo no arquivo de configuração do dspace (webui.supported.locales) --> -<!-- Infelizmente, não funciona... algum problema com a geração de pageMeta, provavelmente no metodo --> -<!-- org.dspace.app.xmlui.aspect.viewArtifacts.Navigation.addPageMeta --> -<!-- Display a language selection if more than 1 language is supported --> -<!-- <xsl:if test="count(/dri:document/dri:meta/dri:pageMeta/dri:metadata[@element='page'][@qualifier='supportedLocale']) > 1"> --> -<!-- <div id="ds-language-selection"> --> -<!-- <xsl:for-each select="/dri:document/dri:meta/dri:pageMeta/dri:metadata[@element='page'][@qualifier='supportedLocale']"> --> -<!-- <xsl:variable name="locale" select="."/> --> -<!-- <a> --> -<!-- <xsl:attribute name="href"> --> -<!-- <xsl:value-of select="concat($context-path,'/?locale-attribute=')"/> --> -<!-- <xsl:value-of select="$locale"/> --> -<!-- </xsl:attribute> --> -<!-- <xsl:value-of select="/dri:document/dri:meta/dri:pageMeta/dri:metadata[@element='supportedLocale'][@qualifier=$locale]"/> --> -<!-- </a> --> -<!-- </xsl:for-each> --> -<!-- </div> --> -<!-- </xsl:if> --> -<!-- ############################################################################################# --> + <xsl:template name="buildTrail"> + <div id="ds-trail-wrapper"> + <ul id="ds-trail"> + <!-- Display a language selection if more than 1 language is supported --> + <xsl:if + test="count(/dri:document/dri:meta/dri:pageMeta/dri:metadata[@element='page'][@qualifier='supportedLocale']) > 1"> + <div id="ds-language-selection"> + <xsl:for-each + select="/dri:document/dri:meta/dri:pageMeta/dri:metadata[@element='page'][@qualifier='supportedLocale']"> + <xsl:variable name="locale" select="." /> + <a> + <xsl:attribute name="href"> + <xsl:value-of select="concat($context-path,'/?locale-attribute=')" /> + <xsl:value-of select="$locale" /> + </xsl:attribute> + <xsl:value-of + select="/dri:document/dri:meta/dri:pageMeta/dri:metadata[@element='supportedLocale'][@qualifier=$locale]" /> + </a> + </xsl:for-each> + </div> + </xsl:if> + <xsl:choose> <xsl:when test="starts-with($request-uri, 'page/about')"> <li class="ds-trail-link first-link"> -- GitLab