001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/common/MemberMapping.java,v 1.8 2007/10/16 06:49:38 lexuanttkhtn Exp $
003: * $Author: lexuanttkhtn $
004: * $Revision: 1.8 $
005: * $Date: 2007/10/16 06:49:38 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding mvnForum MUST remain
012: * intact in the scripts and in the outputted HTML.
013: * The "powered by" text/logo with a link back to
014: * http://www.mvnForum.com and http://www.MyVietnam.net in
015: * the footer of the pages MUST remain visible when the pages
016: * are viewed on the internet or intranet.
017: *
018: * This program is free software; you can redistribute it and/or modify
019: * it under the terms of the GNU General Public License as published by
020: * the Free Software Foundation; either version 2 of the License, or
021: * any later version.
022: *
023: * This program is distributed in the hope that it will be useful,
024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
026: * GNU General Public License for more details.
027: *
028: * You should have received a copy of the GNU General Public License
029: * along with this program; if not, write to the Free Software
030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
031: *
032: * Support can be obtained from support forums at:
033: * http://www.mvnForum.com/mvnforum/index
034: *
035: * Correspondence and Marketing Questions can be sent to:
036: * info at MyVietnam net
037: *
038: * @author: Phong Ta Quoc
039: */
040: package com.mvnforum.common;
041:
042: import java.io.File;
043: import java.util.ArrayList;
044: import java.util.Collection;
045:
046: import net.myvietnam.mvncore.configuration.DOM4JConfiguration;
047: import net.myvietnam.mvncore.util.FileUtil;
048:
049: import org.apache.commons.logging.Log;
050: import org.apache.commons.logging.LogFactory;
051:
052: public class MemberMapping {
053:
054: private static Log log = LogFactory.getLog(MemberMapping.class);
055:
056: private static final String SCHEMA_MAPPING_FILE = "schemaMapping.xml";
057:
058: private static final String DATABASE = "database";
059: private static final String DISABLE = "disable";
060:
061: private String memberName = DATABASE;
062: private String memberPassword = DATABASE;
063: private String memberFirstEmail = DATABASE;
064: private String memberEmail = DATABASE;
065: private String memberEmailVisible = DATABASE;
066: private String memberNameVisible = DATABASE;
067: private String memberFirstIP = DATABASE;
068: private String memberLastIP = DATABASE;
069: private String memberViewCount = DATABASE;
070: private String memberPostCount = DATABASE;
071: private String memberCreationDate = DATABASE;
072: private String memberModifiedDate = DATABASE;
073: private String memberExpireDate = DATABASE;
074: private String memberLastLogon = DATABASE;
075: private String memberOption = DATABASE;
076: private String memberStatus = DATABASE;
077: private String memberActivateCode = DATABASE;
078: private String memberTempPassword = DATABASE;
079: private String memberMessageCount = DATABASE;
080: private String memberMessageOption = DATABASE;
081: private String memberPostsPerPage = DATABASE;
082: private String memberWarnCount = DATABASE;
083: private String memberVoteCount = DATABASE;
084: private String memberVoteTotalStars = DATABASE;
085: private String memberRewardPoints = DATABASE;
086: private String memberTitle = DATABASE;
087: private String memberTimeZone = DATABASE;
088: private String memberSignature = DATABASE;
089: private String memberAvatar = DATABASE;
090: private String memberSkin = DATABASE;
091: private String memberLanguage = DATABASE;
092: private String memberFirstname = DATABASE;
093: private String memberLastname = DATABASE;
094: private String memberGender = DATABASE;
095: private String memberBirthday = DATABASE;
096: private String memberAddress = DATABASE;
097: private String memberCity = DATABASE;
098: private String memberState = DATABASE;
099: private String memberCountry = DATABASE;
100: private String memberPhone = DATABASE;
101: private String memberMobile = DATABASE;
102: private String memberFax = DATABASE;
103: private String memberCareer = DATABASE;
104: private String memberHomepage = DATABASE;
105: private String memberYahoo = DATABASE;
106: private String memberAol = DATABASE;
107: private String memberIcq = DATABASE;
108: private String memberMsn = DATABASE;
109: private String memberCoolLink1 = DATABASE;
110: private String memberCoolLink2 = DATABASE;
111:
112: private Collection localFields = new ArrayList();
113: private Collection externalFields = new ArrayList();
114: private Collection externalFieldValues = new ArrayList();
115:
116: private static MemberMapping instance = new MemberMapping();
117:
118: private MemberMapping() {
119: this .loadSchemaMapping();
120: }
121:
122: public static MemberMapping getInstance() {
123: return instance;
124: }
125:
126: public String[] getLocalFields() {
127: return (String[]) localFields.toArray(new String[0]);
128: }
129:
130: public String[] getExternalFields() {
131: return (String[]) externalFields.toArray(new String[0]);
132: }
133:
134: public String[] getExternalFieldValues() {
135: return (String[]) externalFieldValues.toArray(new String[0]);
136: }
137:
138: private void loadSchemaMapping() {
139:
140: try {
141: String configFilename = FileUtil.getServletClassesPath()
142: + SCHEMA_MAPPING_FILE;
143:
144: DOM4JConfiguration mapping = new DOM4JConfiguration(
145: new File(configFilename));
146:
147: memberName = mapping.getString("MemberName");
148: checkField("MemberName", memberName);
149:
150: memberPassword = mapping.getString("MemberPassword");
151: checkField("MemberPassword", memberPassword);
152:
153: memberFirstEmail = mapping.getString("MemberFirstEmail");
154: checkField("MemberFirstEmail", memberFirstEmail);
155:
156: memberEmail = mapping.getString("MemberEmail");
157: checkField("MemberEmail", memberEmail);
158:
159: memberEmailVisible = mapping
160: .getString("MemberEmailVisible");
161: checkField("MemberEmailVisible", memberEmailVisible);
162:
163: memberNameVisible = mapping.getString("MemberNameVisible");
164: checkField("MemberNameVisible", memberNameVisible);
165:
166: memberFirstIP = mapping.getString("MemberFirstIP");
167: checkField("MemberFirstIP", memberFirstIP);
168:
169: memberLastIP = mapping.getString("MemberLastIP");
170: checkField("MemberLastIP", memberLastIP);
171:
172: memberViewCount = mapping.getString("MemberViewCount");
173: checkField("MemberViewCount", memberViewCount);
174:
175: memberPostCount = mapping.getString("MemberPostCount");
176: checkField("MemberPostCount", memberPostCount);
177:
178: memberCreationDate = mapping
179: .getString("MemberCreationDate");
180: checkField("MemberCreationDate", memberCreationDate);
181:
182: memberModifiedDate = mapping
183: .getString("MemberModifiedDate");
184: checkField("MemberModifiedDate", memberModifiedDate);
185:
186: memberExpireDate = mapping.getString("MemberExpireDate");
187: checkField("MemberExpireDate", memberExpireDate);
188:
189: memberLastLogon = mapping.getString("MemberLastLogon");
190: checkField("MemberLastLogon", memberLastLogon);
191:
192: memberOption = mapping.getString("MemberOption");
193: checkField("MemberOption", memberOption);
194:
195: memberStatus = mapping.getString("MemberStatus");
196: checkField("MemberStatus", memberStatus);
197:
198: memberActivateCode = mapping
199: .getString("MemberActivateCode");
200: checkField("MemberActivateCode", memberActivateCode);
201:
202: memberTempPassword = mapping
203: .getString("MemberTempPassword");
204: checkField("MemberTempPassword", memberTempPassword);
205:
206: memberMessageCount = mapping
207: .getString("MemberMessageCount");
208: checkField("MemberMessageCount", memberMessageCount);
209:
210: memberMessageOption = mapping
211: .getString("MemberMessageOption");
212: checkField("MemberMessageOption", memberMessageOption);
213:
214: memberPostsPerPage = mapping
215: .getString("MemberPostsPerPage");
216: checkField("MemberPostsPerPage", memberPostsPerPage);
217:
218: memberWarnCount = mapping.getString("MemberWarnCount");
219: checkField("MemberWarnCount", memberWarnCount);
220:
221: memberVoteCount = mapping.getString("MemberVoteCount");
222: checkField("MemberVoteCount", memberVoteCount);
223:
224: memberVoteTotalStars = mapping
225: .getString("MemberVoteTotalStars");
226: checkField("MemberVoteTotalStars", memberVoteTotalStars);
227:
228: memberRewardPoints = mapping
229: .getString("MemberRewardPoints");
230: checkField("MemberRewardPoints", memberRewardPoints);
231:
232: memberTitle = mapping.getString("MemberTitle");
233: checkField("MemberTitle", memberTitle);
234:
235: memberTimeZone = mapping.getString("MemberTimeZone");
236: checkField("MemberTimeZone", memberTimeZone);
237:
238: memberSignature = mapping.getString("MemberSignature");
239: checkField("MemberSignature", memberSignature);
240:
241: memberAvatar = mapping.getString("MemberAvatar");
242: checkField("MemberAvatar", memberAvatar);
243:
244: memberSkin = mapping.getString("MemberSkin");
245: checkField("MemberSkin", memberSkin);
246:
247: memberLanguage = mapping.getString("MemberLanguage");
248: checkField("MemberLanguage", memberLanguage);
249:
250: memberFirstname = mapping.getString("MemberFirstname");
251: checkField("MemberFirstname", memberFirstname);
252:
253: memberLastname = mapping.getString("MemberLastname");
254: checkField("MemberLastname", memberLastname);
255:
256: memberGender = mapping.getString("MemberGender");
257: checkField("MemberGender", memberGender);
258:
259: memberBirthday = mapping.getString("MemberBirthday");
260: checkField("MemberBirthday", memberBirthday);
261:
262: memberAddress = mapping.getString("MemberAddress");
263: checkField("MemberAddress", memberAddress);
264:
265: memberCity = mapping.getString("MemberCity");
266: checkField("MemberCity", memberCity);
267:
268: memberState = mapping.getString("MemberState");
269: checkField("MemberState", memberState);
270:
271: memberCountry = mapping.getString("MemberCountry");
272: checkField("MemberCountry", memberCountry);
273:
274: memberPhone = mapping.getString("MemberPhone");
275: checkField("MemberPhone", memberPhone);
276:
277: memberMobile = mapping.getString("MemberMobile");
278: checkField("MemberMobile", memberMobile);
279:
280: memberFax = mapping.getString("MemberFax");
281: checkField("MemberFax", memberFax);
282:
283: memberCareer = mapping.getString("MemberCareer");
284: checkField("MemberCareer", memberCareer);
285:
286: memberHomepage = mapping.getString("MemberHomepage");
287: checkField("MemberHomepage", memberHomepage);
288:
289: memberYahoo = mapping.getString("MemberYahoo");
290: checkField("MemberYahoo", memberYahoo);
291:
292: memberAol = mapping.getString("MemberAol");
293: checkField("MemberAol", memberAol);
294:
295: memberIcq = mapping.getString("MemberIcq");
296: checkField("MemberIcq", memberIcq);
297:
298: memberMsn = mapping.getString("MemberMsn");
299: checkField("MemberMsn", memberMsn);
300:
301: memberCoolLink1 = mapping.getString("MemberCoolLink1");
302: checkField("MemberCoolLink1", memberCoolLink1);
303:
304: memberCoolLink2 = mapping.getString("MemberCoolLink2");
305: checkField("MemberCoolLink2", memberCoolLink2);
306: } catch (Throwable e) {
307: log.error("Cannot load the mapping file", e);
308: }
309: }
310:
311: private void checkField(String field, String mappingField) {
312: if (isExternalField(mappingField)) {
313: externalFields.add(field);
314: externalFieldValues.add(mappingField);
315: } else if (isLocalField(mappingField)) {
316: localFields.add(field);
317: }
318: }
319:
320: public static boolean isLocalField(String field) {
321: return field.equals(DATABASE);
322: }
323:
324: public static boolean isExternalField(String field) {
325: return ((field.equals(DISABLE) == false) && (field
326: .equals(DATABASE) == false));
327: }
328:
329: public String getMemberName() {
330: return memberName;
331: }
332:
333: public String getMemberActivateCode() {
334: return memberActivateCode;
335: }
336:
337: public String getMemberAddress() {
338: return memberAddress;
339: }
340:
341: public String getMemberAol() {
342: return memberAol;
343: }
344:
345: public String getMemberAvatar() {
346: return memberAvatar;
347: }
348:
349: public String getMemberBirthday() {
350: return memberBirthday;
351: }
352:
353: public String getMemberCareer() {
354: return memberCareer;
355: }
356:
357: public String getMemberCity() {
358: return memberCity;
359: }
360:
361: public String getMemberCoolLink1() {
362: return memberCoolLink1;
363: }
364:
365: public String getMemberCoolLink2() {
366: return memberCoolLink2;
367: }
368:
369: public String getMemberCountry() {
370: return memberCountry;
371: }
372:
373: public String getMemberCreationDate() {
374: return memberCreationDate;
375: }
376:
377: public String getMemberEmail() {
378: return memberEmail;
379: }
380:
381: public String getMemberEmailVisible() {
382: return memberEmailVisible;
383: }
384:
385: public String getMemberExpireDate() {
386: return memberExpireDate;
387: }
388:
389: public String getMemberFax() {
390: return memberFax;
391: }
392:
393: public String getMemberFirstEmail() {
394: return memberFirstEmail;
395: }
396:
397: public String getMemberFirstIP() {
398: return memberFirstIP;
399: }
400:
401: public String getMemberFirstname() {
402: return memberFirstname;
403: }
404:
405: public String getMemberGender() {
406: return memberGender;
407: }
408:
409: public String getMemberHomepage() {
410: return memberHomepage;
411: }
412:
413: public String getMemberIcq() {
414: return memberIcq;
415: }
416:
417: public String getMemberLanguage() {
418: return memberLanguage;
419: }
420:
421: public String getMemberLastIP() {
422: return memberLastIP;
423: }
424:
425: public String getMemberLastLogon() {
426: return memberLastLogon;
427: }
428:
429: public String getMemberLastname() {
430: return memberLastname;
431: }
432:
433: public String getMemberMessageCount() {
434: return memberMessageCount;
435: }
436:
437: public String getMemberMessageOption() {
438: return memberMessageOption;
439: }
440:
441: public String getMemberMobile() {
442: return memberMobile;
443: }
444:
445: public String getMemberModifiedDate() {
446: return memberModifiedDate;
447: }
448:
449: public String getMemberMsn() {
450: return memberMsn;
451: }
452:
453: public String getMemberNameVisible() {
454: return memberNameVisible;
455: }
456:
457: public String getMemberOption() {
458: return memberOption;
459: }
460:
461: public String getMemberPassword() {
462: return memberPassword;
463: }
464:
465: public String getMemberPhone() {
466: return memberPhone;
467: }
468:
469: public String getMemberPostCount() {
470: return memberPostCount;
471: }
472:
473: public String getMemberPostsPerPage() {
474: return memberPostsPerPage;
475: }
476:
477: public String getMemberRewardPoints() {
478: return memberRewardPoints;
479: }
480:
481: public String getMemberSignature() {
482: return memberSignature;
483: }
484:
485: public String getMemberSkin() {
486: return memberSkin;
487: }
488:
489: public String getMemberState() {
490: return memberState;
491: }
492:
493: public String getMemberStatus() {
494: return memberStatus;
495: }
496:
497: public String getMemberTempPassword() {
498: return memberTempPassword;
499: }
500:
501: public String getMemberTimeZone() {
502: return memberTimeZone;
503: }
504:
505: public String getMemberTitle() {
506: return memberTitle;
507: }
508:
509: public String getMemberViewCount() {
510: return memberViewCount;
511: }
512:
513: public String getMemberVoteCount() {
514: return memberVoteCount;
515: }
516:
517: public String getMemberVoteTotalStars() {
518: return memberVoteTotalStars;
519: }
520:
521: public String getMemberWarnCount() {
522: return memberWarnCount;
523: }
524:
525: public String getMemberYahoo() {
526: return memberYahoo;
527: }
528: }
|