001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/importexport/CmsImportVersion6.java,v $
003: * Date : $Date: 2008-02-27 12:05:48 $
004: * Version: $Revision: 1.5 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 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 org.opencms.importexport;
033:
034: import org.opencms.i18n.CmsMessageContainer;
035: import org.opencms.main.CmsLog;
036: import org.opencms.main.OpenCms;
037: import org.opencms.util.CmsDataTypeUtil;
038:
039: import java.util.ArrayList;
040: import java.util.HashMap;
041: import java.util.Iterator;
042: import java.util.List;
043: import java.util.Map;
044:
045: import org.apache.commons.codec.binary.Base64;
046: import org.apache.commons.logging.Log;
047:
048: import org.dom4j.Element;
049:
050: /**
051: * Implementation of the OpenCms Import Interface ({@link org.opencms.importexport.I_CmsImport}) for
052: * the import version 6.<p>
053: *
054: * This import format is used in OpenCms since 6.5.6.<p>
055: *
056: * @author Michael Moossen
057: *
058: * @version $Revision: 1.5 $
059: *
060: * @since 6.5.6
061: *
062: * @see org.opencms.importexport.A_CmsImport
063: *
064: * @deprecated this import class is no longer in use and should only be used to import old export files
065: */
066: public class CmsImportVersion6 extends CmsImportVersion5 {
067:
068: /** The version number of this import implementation.<p> */
069: public static final int IMPORT_VERSION6 = 6;
070:
071: /** The log object for this class. */
072: private static final Log LOG = CmsLog
073: .getLog(CmsImportVersion6.class);
074:
075: /**
076: * Creates a new CmsImportVerion7 object.<p>
077: */
078: public CmsImportVersion6() {
079:
080: m_convertToXmlPage = true;
081: }
082:
083: /**
084: * @see org.opencms.importexport.I_CmsImport#getVersion()
085: */
086: public int getVersion() {
087:
088: return CmsImportVersion6.IMPORT_VERSION6;
089: }
090:
091: /**
092: * Imports the OpenCms users.<p>
093: *
094: * @throws CmsImportExportException if something goes wrong
095: */
096: protected void importUsers() throws CmsImportExportException {
097:
098: try {
099: // getAll user nodes
100: List userNodes = m_docXml.selectNodes("//"
101: + A_CmsImport.N_USERDATA);
102: // walk threw all groups in manifest
103: for (int i = 0; i < userNodes.size(); i++) {
104: Element currentElement = (Element) userNodes.get(i);
105:
106: String name = getChildElementTextValue(currentElement,
107: A_CmsImport.N_NAME);
108: name = OpenCms.getImportExportManager().translateUser(
109: name);
110:
111: // decode passwords using base 64 decoder
112: String pwd = getChildElementTextValue(currentElement,
113: A_CmsImport.N_PASSWORD);
114: String password = new String(Base64.decodeBase64(pwd
115: .trim().getBytes()));
116:
117: String flags = getChildElementTextValue(currentElement,
118: A_CmsImport.N_FLAGS);
119: String firstname = getChildElementTextValue(
120: currentElement, A_CmsImport.N_FIRSTNAME);
121: String lastname = getChildElementTextValue(
122: currentElement, A_CmsImport.N_LASTNAME);
123: String email = getChildElementTextValue(currentElement,
124: A_CmsImport.N_EMAIL);
125: long dateCreated = Long
126: .parseLong(getChildElementTextValue(
127: currentElement,
128: A_CmsImport.N_DATECREATED));
129:
130: // get the userinfo and put it into the additional info map
131: Map userInfo = new HashMap();
132: Iterator itInfoNodes = currentElement.selectNodes(
133: "./" + A_CmsImport.N_USERINFO + "/"
134: + A_CmsImport.N_USERINFO_ENTRY)
135: .iterator();
136: while (itInfoNodes.hasNext()) {
137: Element infoEntryNode = (Element) itInfoNodes
138: .next();
139: String key = infoEntryNode
140: .attributeValue(A_CmsImport.A_NAME);
141: String type = infoEntryNode
142: .attributeValue(A_CmsImport.A_TYPE);
143: String value = infoEntryNode.getTextTrim();
144: userInfo.put(key, CmsDataTypeUtil.dataImport(value,
145: type));
146: }
147:
148: // get the groups of the user and put them into the list
149: List groupNodes = currentElement.selectNodes("*/"
150: + A_CmsImport.N_GROUPNAME);
151: List userGroups = new ArrayList();
152: for (int j = 0; j < groupNodes.size(); j++) {
153: Element currentGroup = (Element) groupNodes.get(j);
154: String userInGroup = getChildElementTextValue(
155: currentGroup, A_CmsImport.N_NAME);
156: userInGroup = OpenCms.getImportExportManager()
157: .translateGroup(userInGroup);
158: userGroups.add(userInGroup);
159: }
160:
161: // import this user
162: importUser(name, flags, password, firstname, lastname,
163: email, dateCreated, userInfo, userGroups);
164: }
165: } catch (CmsImportExportException e) {
166: throw e;
167: } catch (Exception e) {
168: m_report.println(e);
169: CmsMessageContainer message = Messages.get().container(
170: Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_USERS_0);
171: if (LOG.isDebugEnabled()) {
172: LOG.debug(message.key(), e);
173: }
174: throw new CmsImportExportException(message, e);
175: }
176: }
177: }
|