GenericPerson

* Titel und Name wird nun synchron zu den Daten gehalten.
 * Ein paar kleine Fehlerkorrekturen

git-svn-id: https://svn.libreccm.org/ccm/trunk@564 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2010-10-09 13:05:35 +00:00
parent d539eae18c
commit ec89055598
5 changed files with 56 additions and 44 deletions

View File

@ -521,10 +521,6 @@ public class ContentType extends ACSObject {
} }
public static ContentTypeCollection getSiblingsOf(ContentType ct) { 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(); ContentTypeCollection ctc = ContentType.getRegisteredContentTypes();
// The Filter Factory // The Filter Factory

View File

@ -90,6 +90,7 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter
public void setSurname(String surname) { public void setSurname(String surname) {
set(SURNAME, surname); set(SURNAME, surname);
updateNameAndTitle();
} }
public String getGivenName() { public String getGivenName() {
@ -98,6 +99,7 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter
public void setGivenName(String givenName) { public void setGivenName(String givenName) {
set(GIVENNAME, givenName); set(GIVENNAME, givenName);
updateNameAndTitle();
} }
public String getTitlePre() { public String getTitlePre() {
@ -106,6 +108,7 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter
public void setTitlePre(String titlePre) { public void setTitlePre(String titlePre) {
set(TITLEPRE, titlePre); set(TITLEPRE, titlePre);
updateNameAndTitle();
} }
public String getTitlePost() { public String getTitlePost() {
@ -114,6 +117,7 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter
public void setTitlePost(String titlePost) { public void setTitlePost(String titlePost) {
set(TITLEPOST, titlePost); set(TITLEPOST, titlePost);
updateNameAndTitle();
} }
public Date getBirthdate() { public Date getBirthdate() {
@ -139,16 +143,10 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter
* @return {@code titlePre} {@code givenName) {@code surnameName} {@code titlePost} * @return {@code titlePre} {@code givenName) {@code surnameName} {@code titlePost}
*/ */
public String getFullName() { public String getFullName() {
String titlePre; String titlePre = getTitlePre();
String titlePost; String givenName = getGivenName();
String givenName; String surname = getSurname();
String surname; String titlePost = getTitlePost();
String fullName = "";
titlePre = getTitlePre();
titlePost = getTitlePost();
givenName = getGivenName();
surname = getSurname();
if (titlePre == null) { if (titlePre == null) {
titlePre = ""; titlePre = "";
@ -163,17 +161,14 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter
surname = ""; surname = "";
} }
if (0 == fullName.length()) { return String.format("%s %s %s %s", titlePre, givenName, surname, titlePost).trim();
fullName = getTitle();
} }
fullName = String.format("%s %s %s %s", private void updateNameAndTitle() {
titlePre, // Sync title and name with CI data
givenName, setTitle(getFullName());
surname, setName(GenericPerson.urlSave(getTitle()));
titlePost).trim();
return fullName;
} }
// Get all contacts for this person // Get all contacts for this person
@ -211,4 +206,22 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter
public StringTokenizer getRelationAttributes() { public StringTokenizer getRelationAttributes() {
return new StringTokenizer(RELATION_ATTRIBUTES, ";"); 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-]", "_");
}
} }

View File

@ -47,6 +47,7 @@ import org.apache.log4j.Logger;
* *
* @version $Revision: #7 $ $Date: 2004/08/17 $ * @version $Revision: #7 $ $Date: 2004/08/17 $
* @author Nobuko Asakai (nasakai@redhat.com) * @author Nobuko Asakai (nasakai@redhat.com)
* @author Sören Bernstein (Quasimodo)
*/ */
public class Link extends ACSObject { public class Link extends ACSObject {
private static final Logger s_log = Logger.getLogger(Link.class); private static final Logger s_log = Logger.getLogger(Link.class);

View File

@ -32,6 +32,8 @@ import com.arsdigita.domain.DomainObject;
* *
* This is a modified copy of ContentItemTraversalAdapter to make the * This is a modified copy of ContentItemTraversalAdapter to make the
* Link-Objects aware of multilingual items (ContentBundle) * Link-Objects aware of multilingual items (ContentBundle)
*
* @author Sören Bernstein (Quasimodo)
*/ */
public class LinkTraversalAdapter public class LinkTraversalAdapter
extends ContentItemTraversalAdapter { extends ContentItemTraversalAdapter {

View File

@ -73,7 +73,7 @@ public class GenericPersonCreate extends PageCreate {
public void validate(FormSectionEvent e) throws FormProcessException { public void validate(FormSectionEvent e) throws FormProcessException {
Folder f = m_parent.getFolder(e.getPageState()); Folder f = m_parent.getFolder(e.getPageState());
Assert.exists(f); Assert.exists(f);
validateNameUniqueness(f, e, urlSave(getFullname(e))); validateNameUniqueness(f, e, GenericPerson.urlSave(getFullname(e)));
} }
// Process: save fields to the database // Process: save fields to the database
@ -89,7 +89,7 @@ public class GenericPersonCreate extends PageCreate {
final ContentPage item = createContentPage(state); final ContentPage item = createContentPage(state);
item.setLanguage((String) data.get(LANGUAGE)); item.setLanguage((String) data.get(LANGUAGE));
item.setName(urlSave(fullName)); item.setName(GenericPerson.urlSave(fullName));
item.setTitle(fullName); item.setTitle(fullName);
if (!ContentSection.getConfig().getHideLaunchDate()) { if (!ContentSection.getConfig().getHideLaunchDate()) {
item.setLaunchDate((Date) data.get(LAUNCH_DATE)); item.setLaunchDate((Date) data.get(LAUNCH_DATE));
@ -112,28 +112,28 @@ public class GenericPersonCreate extends PageCreate {
m_parent.editItem(state, item); m_parent.editItem(state, item);
} }
// // Generate full name
private String getFullname(FormSectionEvent e) { private String getFullname(FormSectionEvent e) {
final FormData data = e.getFormData(); 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);
if (titlePre == null) {
titlePre = "";
}
if (titlePost == null) {
titlePost = "";
}
if (givenName == null) {
givenName = "";
}
if (surname == null) {
surname = "";
} }
// Create a ulr save version of the full name return String.format("%s %s %s %s", titlePre, givenName, surname, titlePost).trim();
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]);
} }
// Replace all special chars that are not yet replaced with a dash
return out.replaceAll("[^A-Za-z0-9-]", "_");
}
} }