All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.util.UserImpl Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.util;

import java.util.HashMap;
import java.util.Map;

import com.hfg.xml.XMLTag;

//------------------------------------------------------------------------------
/**
 Container for user information.
 
@author J. Alex Taylor, hairyfatguy.com
*/ //------------------------------------------------------------------------------ // com.hfg XML/HTML Coding Library // // 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 // // J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com // [email protected] //------------------------------------------------------------------------------ public class UserImpl implements User { private String mUID; private String mName; private String mFirstName; private String mPreferredName; private String mSurname; private String mEmail; private String mPhoneNumber; private String mImageUrl; private String mClientHost; private String mDomain; private Map mFields; private String mTagName = XML_USER; private static final String XML_USER = "User"; private static final String XML_UID = "UID"; private static final String XML_EMAIL = "Email"; private static final String XML_FIRST_NAME = "FirstName"; private static final String XML_PREFERRED_NAME = "PreferredName"; private static final String XML_DOMAIN = "Domain"; private static final String XML_NAME = "Name"; private static final String XML_IMAGE_URL = "ImageUrl"; private static final String XML_CLIENT_HOST = "ClientHost"; //########################################################################### // CONSTRUCTORS //########################################################################### //-------------------------------------------------------------------------- public UserImpl() { } //-------------------------------------------------------------------------- public UserImpl(XMLTag inXMLTag) { inXMLTag.verifyTagName(mTagName); setUID(inXMLTag.getRequiredSubtagByName(XML_UID).getUnescapedContent()); setName(inXMLTag.getRequiredSubtagByName(XML_NAME).getUnescapedContent()); setImageUrl(inXMLTag.getRequiredSubtagByName(XML_IMAGE_URL).getUnescapedContent()); XMLTag emailTag = inXMLTag.getOptionalSubtagByName(XML_EMAIL); if (emailTag != null) { setEmail(emailTag.getUnescapedContent()); } XMLTag clientHostTag = inXMLTag.getOptionalSubtagByName(XML_CLIENT_HOST); if (clientHostTag != null) { setClientHost(clientHostTag.getUnescapedContent()); } } //########################################################################### // PUBLIC METHODS //########################################################################### //-------------------------------------------------------------------------- public XMLTag toXMLTag() { XMLTag parentTag = new XMLTag(XML_USER); parentTag.addSubtag(new XMLTag(XML_UID).setContent(mUID)); parentTag.addSubtag(new XMLTag(XML_NAME).setContent(mName)); parentTag.addSubtag(new XMLTag(XML_IMAGE_URL).setContent(mImageUrl)); if (StringUtil.isSet(mFirstName)) { parentTag.addSubtag(new XMLTag(XML_FIRST_NAME).setContent(mFirstName)); } if (StringUtil.isSet(mPreferredName)) { parentTag.addSubtag(new XMLTag(XML_PREFERRED_NAME).setContent(mPreferredName)); } if (StringUtil.isSet(mEmail)) { parentTag.addSubtag(new XMLTag(XML_EMAIL).setContent(mEmail)); } if (StringUtil.isSet(mClientHost)) { parentTag.addSubtag(new XMLTag(XML_CLIENT_HOST).setContent(mClientHost)); } return parentTag; } //-------------------------------------------------------------------------- @Override public String toString() { return getName(); } //-------------------------------------------------------------------------- public UserImpl setUID(String inValue) { mUID = inValue; return this; } //-------------------------------------------------------------------------- public String getUID() { return mUID; } //-------------------------------------------------------------------------- public UserImpl setName(String inValue) { mName = inValue; // Make an attempt to set the first name and surname values if (StringUtil.isSet(mName) && (null == mSurname || null == mFirstName) && mName.contains(",")) { String[] pieces = mName.split(","); if (pieces.length > 1) { if (null == mSurname) setSurname(pieces[0].trim()); if (null == mFirstName) setFirstName(pieces[1].trim()); } } return this; } //-------------------------------------------------------------------------- public String getName() { return mName; } //-------------------------------------------------------------------------- public UserImpl setFirstName(String inValue) { mFirstName = inValue; return this; } //-------------------------------------------------------------------------- public String getFirstName() { return mFirstName; } //-------------------------------------------------------------------------- public UserImpl setPreferredName(String inValue) { mPreferredName = inValue; return this; } //-------------------------------------------------------------------------- public String getPreferredName() { return mPreferredName; } //-------------------------------------------------------------------------- public UserImpl setSurname(String inValue) { mSurname = inValue; return this; } //-------------------------------------------------------------------------- public String getSurname() { return mSurname; } //-------------------------------------------------------------------------- public UserImpl setDomain(String inValue) { mDomain = inValue; return this; } //-------------------------------------------------------------------------- public String getDomain() { return mDomain; } //-------------------------------------------------------------------------- public UserImpl setEmail(String inValue) { mEmail = inValue; if (mEmail != null && null == mDomain) { int index = mEmail.indexOf("@"); setDomain(mEmail.substring(index + 1)); } return this; } //-------------------------------------------------------------------------- public String getEmail() { return mEmail; } //-------------------------------------------------------------------------- public UserImpl setPhoneNumber(String inValue) { mPhoneNumber = inValue; return this; } //-------------------------------------------------------------------------- public String getPhoneNumber() { return mPhoneNumber; } //-------------------------------------------------------------------------- public UserImpl setImageUrl(String inValue) { mImageUrl = inValue; return this; } //-------------------------------------------------------------------------- public String getImageUrl() { return mImageUrl; } //-------------------------------------------------------------------------- public UserImpl setClientHost(String inValue) { mClientHost = inValue; return this; } //-------------------------------------------------------------------------- public String getClientHost() { return mClientHost; } //-------------------------------------------------------------------------- public UserImpl setField(String inName, String inValue) { if (null == mFields) { mFields = new HashMap<>(20); } mFields.put(inName, inValue); return this; } //-------------------------------------------------------------------------- public String getField(String inName) { return (mFields != null ? mFields.get(inName) : null); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy