diff --git a/ccm-cms/src/com/arsdigita/cms/ContentType.java b/ccm-cms/src/com/arsdigita/cms/ContentType.java index 1bfa63f97..f0919b87c 100755 --- a/ccm-cms/src/com/arsdigita/cms/ContentType.java +++ b/ccm-cms/src/com/arsdigita/cms/ContentType.java @@ -521,10 +521,6 @@ public class ContentType extends ACSObject { } public static ContentTypeCollection getSiblingsOf(ContentType ct) { -// final String query = "com.arsdigita.cms.registeredContentTypes"; -// DataQuery dq = SessionManager.getSession().retrieveQuery(query); -// DataCollection dc = new DataQueryDataCollectionAdapter(dq, "type"); -// return new ContentTypeCollection(dc); ContentTypeCollection ctc = ContentType.getRegisteredContentTypes(); // The Filter Factory diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericPerson.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericPerson.java index be43bbb07..5d9e4e0e6 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericPerson.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericPerson.java @@ -51,7 +51,7 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter private static final String RELATION_ATTRIBUTES = "GenericContactType"; /** Data object type for this domain object */ public static final String BASE_DATA_OBJECT_TYPE = - "com.arsdigita.cms.contenttypes.GenericPerson"; + "com.arsdigita.cms.contenttypes.GenericPerson"; /** * Default constructor. This creates a new (empty) GenericPerson. @@ -90,6 +90,7 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter public void setSurname(String surname) { set(SURNAME, surname); + updateNameAndTitle(); } public String getGivenName() { @@ -98,6 +99,7 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter public void setGivenName(String givenName) { set(GIVENNAME, givenName); + updateNameAndTitle(); } public String getTitlePre() { @@ -106,6 +108,7 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter public void setTitlePre(String titlePre) { set(TITLEPRE, titlePre); + updateNameAndTitle(); } public String getTitlePost() { @@ -114,6 +117,7 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter public void setTitlePost(String titlePost) { set(TITLEPOST, titlePost); + updateNameAndTitle(); } public Date getBirthdate() { @@ -139,16 +143,10 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter * @return {@code titlePre} {@code givenName) {@code surnameName} {@code titlePost} */ public String getFullName() { - String titlePre; - String titlePost; - String givenName; - String surname; - String fullName = ""; - - titlePre = getTitlePre(); - titlePost = getTitlePost(); - givenName = getGivenName(); - surname = getSurname(); + String titlePre = getTitlePre(); + String givenName = getGivenName(); + String surname = getSurname(); + String titlePost = getTitlePost(); if (titlePre == null) { titlePre = ""; @@ -163,17 +161,14 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter surname = ""; } - if (0 == fullName.length()) { - fullName = getTitle(); - } + return String.format("%s %s %s %s", titlePre, givenName, surname, titlePost).trim(); + } - fullName = String.format("%s %s %s %s", - titlePre, - givenName, - surname, - titlePost).trim(); + private void updateNameAndTitle() { + // Sync title and name with CI data + setTitle(getFullName()); + setName(GenericPerson.urlSave(getTitle())); - return fullName; } // Get all contacts for this person @@ -211,4 +206,22 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter public StringTokenizer getRelationAttributes() { return new StringTokenizer(RELATION_ATTRIBUTES, ";"); } + + // Create a ulr save version of the full name + public static String urlSave(String in) { + + // Replacement map + String[][] replacements = {{"ä", "ae"}, {"Ä", "Ae"}, {"ö", "oe"}, {"Ö", "Oe"}, {"ü", "ue"}, {"Ü", "Ue"}, {"ß", "ss"}, {".", ""}}; + + // Replace all spaces with dash + String out = in.replace(" ", "-"); + + // Replace all special chars defined in replacement map + for (int i = 0; i < replacements.length; i++) { + out = out.replace(replacements[i][0], replacements[i][1]); + } + + // Replace all special chars that are not yet replaced with a dash + return out.replaceAll("[^A-Za-z0-9-]", "_"); + } } diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/Link.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/Link.java index 2843f9a54..29a92abdf 100755 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/Link.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/Link.java @@ -47,6 +47,7 @@ import org.apache.log4j.Logger; * * @version $Revision: #7 $ $Date: 2004/08/17 $ * @author Nobuko Asakai (nasakai@redhat.com) + * @author Sören Bernstein (Quasimodo) */ public class Link extends ACSObject { private static final Logger s_log = Logger.getLogger(Link.class); diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/LinkTraversalAdapter.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/LinkTraversalAdapter.java index 14be53428..8df5bd30f 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/LinkTraversalAdapter.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/LinkTraversalAdapter.java @@ -32,6 +32,8 @@ import com.arsdigita.domain.DomainObject; * * This is a modified copy of ContentItemTraversalAdapter to make the * Link-Objects aware of multilingual items (ContentBundle) + * + * @author Sören Bernstein (Quasimodo) */ public class LinkTraversalAdapter extends ContentItemTraversalAdapter { diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonCreate.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonCreate.java index 6f0b84c09..ab574a557 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonCreate.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonCreate.java @@ -73,7 +73,7 @@ public class GenericPersonCreate extends PageCreate { public void validate(FormSectionEvent e) throws FormProcessException { Folder f = m_parent.getFolder(e.getPageState()); Assert.exists(f); - validateNameUniqueness(f, e, urlSave(getFullname(e))); + validateNameUniqueness(f, e, GenericPerson.urlSave(getFullname(e))); } // Process: save fields to the database @@ -89,7 +89,7 @@ public class GenericPersonCreate extends PageCreate { final ContentPage item = createContentPage(state); item.setLanguage((String) data.get(LANGUAGE)); - item.setName(urlSave(fullName)); + item.setName(GenericPerson.urlSave(fullName)); item.setTitle(fullName); if (!ContentSection.getConfig().getHideLaunchDate()) { item.setLaunchDate((Date) data.get(LAUNCH_DATE)); @@ -112,28 +112,28 @@ public class GenericPersonCreate extends PageCreate { m_parent.editItem(state, item); } - // + // Generate full name private String getFullname(FormSectionEvent e) { final FormData data = e.getFormData(); - return data.getString(TITLEPRE) + " " + data.getString(GIVENNAME) + " " + data.getString(SURNAME) + " " + data.getString(TITLEPOST); + String titlePre = data.getString(TITLEPRE); + String givenName = data.getString(GIVENNAME); + String surname = data.getString(SURNAME); + String titlePost = data.getString(TITLEPOST); - } - - // Create a ulr save version of the full name - private String urlSave(String in) { - - // Replacement map - String[][] replacements = {{"ä", "ae"}, {"Ä", "Ae"}, {"ö", "oe"}, {"Ö", "Oe"}, {"ü", "ue"}, {"Ü", "Ue"}, {"ß", "ss"}, {".", ""}}; - - // Replace all spaces with dash - String out = in.replace(" ", "-"); - - // Replace all special chars defined in replacement map - for (int i = 0; i < replacements.length; i++) { - out = out.replace(replacements[i][0], replacements[i][1]); + if (titlePre == null) { + titlePre = ""; + } + if (titlePost == null) { + titlePost = ""; + } + if (givenName == null) { + givenName = ""; + } + if (surname == null) { + surname = ""; } - // Replace all special chars that are not yet replaced with a dash - return out.replaceAll("[^A-Za-z0-9-]", "_"); + return String.format("%s %s %s %s", titlePre, givenName, surname, titlePost).trim(); } + }