+ */
+public class LanguageUtil {
+
+ private static org.apache.log4j.Logger s_log = org.apache.log4j.Logger.getLogger(
+ LanguageUtil.class);
+ private static String s_languages = null;
+ private static String[] s_languagesArray = null;
+ /**
+ * Mapping from the ISO639-1 2-letter codes to the ISO639-2 3-letter codes
+ */
+ private static final String ISO639_2LA_3LA = "com.arsdigita.cms.util.iso639rev";
+ private static ResourceBundle s_lang3LA = ResourceBundle.getBundle(ISO639_2LA_3LA);
+ /**
+ * Mapping from the ISO639-1 2-letter codes to the full descriptive name
+ */
+ private static final String ISO639_2LA_FULL = "com.arsdigita.cms.util.iso639full";
+ private static ResourceBundle s_langFull = ResourceBundle.getBundle(ISO639_2LA_FULL);
+
+ public static GlobalizedMessage globalize(String key) {
+ return new LanguageGlobalizedMessage(key);
+ }
+
+ /**
+ * Sets the supported languages, eliminates all spaces and trims
+ *
+ * @param comma separated list of langages initialized from initializer at the server startup
+ */
+ public static void setSupportedLanguages(String languages) {
+ s_languages = languages.replace(" ", "").trim();
+ }
+
+ /**
+ * Get the comma separated list of all supported languages
+ */
+ public static String getSupportedLanguages() {
+ Assert.exists(s_languages, "supported languages not set");
+ return s_languages;
+ }
+
+ /**
+ * Returns the collection of all supported languages.
+ *
+ * @return all supported languages
+ */
+ public static Collection getSupportedLanguages2LA() {
+ String allLanguages = getSupportedLanguages();
+ StringTokenizer tokenizer = new StringTokenizer(allLanguages, ",");
+ Collection langList = new LinkedList();
+ while (tokenizer.hasMoreElements()) {
+ String language = tokenizer.nextToken();
+ langList.add(language);
+ }
+ return langList;
+ }
+
+ /**
+ * Returns the collection of all supported languages. Each entry is a pair of 2 letter code as
+ * key and three letter code as value.
+ *
+ * @return all supported languages
+ */
+ public static Collection getSupportedLanguages3LA() {
+ String allLanguages = getSupportedLanguages();
+ StringTokenizer tokenizer = new StringTokenizer(allLanguages, ",");
+ Collection langList = new LinkedList();
+ while (tokenizer.hasMoreElements()) {
+ String language = tokenizer.nextToken();
+ langList.add(new Pair(language, getLang3LA(language)));
+ }
+ return langList;
+ }
+
+ /**
+ * Returns the collection of all supported languages. Each entry is a pair of 2 letter code as
+ * key and full language name as a value.
+ *
+ * @return all supported languages
+ */
+ public static Collection getSupportedLanguagesFull() {
+ String allLanguages = getSupportedLanguages();
+ StringTokenizer tokenizer = new StringTokenizer(allLanguages, ",");
+ Collection langList = new LinkedList();
+ while (tokenizer.hasMoreElements()) {
+ String language = tokenizer.nextToken();
+ langList.add(new Pair(language, getLangFull(language)));
+ }
+ return langList;
+ }
+
+ /**
+ * Get the List of languages in which this item can be created. Usefull on UI where we need to
+ * display the list of languages in which this Item can be created.
+ */
+ public static Collection getCreatableLanguages(ContentPage item) {
+ ContentBundle bundle = item.getContentBundle();
+ Collection allList = getSupportedLanguages2LA();
+ allList.removeAll(bundle.getLanguages());
+ return allList;
+ }
+
+ /**
+ * Returns three letter acronym for language code mapped from two letter code.
+ *
+ * @return three letter code for the two letter code. If the resource is not found then the key
+ * itself is returned.
+ */
+ public static String getLang3LA(String lang) {
+ String threeLA;
+ try {
+ // Lookup 3-letter language code via java.util.Locale
+ threeLA = (new Locale(lang)).getISO3Language();
+ } catch (MissingResourceException mre) {
+ // If there is none
+ try {
+ // Lookup 3-letter code via ressource bundle
+ threeLA = s_lang3LA.getString(lang);
+ } catch (MissingResourceException mexc) {
+ // if there is still no match, log a warning and return the 2-letter code
+ s_log.warn("Three letter language code for key '" + lang + "' not found: " + mexc);
+ threeLA = lang;
+ }
+ }
+ return threeLA;
+ }
+
+ /**
+ * Returns the full language name mapped from the two letter acronym.
+ *
+ * @param lang 2 letter language code
+ *
+ * @return full language name for the given two letter code If the resource is not found then
+ * the key itself is returned.
+ */
+ public static String getLangFull(String lang) {
+ // Lookup language name via java.util.Locale
+ String fullName = (new Locale(lang)).getDisplayLanguage(GlobalizationHelper.
+ getNegotiatedLocale());
+
+ if (lang.equals(fullName)) {
+ // If that fails
+ try {
+ // Lookup language name vie ressource bundle
+ fullName = s_langFull.getString(lang);
+ } catch (MissingResourceException mexc) {
+ // If there is still nomatch, log a warning and return 2-letter code
+ s_log.warn("Full language name for key '" + lang + "' not found " + mexc);
+ fullName = lang;
+ }
+ }
+ return fullName;
+ }
+
+ /**
+ * Takes in a list of 2 letter codes and converts into 3 letter codes. Each entry is pair of 2
+ * letter code as key and 3 letter code as value.
+ */
+ public static Collection convertTo3LA(Collection list) {
+ Collection conList = new LinkedList();
+ for (Iterator iter = list.iterator(); iter.hasNext();) {
+ String lang2Code = (String) iter.next();
+ conList.add(new Pair(lang2Code, getLang3LA(lang2Code)));
+ }
+ return conList;
+ }
+
+ public static Collection convertToFull(Collection list) {
+ Collection conList = new LinkedList();
+ for (Iterator iter = list.iterator(); iter.hasNext();) {
+ String lang2Code = (String) iter.next();
+ conList.add(new Pair(lang2Code, getLangFull(lang2Code)));
+ }
+ return conList;
+ }
+
+ public static Collection convertToG11N(Collection list) {
+ Collection conList = new LinkedList();
+ for (Iterator iter = list.iterator(); iter.hasNext();) {
+ String lang2Code = (String) iter.next();
+ conList.add(new Pair(lang2Code, globalize(lang2Code)));
+ }
+ return conList;
+ }
+
+ // Special GlobalizedMessage for use with the LanguageUtil#globalize method
+ private static class LanguageGlobalizedMessage extends GlobalizedMessage {
+
+ public LanguageGlobalizedMessage(String key) {
+ super(key);
+ }
+
+ @Override
+ public Object localize(Locale locale) {
+ return LanguageUtil.getLangFull(this.getKey());
+ }
+
+ }
+}
diff --git a/ccm-cms/src/main/resources/com/arsdigita/cms/util/PageClassConfigHandler.java b/ccm-cms/src/main/resources/com/arsdigita/cms/util/PageClassConfigHandler.java
new file mode 100755
index 000000000..118c10bd6
--- /dev/null
+++ b/ccm-cms/src/main/resources/com/arsdigita/cms/util/PageClassConfigHandler.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+package com.arsdigita.cms.util;
+
+
+import org.xml.sax.helpers.DefaultHandler;
+
+import java.util.Map;
+
+/**
+ *
+ * SAX event handler class for parsing configuration file.
+ *
+ * Parse URL-to-Page/Dispatcher/Servlet mappings from a file.
+ *
+ * Format of the file is XML:
+ *
+ * <dispatcher-configuration>
+ * <url-mapping
+ * <url>my-page</url>
+ * OR <page-class>com.arsdigita.Page.class</page-class>
+ * <url-mapping
+ * </dispatcher-configuration>
+ *
+ */
+public class PageClassConfigHandler extends DefaultHandler {
+
+ private Map m_map;
+ private Map m_rmap;
+ private StringBuffer m_buffer;
+ private String m_url;
+ private String m_className;
+
+ /**
+ * @param map A map to configure (pages-> classes)
+ * @param rmap A map to configure (classes-> pages)
+ *
+ * @pre md.m_map != null
+ */
+ public PageClassConfigHandler(Map map, Map rmap) {
+ m_map = map;
+ // reverse map
+ m_rmap = rmap;
+ m_buffer = new StringBuffer();
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int len) {
+ for (int i = 0; i < len; i++) {
+ m_buffer.append(ch[start + i]);
+ }
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qn) {
+ if ( qn.equals("url") ) {
+ m_url = m_buffer.toString().trim();
+ } else if ( qn.equals("page-class") ) {
+ m_className = m_buffer.toString().trim();
+ } else if ( qn.equals("url-mapping") ) {
+ m_map.put(m_url, m_className);
+ m_rmap.put(m_className, m_url);
+ }
+ m_buffer = new StringBuffer();
+ }
+}
diff --git a/ccm-cms/src/main/resources/com/arsdigita/cms/util/SecurityConstants.java b/ccm-cms/src/main/resources/com/arsdigita/cms/util/SecurityConstants.java
new file mode 100755
index 000000000..dde69fd2c
--- /dev/null
+++ b/ccm-cms/src/main/resources/com/arsdigita/cms/util/SecurityConstants.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+package com.arsdigita.cms.util;
+
+
+
+/**
+ * Security class used for checking and granting privileges in
+ * CMS.
+ *
+ * @author Michael Pih
+ * @version $Revision: #7 $ $DateTime: 2004/08/17 23:15:09 $
+ * @version $Id: SecurityConstants.java 2090 2010-04-17 08:04:14Z pboy $
+ */
+public interface SecurityConstants {
+
+ // CMS Actions
+ public final static String STAFF_ADMIN = "staff_admin";
+ public final static String WORKFLOW_ADMIN = "workflow_admin";
+ public final static String CATEGORY_ADMIN = "category_admin";
+ public final static String LIFECYCLE_ADMIN = "lifecycle_admin";
+ public final static String CONTENT_TYPE_ADMIN = "content_type_admin";
+ public final static String PUBLISH = "publish";
+ public final static String NEW_ITEM = "new_item";
+ public final static String PUBLIC_PAGES = "public_pages";
+ public final static String PREVIEW_PAGES = "preview_pages";
+ public final static String ADMIN_PAGES = "admin_pages";
+ public final static String EDIT_ITEM = "edit_item";
+ public final static String SCHEDULE_PUBLICATION = "schedule_publication";
+ public final static String DELETE_ITEM = "delete_item";
+ public final static String APPLY_WORKFLOW = "apply_workflow";
+ public final static String CATEGORIZE_ITEMS = "categorize_items";
+ public final static String DELETE_IMAGES = "delete_images";
+ public final static String APPLY_ALTERNATE_WORKFLOWS = "apply_alternate_workflows";
+
+ // CMS Privileges
+ public final static String CMS_APPLY_ALTERNATE_WORKFLOWS = "cms_apply_alternate_workflows";
+ public final static String CMS_CATEGORIZE_ITEMS = "cms_categorize_items";
+ public final static String CMS_CATEGORY_ADMIN = "cms_category_admin";
+ public final static String CMS_CONTENT_TYPE_ADMIN = "cms_content_type_admin";
+ public final static String CMS_DELETE_ITEM = "cms_delete_item";
+ public final static String CMS_EDIT_ITEM = "cms_edit_item";
+ public final static String CMS_ITEM_ADMIN = "cms_item_admin";
+ public final static String CMS_LIFECYCLE_ADMIN = "cms_lifecycle_admin";
+ public final static String CMS_NEW_ITEM = "cms_new_item";
+ public final static String CMS_PREVIEW_ITEM = "cms_preview_item";
+ public final static String CMS_PUBLISH = "cms_publish";
+ public final static String CMS_APPROVE_ITEM = "cms_approve_item";
+ public final static String CMS_READ_ITEM = "cms_read_item";
+ public final static String CMS_STAFF_ADMIN = "cms_staff_admin";
+ public final static String CMS_WORKFLOW_ADMIN = "cms_workflow_admin";
+}
diff --git a/ccm-cms/src/main/resources/com/arsdigita/cms/util/Util.java b/ccm-cms/src/main/resources/com/arsdigita/cms/util/Util.java
new file mode 100755
index 000000000..fd90026ce
--- /dev/null
+++ b/ccm-cms/src/main/resources/com/arsdigita/cms/util/Util.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+package com.arsdigita.cms.util;
+
+import com.arsdigita.runtime.ConfigError;
+import org.apache.oro.text.perl.Perl5Util;
+
+/**
+ * Utility functions for use by installer classes.
+ *
+ * @author Jon Orris (jorris@redhat.com)
+ * @version $Revision: #6 $ $DateTime: 2004/08/17 23:15:09 $
+ */
+
+public class Util {
+ public static void validateURLParameter(String name, String value)
+ throws ConfigError {
+
+ final String pattern = "/[^A-Za-z_0-9\\-]+/";
+ Perl5Util util = new Perl5Util();
+ if ( util.match(pattern, value) ) {
+ throw new ConfigError
+ ("The \"" + name + "\" parameter must contain only " +
+ " alpha-numeric characters, underscores, and/or hyphens.");
+ }
+ }
+
+}
diff --git a/ccm-cms/src/main/resources/com/arsdigita/cms/util/iso639full.properties b/ccm-cms/src/main/resources/com/arsdigita/cms/util/iso639full.properties
new file mode 100755
index 000000000..56d1e2d1a
--- /dev/null
+++ b/ccm-cms/src/main/resources/com/arsdigita/cms/util/iso639full.properties
@@ -0,0 +1,141 @@
+aa=Afar
+ab=Abkhazian
+af=Afrikaans
+am=Amharic
+ar=Arabic
+as=Assamese
+ay=Aymara
+az=Azerbaijani
+ba=Bashkir
+be=Byelorussian
+bg=Bulgarian
+bh=Bihari
+bi=Bislama
+bn=Bengali;=Bangla
+bo=Tibetan
+br=Breton
+ca=Catalan
+co=Corsican
+cs=Czech
+cy=Welsh
+da=Danish
+de=German
+dz=Bhutani
+el=Greek
+en=English
+eo=Esperanto
+es=Spanish
+et=Estonian
+eu=Basque
+fa=Persian
+fi=Finnish
+fj=Fiji
+fo=Faroese
+fr=French
+fy=Frisian
+ga=Irish
+gd=Scots=Gaelic
+gl=Galician
+gn=Guarani
+gu=Gujarati
+ha=Hausa
+he=Hebrew
+hi=Hindi
+hr=Croatian
+hu=Hungarian
+hy=Armenian
+ia=Interlingua
+id=Indonesian
+ie=Interlingue
+ik=Inupiak
+is=Icelandic
+it=Italian
+iu=Inuktitut
+iw=Hebrew
+ja=Japanese
+jw=Javanese
+ka=Georgian
+kk=Kazakh
+kl=Greenlandic
+km=Cambodian
+kn=Kannada
+ko=Korean
+ks=Kashmiri
+ku=Kurdish
+ky=Kirghiz
+la=Latin
+ln=Lingala
+lo=Laothian
+lt=Lithuanian
+lv=Latvian
+mg=Malagasy
+mi=Maori
+mk=Macedonian
+ml=Malayalam
+mn=Mongolian
+mo=Moldavian
+mr=Marathi
+ms=Malay
+mt=Maltese
+my=Burmese
+na=Nauru
+ne=Nepali
+nl=Dutch
+no=Norwegian
+oc=Occitan
+om==Oromo
+or=Oriya
+pa=Punjabi
+pl=Polish
+ps=Pashto,=Pushto
+pt=Portuguese
+qu=Quechua
+rm=Rhaeto-Romance
+rn=Kirundi
+ro=Romanian
+ru=Russian
+rw=Kinyarwanda
+sa=Sanskrit
+sd=Sindhi
+sg=Sangho
+sh=Serbo-Croatian
+si=Sinhalese
+sk=Slovak
+sl=Slovenian
+sm=Samoan
+sn=Shona
+so=Somali
+sq=Albanian
+sr=Serbian
+ss=Siswati
+st=Sesotho
+su=Sundanese
+sv=Swedish
+sw=Swahili
+ta=Tamil
+te=Telugu
+tg=Tajik
+th=Thai
+ti=Tigrinya
+tk=Turkmen
+tl=Tagalog
+tn=Setswana
+to=Tonga
+tr=Turkish
+ts=Tsonga
+tt=Tatar
+tw=Twi
+ug=Uighur
+uk=Ukrainian
+ur=Urdu
+uz=Uzbek
+vi=Vietnamese
+vo=Volapuk
+wo=Wolof
+xh=Xhosa
+yi=Yiddish
+yo=Yoruba
+za=Zhuang
+zh=Chinese
+zu=Zulu
+--=Undefined
diff --git a/ccm-cms/src/main/resources/com/arsdigita/cms/util/iso639rev.properties b/ccm-cms/src/main/resources/com/arsdigita/cms/util/iso639rev.properties
new file mode 100755
index 000000000..3cb40744c
--- /dev/null
+++ b/ccm-cms/src/main/resources/com/arsdigita/cms/util/iso639rev.properties
@@ -0,0 +1,138 @@
+aa=aar
+ab=abk
+af=afr
+am=amh
+ar=ara
+as=asm
+ay=aym
+az=aze
+ba=bak
+be=bel
+be=bre
+bg=bul
+bh=bih
+bi=bis
+bn=ben
+bo=bod
+ca=cat
+co=cos
+cs=ces
+cy=cym
+da=dan
+de=deu
+dz=dzo
+el=ell
+en=eng
+eo=epo
+es=spa
+et=est
+eu=baq
+fa=fas
+fi=fin
+fj=fij
+fo=fao
+fr=fra
+fy=fry
+ga=gai
+gl=glg
+gn=grn
+gu=guj
+ha=hau
+he=heb
+hi=hin
+hr=hrv
+hu=hun
+hy=arm
+ia=ina
+id=ind
+ik=ipk
+is=ice
+it=ita
+iu=iku
+iw=heb
+ja=jpn
+jv=jav
+jw=jaw
+ka=kat
+kk=kaz
+kl=kal
+km=khm
+kn=kan
+ko=kor
+ks=kas
+ku=kur
+ky=kir
+la=lat
+ln=lin
+lo=lao
+lt=lit
+lv=lav
+mg=mlg
+mi=mri
+mk=mak
+ml=mlt
+mn=mon
+mo=mol
+mr=mar
+ms=msa
+my=mya
+na=nau
+ne=nep
+nl=dut
+no=nor
+oc=oci
+om=orm
+or=ori
+pa=pan
+pl=pol
+ps=pus
+pt=por
+qu=que
+rm=roh
+rn=run
+ro=ron
+ru=rus
+rw=kin
+sa=san
+sd=snd
+sg=sag
+sh=scr
+si=sin
+sk=slk
+sl=slv
+sm=smo
+sn=sna
+so=som
+sq=sqi
+sr=ser
+ss=ssw
+st=sot
+su=sun
+sv=sve
+sw=swa
+ta=tam
+te=tel
+tg=tgk
+th=tha
+ti=tir
+tk=tuk
+tl=tgl
+tn=tsn
+to=tog
+tr=tur
+ts=tso
+tt=tat
+tw=twi
+ug=uig
+uk=ukr
+ur=urd
+uz=uzb
+vi=vie
+vo=vol
+wo=wol
+xh=xho
+yi=yid
+yo=yor
+za=zha
+zh=zho
+zu=zul
diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources.properties
index 1c840d69c..d6aea8ed4 100644
--- a/ccm-cms/src/main/resources/org/librecms/CmsResources.properties
+++ b/ccm-cms/src/main/resources/org/librecms/CmsResources.properties
@@ -272,3 +272,10 @@ cms.ui.assets.binaryasset.filename=File name
cms.ui.assets.binaryasset.mimetype=Type
cms.ui.assets.binaryasset.size=Size (bytes)
cms.ui.categories=Categories
+cms.ui.new_item=Create new content item
+cms.ui.authoring.content_type=Content Type:
+#Language
+cms.ui.language.field=Sprache
+cms.ui.authoring.workflow=Select a workflow
+cms.ui.create=Create
+cms.contenttypes.ui.summary=Summary
diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties
index 2681f5da3..487f1da76 100644
--- a/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties
+++ b/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties
@@ -270,3 +270,10 @@ cms.ui.assets.binaryasset.filename=Dateiname
cms.ui.assets.binaryasset.mimetype=Typ
cms.ui.assets.binaryasset.size=Gr\u00f6\u00dfe (Bytes)
cms.ui.categories=Kategorien
+cms.ui.new_item=Neues Content Item angelegen
+cms.ui.authoring.content_type=Content Typ:
+#Language
+cms.ui.language.field=Sprache
+cms.ui.authoring.workflow=Arbeitsablauf ausw\u00e4hlen
+cms.ui.create=Anlegen
+cms.contenttypes.ui.summary=Zusammenfassung
diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties
index c147f5d3c..798c94e3b 100644
--- a/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties
+++ b/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties
@@ -229,3 +229,10 @@ cms.ui.assets.binaryasset.filename=File name
cms.ui.assets.binaryasset.mimetype=Type
cms.ui.assets.binaryasset.size=Size (bytes)
cms.ui.categories=Categories
+cms.ui.new_item=New item
+cms.ui.authoring.content_type=Content Type:
+#Language
+cms.ui.language.field=Sprache
+cms.ui.authoring.workflow=Select a workflow
+cms.ui.create=Create
+cms.contenttypes.ui.summary=Summary
diff --git a/ccm-core/src/main/java/org/libreccm/admin/ui/AdminView.java b/ccm-core/src/main/java/org/libreccm/admin/ui/AdminView.java
index 850bed7e9..61c53b6bf 100644
--- a/ccm-core/src/main/java/org/libreccm/admin/ui/AdminView.java
+++ b/ccm-core/src/main/java/org/libreccm/admin/ui/AdminView.java
@@ -36,6 +36,8 @@ import com.vaadin.ui.Label;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.VerticalLayout;
import org.apache.shiro.subject.Subject;
+import org.libreccm.admin.ui.usersgroupsroles.UsersGroupsRoles;
+import org.libreccm.admin.ui.usersgroupsroles.UsersTableDataProvider;
import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.security.PermissionChecker;
import org.libreccm.security.User;
@@ -72,7 +74,7 @@ public class AdminView extends CustomComponent implements View {
@Inject
private JpqlConsoleController jpqlConsoleController;
-
+
@Inject
private Subject subject;
@@ -81,6 +83,9 @@ public class AdminView extends CustomComponent implements View {
@Inject
private GlobalizationHelper globalizationHelper;
+
+ @Inject
+ private UsersTableDataProvider usersTableDataProvider;
private ResourceBundle bundle;
@@ -88,46 +93,49 @@ public class AdminView extends CustomComponent implements View {
private UserRepository userRepo;
private final TabSheet tabSheet;
- private final Grid usersTable;
-
+// private final Grid usersTable;
+ private final UsersGroupsRoles usersGroupsRoles;
+
private final JpqlConsole jpqlConsole;
public AdminView() {
tabSheet = new TabSheet();
- final TabSheet userGroupsRoles = new TabSheet();
- usersTable = new Grid<>();
- usersTable.setWidth("100%");
-// usersTable.setItems(userRepo.findAll());
- usersTable.addColumn(User::getName)
- .setId(COL_USER_NAME)
- .setCaption("User name");
- usersTable
- .addColumn(User::getGivenName)
- .setId(COL_GIVEN_NAME)
- .setCaption("Given name");
- usersTable
- .addColumn(User::getFamilyName)
- .setId(COL_FAMILY_NAME)
- .setCaption("Family name");
- usersTable
- .addColumn(user -> user.getPrimaryEmailAddress().getAddress())
- .setId(COL_EMAIL)
- .setCaption("E-Mail");
- usersTable
- .addColumn(user -> {
- if (user.isBanned()) {
- return bundle.getString("ui.admin.user.banned_yes");
- } else {
- return bundle.getString("ui.admin.user.banned_no");
- }
- })
- .setId(COL_BANNED)
- .setCaption("Banned?");
- userGroupsRoles.addTab(usersTable, "Users");
-
- tabSheet.addTab(userGroupsRoles, "Users/Groups/Roles");
+// final TabSheet userGroupsRoles = new TabSheet();
+// usersTable = new Grid<>();
+// usersTable.setWidth("100%");
+//// usersTable.setItems(userRepo.findAll());
+// usersTable.addColumn(User::getName)
+// .setId(COL_USER_NAME)
+// .setCaption("User name");
+// usersTable
+// .addColumn(User::getGivenName)
+// .setId(COL_GIVEN_NAME)
+// .setCaption("Given name");
+// usersTable
+// .addColumn(User::getFamilyName)
+// .setId(COL_FAMILY_NAME)
+// .setCaption("Family name");
+// usersTable
+// .addColumn(user -> user.getPrimaryEmailAddress().getAddress())
+// .setId(COL_EMAIL)
+// .setCaption("E-Mail");
+// usersTable
+// .addColumn(user -> {
+// if (user.isBanned()) {
+// return bundle.getString("ui.admin.user.banned_yes");
+// } else {
+// return bundle.getString("ui.admin.user.banned_no");
+// }
+// })
+// .setId(COL_BANNED)
+// .setCaption("Banned?");
+// userGroupsRoles.addTab(usersTable, "Users");
+//
+// tabSheet.addTab(userGroupsRoles, "Users/Groups/Roles");
+ usersGroupsRoles = new UsersGroupsRoles(this);
+ tabSheet.addTab(usersGroupsRoles, "Users/Groups/Roles");
final ServletContext servletContext = VaadinServlet
.getCurrent()
@@ -139,54 +147,12 @@ public class AdminView extends CustomComponent implements View {
jpqlConsole = null;
}
-// final CssLayout header = new CssLayout() {
-//
-// private static final long serialVersionUID = -4372147161604688854L;
-//
-// @Override
-// protected String getCss(final Component component) {
-// /*if ((component instanceof Image)
-// && "libreccm-logo".equals(component.getId())) {
-//
-// return "position: absolute; top: 10px; left: 10px;";
-//
-// } else if ((component instanceof Label)
-// && "libreccm-headerinfoline".equals(component
-// .getId())) {
-// return "background-color: #8b8e8a; width: 100%; position: absolute; top:120px; left: 0";
-// }*/
-// return "";
-//
-//// return ".v-csslayout {\n"
-//// + "background-color: #56a1bd;\n"
-//// + "background-image: -ie-linear-gradient(top , #56a1db 5%, #024c68 95%\n"
-//// + "background-image: -moz-linear-gradient(top , #56a1db 5%, #024c68 95%\n"
-//// + "background-image: -webkit-linear-gradient(top , #56a1db 5%, #024c68 95%\n"
-//// + "background-image: linear-gradient(top , #56a1db 5%, #024c68 95%\n"
-//// + "}\n"
-//// + "\n"
-//// + ".libreccm-logo {\n"
-//// + "border-left: 10px solid #0f0;\n"
-//// + "}\n";
-// }
-//
-// };
-// header.setWidth("100%");
-// header.setHeight("5em");
final GridLayout header = new GridLayout(5, 1);
header.setWidth("100%");
header.addStyleName("libreccm-header");
-// final Image logo = new Image(
-// "",
-// new ClassResource("/themes/libreccm-default/images/libreccm.png"));
-// logo.setId("libreccm-logo");
-// logo.addStyleName("libreccm-logo");
-// header.addComponent(logo, 0, 0);
-// header.setComponentAlignment(logo, Alignment.MIDDLE_LEFT);
final Label headerInfoLine = new Label("LibreCCM");
headerInfoLine.setId("libreccm-headerinfoline");
-// headerInfoLine.setWidth("100%");
header.addComponent(headerInfoLine, 3, 0, 4, 0);
header.setComponentAlignment(headerInfoLine, Alignment.TOP_RIGHT);
@@ -216,20 +182,19 @@ public class AdminView extends CustomComponent implements View {
bundle = ResourceBundle
.getBundle(AdminUiConstants.ADMIN_BUNDLE,
globalizationHelper.getNegotiatedLocale());
+
+ usersGroupsRoles.setDataProvider(usersTableDataProvider);
}
@Override
public void enter(final ViewChangeListener.ViewChangeEvent event) {
-// if (!subject.isAuthenticated()) {
-// getUI().getNavigator().navigateTo(LoginView.VIEWNAME);
-// }
- usersTable.setItems(userRepo.findAll());
+// usersGroupsRoles.setUsers(userRepo.findAll());
}
-
+
protected JpqlConsoleController getJpqlConsoleController() {
return jpqlConsoleController;
}
-
+
}
diff --git a/ccm-core/src/main/java/org/libreccm/admin/ui/usersgroupsroles/UsersGroupsRoles.java b/ccm-core/src/main/java/org/libreccm/admin/ui/usersgroupsroles/UsersGroupsRoles.java
new file mode 100644
index 000000000..18118cdfc
--- /dev/null
+++ b/ccm-core/src/main/java/org/libreccm/admin/ui/usersgroupsroles/UsersGroupsRoles.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2017 LibreCCM Foundation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package org.libreccm.admin.ui.usersgroupsroles;
+
+import com.arsdigita.ui.admin.AdminUiConstants;
+
+import com.vaadin.ui.CustomComponent;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.TabSheet;
+import com.vaadin.ui.UI;
+import org.libreccm.admin.ui.AdminView;
+import org.libreccm.security.User;
+
+import java.util.List;
+import java.util.ResourceBundle;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class UsersGroupsRoles extends CustomComponent {
+
+ private static final long serialVersionUID = 7280416743018127366L;
+
+ private static final String COL_USER_NAME = "username";
+ private static final String COL_GIVEN_NAME = "given_name";
+ private static final String COL_FAMILY_NAME = "family_name";
+ private static final String COL_EMAIL = "email";
+ private static final String COL_BANNED = "banned";
+
+ private final AdminView view;
+
+ private final TabSheet tabSheet;
+
+ private final Grid usersTable;
+
+ public UsersGroupsRoles(final AdminView view) {
+
+ this.view = view;
+
+ final ResourceBundle bundle = ResourceBundle.getBundle(
+ AdminUiConstants.ADMIN_BUNDLE, UI.getCurrent().getLocale());
+
+ tabSheet = new TabSheet();
+ usersTable = new Grid<>();
+ usersTable.setWidth("100%");
+// usersTable.setItems(userRepo.findAll());
+ usersTable.addColumn(User::getName)
+ .setId(COL_USER_NAME)
+ .setCaption("User name");
+ usersTable
+ .addColumn(User::getGivenName)
+ .setId(COL_GIVEN_NAME)
+ .setCaption("Given name");
+ usersTable
+ .addColumn(User::getFamilyName)
+ .setId(COL_FAMILY_NAME)
+ .setCaption("Family name");
+ usersTable
+ .addColumn(user -> user.getPrimaryEmailAddress().getAddress())
+ .setId(COL_EMAIL)
+ .setCaption("E-Mail");
+ usersTable
+ .addColumn(user -> {
+ if (user.isBanned()) {
+ return bundle.getString("ui.admin.user.banned_yes");
+ } else {
+ return bundle.getString("ui.admin.user.banned_no");
+ }
+ })
+ .setId(COL_BANNED)
+ .setCaption("Banned?");
+
+
+ tabSheet.addTab(usersTable, "Users");
+
+ setCompositionRoot(tabSheet);
+
+ }
+
+// public void setUsers(final List users) {
+// usersTable.setItems(users);
+// }
+
+ public void setDataProvider(final UsersTableDataProvider dataProvider) {
+ usersTable.setDataProvider(dataProvider);
+ }
+
+}
diff --git a/ccm-core/src/main/java/org/libreccm/admin/ui/usersgroupsroles/UsersTableDataProvider.java b/ccm-core/src/main/java/org/libreccm/admin/ui/usersgroupsroles/UsersTableDataProvider.java
new file mode 100644
index 000000000..7693a72d8
--- /dev/null
+++ b/ccm-core/src/main/java/org/libreccm/admin/ui/usersgroupsroles/UsersTableDataProvider.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2017 LibreCCM Foundation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package org.libreccm.admin.ui.usersgroupsroles;
+
+import com.vaadin.cdi.ViewScoped;
+import com.vaadin.data.provider.AbstractDataProvider;
+import com.vaadin.data.provider.Query;
+import org.libreccm.security.User;
+
+import java.util.stream.Stream;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
+import javax.transaction.Transactional;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+@ViewScoped
+public class UsersTableDataProvider extends AbstractDataProvider {
+
+ private static final long serialVersionUID = 8849235775786370772L;
+
+ @Inject
+ private EntityManager entityManager;
+
+ @Override
+ public boolean isInMemory() {
+ return false;
+ }
+
+ @Transactional(Transactional.TxType.REQUIRED)
+ @Override
+ public int size(final Query query) {
+ final CriteriaBuilder builder = entityManager
+ .getCriteriaBuilder();
+ CriteriaQuery criteriaQuery = builder
+ .createQuery(Long.class);
+ final Root from = criteriaQuery.from(User.class);
+
+ criteriaQuery = criteriaQuery.select(builder.count(from));
+
+
+
+ return entityManager
+ .createQuery(criteriaQuery)
+ .getSingleResult()
+ .intValue();
+ }
+
+ @Transactional(Transactional.TxType.REQUIRED)
+ @Override
+ public Stream fetch(final Query query) {
+ final CriteriaBuilder builder = entityManager
+ .getCriteriaBuilder();
+ final CriteriaQuery criteriaQuery = builder
+ .createQuery(User.class);
+ final Root from = criteriaQuery.from(User.class);
+
+
+ return entityManager
+ .createQuery(criteriaQuery)
+ .setMaxResults(query.getLimit())
+ .setFirstResult(query.getOffset())
+ .getResultList()
+ .stream();
+ }
+
+}
diff --git a/ccm-core/src/test/java/org/libreccm/core/CcmObjectRepositoryTest.java b/ccm-core/src/test/java/org/libreccm/core/CcmObjectRepositoryTest.java
index e589945cc..d9b43679a 100644
--- a/ccm-core/src/test/java/org/libreccm/core/CcmObjectRepositoryTest.java
+++ b/ccm-core/src/test/java/org/libreccm/core/CcmObjectRepositoryTest.java
@@ -323,8 +323,8 @@ public class CcmObjectRepositoryTest {
* {@link IllegalArgumentException} if called with {@code null} as the
* object to save.
*/
- @Test(expected = IllegalArgumentException.class)
- @ShouldThrowException(IllegalArgumentException.class)
+ @Test(expected = NullPointerException.class)
+ @ShouldThrowException(NullPointerException.class)
@InSequence(500)
public void saveNullValue() {
ccmObjectRepository.save(null);
diff --git a/ccm-core/src/test/java/org/libreccm/security/GroupRepositoryTest.java b/ccm-core/src/test/java/org/libreccm/security/GroupRepositoryTest.java
index 26a72ad01..57e83946e 100644
--- a/ccm-core/src/test/java/org/libreccm/security/GroupRepositoryTest.java
+++ b/ccm-core/src/test/java/org/libreccm/security/GroupRepositoryTest.java
@@ -222,8 +222,8 @@ public class GroupRepositoryTest {
groupRepository.save(group);
}
- @Test(expected = IllegalArgumentException.class)
- @ShouldThrowException(IllegalArgumentException.class)
+ @Test(expected = NullPointerException.class)
+ @ShouldThrowException(NullPointerException.class)
@InSequence(600)
public void saveNullValue() {
groupRepository.save(null);
diff --git a/ccm-core/src/test/java/org/libreccm/security/PartyRepositoryTest.java b/ccm-core/src/test/java/org/libreccm/security/PartyRepositoryTest.java
index 05bebdd5f..db18f7805 100644
--- a/ccm-core/src/test/java/org/libreccm/security/PartyRepositoryTest.java
+++ b/ccm-core/src/test/java/org/libreccm/security/PartyRepositoryTest.java
@@ -250,8 +250,8 @@ public class PartyRepositoryTest {
});
}
- @Test(expected = IllegalArgumentException.class)
- @ShouldThrowException(IllegalArgumentException.class)
+ @Test(expected = NullPointerException.class)
+ @ShouldThrowException(NullPointerException.class)
@InSequence(500)
public void saveNullValue() {
shiro.getSystemUser().execute(() -> partyRepository.save(null));
diff --git a/ccm-core/src/test/java/org/libreccm/security/RoleRepositoryTest.java b/ccm-core/src/test/java/org/libreccm/security/RoleRepositoryTest.java
index 30c6a1579..b25a0dcb1 100644
--- a/ccm-core/src/test/java/org/libreccm/security/RoleRepositoryTest.java
+++ b/ccm-core/src/test/java/org/libreccm/security/RoleRepositoryTest.java
@@ -320,8 +320,8 @@ public class RoleRepositoryTest {
* throws a {@link IllegalArgumentException} is called with {@code null} for
* the {@link Role} to save.
*/
- @Test(expected = IllegalArgumentException.class)
- @ShouldThrowException(IllegalArgumentException.class)
+ @Test(expected = NullPointerException.class)
+ @ShouldThrowException(NullPointerException.class)
@InSequence(600)
public void saveNullValue() {
roleRepository.save(null);
diff --git a/ccm-core/src/test/java/org/libreccm/security/UserRepositoryTest.java b/ccm-core/src/test/java/org/libreccm/security/UserRepositoryTest.java
index 763f16052..377fc5c1a 100644
--- a/ccm-core/src/test/java/org/libreccm/security/UserRepositoryTest.java
+++ b/ccm-core/src/test/java/org/libreccm/security/UserRepositoryTest.java
@@ -289,8 +289,8 @@ public class UserRepositoryTest {
shiro.getSystemUser().execute(() -> userRepository.save(user));
}
- @Test(expected = IllegalArgumentException.class)
- @ShouldThrowException(IllegalArgumentException.class)
+ @Test(expected = NullPointerException.class)
+ @ShouldThrowException(NullPointerException.class)
@InSequence(700)
public void saveNullValue() {
shiro.getSystemUser().execute(() -> userRepository.save(null));
diff --git a/ccm-core/src/test/resources-wildfly-remote-h2-mem/scripts/create_ccm_core_schema.sql b/ccm-core/src/test/resources-wildfly-remote-h2-mem/scripts/create_ccm_core_schema.sql
index 17314a655..95f8fc561 100644
--- a/ccm-core/src/test/resources-wildfly-remote-h2-mem/scripts/create_ccm_core_schema.sql
+++ b/ccm-core/src/test/resources-wildfly-remote-h2-mem/scripts/create_ccm_core_schema.sql
@@ -282,7 +282,7 @@ create schema CCM_CORE;
DEFAULT_VALUE varchar(255),
PARAMETER_MODEL varchar(255),
PARAMETER_NAME varchar(255),
- OBJECT_ID bigint not null,s
+ OBJECT_ID bigint not null,
primary key (OBJECT_ID)
);