001: /*
002: * File : $Source: /usr/local/cvs/alkacon/com.alkacon.opencms.registration/src/com/alkacon/opencms/registration/CmsProfileXmlContentHandler.java,v $
003: * Date : $Date: 2008-02-19 13:22:30 $
004: * Version: $Revision: 1.1 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Mananagement System
008: *
009: * Copyright (C) 2005 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package com.alkacon.opencms.registration;
033:
034: import com.alkacon.opencms.formgenerator.CmsForm;
035:
036: import org.opencms.file.CmsFile;
037: import org.opencms.file.CmsObject;
038: import org.opencms.main.CmsException;
039: import org.opencms.xml.content.CmsDefaultXmlContentHandler;
040: import org.opencms.xml.content.CmsXmlContent;
041: import org.opencms.xml.types.I_CmsXmlContentValue;
042:
043: import java.util.ArrayList;
044: import java.util.Arrays;
045: import java.util.Iterator;
046: import java.util.List;
047: import java.util.Locale;
048:
049: /**
050: * Xml content handler for the webuser profile.<p>
051: *
052: * @author Michael Moossen
053: *
054: * @version $Revision: 1.1 $
055: *
056: * @since 7.0.3
057: */
058: public class CmsProfileXmlContentHandler extends
059: CmsDefaultXmlContentHandler {
060:
061: /**
062: * Default constructor.<p>
063: */
064: public CmsProfileXmlContentHandler() {
065:
066: super ();
067: }
068:
069: /**
070: * @see org.opencms.xml.content.CmsDefaultXmlContentHandler#prepareForWrite(org.opencms.file.CmsObject, org.opencms.xml.content.CmsXmlContent, org.opencms.file.CmsFile)
071: */
072: public CmsFile prepareForWrite(CmsObject cms,
073: CmsXmlContent content, CmsFile file) throws CmsException {
074:
075: // for each locale
076: Iterator locales = content.getLocales().iterator();
077: while (locales.hasNext()) {
078: Locale locale = (Locale) locales.next();
079: // check unmodifiable fields
080: List unmodifiables = new ArrayList(Arrays
081: .asList(new String[] { "login" }));
082: Iterator fields = content.getValues(
083: CmsForm.NODE_INPUTFIELD, locale).iterator();
084: while (fields.hasNext()) {
085: I_CmsXmlContentValue inputField = (I_CmsXmlContentValue) fields
086: .next();
087: String stringValue = content.getStringValue(cms,
088: inputField.getPath() + "/"
089: + CmsForm.NODE_FIELDLABEL, locale);
090: if (unmodifiables.contains(stringValue)) {
091: throw new CmsException(Messages.get().container(
092: Messages.ERR_MANDATORY_FIELDS_MISSING_1,
093: unmodifiables));
094: } else {
095: int pos = stringValue.lastIndexOf("|");
096: if ((pos >= 0) && (pos < stringValue.length() - 1)) {
097: stringValue = stringValue.substring(pos + 1);
098: if (unmodifiables.contains(stringValue)) {
099: throw new CmsException(
100: Messages
101: .get()
102: .container(
103: Messages.ERR_MANDATORY_FIELDS_MISSING_1,
104: unmodifiables));
105: }
106: }
107: }
108: }
109: }
110: return super.prepareForWrite(cms, content, file);
111: }
112: }
|