KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > content > DCPersonName


1 /*
2  * DCPersonName.java
3  *
4  * Version: $Revision: 1.5 $
5  *
6  * Date: $Date: 2005/04/20 14:22:33 $
7  *
8  * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
9  * Institute of Technology. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *
15  * - Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * - Neither the name of the Hewlett-Packard Company nor the name of the
23  * Massachusetts Institute of Technology nor the names of their
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38  * DAMAGE.
39  */

40 package org.dspace.content;
41
42 /**
43  * DSpace person name utility class
44  * <P>
45  * Person names in the Dublin Core value table in the DSpace database are stored
46  * in the following simple format:
47  * <P>
48  * <code>Lastname, First name(s)</code>
49  * <P>
50  * <em>FIXME: No policy for dealing with "van"/"van der" and "Jr."</em>
51  *
52  * @author Robert Tansley
53  * @version $Revision: 1.5 $
54  */

55 public class DCPersonName
56 {
57     /** The person's last name */
58     private String JavaDoc lastName;
59
60     /** The person's first name(s) */
61     private String JavaDoc firstNames;
62
63     /** Construct a blank name */
64     public DCPersonName()
65     {
66         lastName = null;
67         firstNames = null;
68     }
69
70     /**
71      * Construct a name from a raw DC value
72      *
73      * @param rawValue
74      * the value entry from the database
75      */

76     public DCPersonName(String JavaDoc rawValue)
77     {
78         // Null by default (representing noone)
79
lastName = null;
80         firstNames = null;
81
82         // Check we've actually been passed a name
83
if ((rawValue != null) && !rawValue.equals(""))
84         {
85             // Extract the last name and first name components
86
int commaIndex = rawValue.indexOf(',');
87
88             // Just in case there's no comma, assume whole thing is
89
// last name
90
if (commaIndex == -1)
91             {
92                 commaIndex = rawValue.length();
93             }
94
95             lastName = rawValue.substring(0, commaIndex);
96
97             // Just in case the first name is blank
98
if (rawValue.length() > (commaIndex + 2))
99             {
100                 firstNames = rawValue.substring(commaIndex + 2);
101             }
102             else
103             {
104                 // Since we have a name, we don't want to
105
// leave the last name as null
106
firstNames = "";
107             }
108         }
109     }
110
111     /**
112      * Construct a name from a last name and first name
113      *
114      * @param lastNameIn
115      * the last name
116      * @param firstNamesIn
117      * the first names
118      */

119     public DCPersonName(String JavaDoc lastNameIn, String JavaDoc firstNamesIn)
120     {
121         lastName = lastNameIn;
122         firstNames = firstNamesIn;
123     }
124
125     /**
126      * Return a string for writing the name to the database
127      *
128      * @return the name, suitable for putting in the database
129      */

130     public String JavaDoc toString()
131     {
132         StringBuffer JavaDoc out = new StringBuffer JavaDoc();
133
134         if (lastName != null)
135         {
136             out.append(lastName);
137
138             if ((firstNames != null) && !firstNames.equals(""))
139             {
140                 out.append(", ").append(firstNames);
141             }
142         }
143
144         return (out.toString());
145     }
146
147     /**
148      * Get the first name(s). Guaranteed non-null.
149      *
150      * @return the first name(s), or an empty string if none
151      */

152     public String JavaDoc getFirstNames()
153     {
154         return ((firstNames == null) ? "" : firstNames);
155     }
156
157     /**
158      * Get the last name. Guaranteed non-null.
159      *
160      * @return the last name, or an empty string if none
161      */

162     public String JavaDoc getLastName()
163     {
164         return ((lastName == null) ? "" : lastName);
165     }
166 }
167
Popular Tags