001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.importexport;
029
030import org.opencms.configuration.CmsConfigurationManager;
031import org.opencms.configuration.CmsParameterConfiguration;
032import org.opencms.db.CmsDbEntryNotFoundException;
033import org.opencms.db.log.CmsLogEntry;
034import org.opencms.file.CmsDataAccessException;
035import org.opencms.file.CmsFile;
036import org.opencms.file.CmsObject;
037import org.opencms.file.CmsProject;
038import org.opencms.file.CmsProperty;
039import org.opencms.file.CmsPropertyDefinition;
040import org.opencms.file.CmsRequestContext;
041import org.opencms.file.CmsResource;
042import org.opencms.file.CmsResourceBuilder;
043import org.opencms.file.CmsResourceFilter;
044import org.opencms.file.CmsUser;
045import org.opencms.file.CmsVfsResourceNotFoundException;
046import org.opencms.file.types.CmsResourceTypePlain;
047import org.opencms.file.types.CmsResourceTypeXmlAdeConfiguration;
048import org.opencms.file.types.CmsResourceTypeXmlContainerPage;
049import org.opencms.file.types.I_CmsResourceType;
050import org.opencms.i18n.CmsMessageContainer;
051import org.opencms.importexport.CmsImportExportManager.TimestampMode;
052import org.opencms.loader.CmsLoaderException;
053import org.opencms.lock.CmsLock;
054import org.opencms.main.CmsException;
055import org.opencms.main.CmsIllegalStateException;
056import org.opencms.main.CmsLog;
057import org.opencms.main.OpenCms;
058import org.opencms.relations.CmsRelationType;
059import org.opencms.relations.I_CmsLinkParseable;
060import org.opencms.report.I_CmsReport;
061import org.opencms.security.CmsAccessControlEntry;
062import org.opencms.security.CmsOrganizationalUnit;
063import org.opencms.security.CmsRole;
064import org.opencms.security.I_CmsPasswordHandler;
065import org.opencms.security.I_CmsPrincipal;
066import org.opencms.ui.apps.lists.CmsListManager;
067import org.opencms.util.CmsCollectionsGenericWrapper;
068import org.opencms.util.CmsDataTypeUtil;
069import org.opencms.util.CmsDateUtil;
070import org.opencms.util.CmsMacroResolver;
071import org.opencms.util.CmsStringUtil;
072import org.opencms.util.CmsUUID;
073import org.opencms.xml.CmsXmlEntityResolver;
074import org.opencms.xml.CmsXmlErrorHandler;
075import org.opencms.xml.content.CmsXmlContent;
076
077import java.io.File;
078import java.io.IOException;
079import java.io.InputStream;
080import java.text.ParseException;
081import java.util.ArrayList;
082import java.util.Arrays;
083import java.util.Collection;
084import java.util.Collections;
085import java.util.HashMap;
086import java.util.HashSet;
087import java.util.Iterator;
088import java.util.List;
089import java.util.Map;
090import java.util.Map.Entry;
091import java.util.Set;
092import java.util.concurrent.atomic.AtomicLong;
093import java.util.zip.ZipFile;
094
095import org.apache.commons.codec.binary.Base64;
096import org.apache.commons.digester3.Digester;
097import org.apache.commons.digester3.Rule;
098import org.apache.commons.logging.Log;
099
100import org.dom4j.Document;
101import org.xml.sax.Attributes;
102import org.xml.sax.SAXException;
103
104import com.google.common.base.Objects;
105import com.google.common.collect.ArrayListMultimap;
106import com.google.common.collect.Multimap;
107
108/**
109 * Adds the XML handler rules for import and export of resources and accounts.<p>
110 *
111 * @since 7.0.4
112 */
113public class CmsImportVersion10 implements I_CmsImport {
114
115    /**
116     * Categories of resources that need to be handled differently in the 'rewrite parseables' import step.
117     */
118    public static enum LinkParsableCategory {
119        /** ADE config (formatters, sitemap configs) */
120        config,
121
122        /** Container pages. */
123        page,
124
125        /** Other contents. */
126        other;
127    }
128
129    /**
130     * Data class to temporarily keep track of relation data for a resource to be imported.<p>
131     */
132    public static class RelationData {
133
134        /** The relation target. */
135        private String m_target;
136
137        /** The target structure id. */
138        private CmsUUID m_targetId;
139
140        /** The relation type. */
141        private CmsRelationType m_type;
142
143        /**
144         * Creates a new instance.<p>
145         *
146         * @param target the relation target path
147         * @param targetId the relation target structure id
148         * @param type the relation type
149         */
150        public RelationData(String target, CmsUUID targetId, CmsRelationType type) {
151
152            super();
153            m_target = target;
154            m_type = type;
155            m_targetId = targetId;
156        }
157
158        /**
159         * @see java.lang.Object#equals(java.lang.Object)
160         */
161        @Override
162        public boolean equals(Object otherObj) {
163
164            if (!(otherObj instanceof RelationData)) {
165                return false;
166            }
167            RelationData other = (RelationData)otherObj;
168            return Objects.equal(m_target, other.m_target)
169                && Objects.equal(m_type, other.m_type)
170                && Objects.equal(m_targetId, other.m_targetId);
171        }
172
173        /**
174         * Gets the relation target path.<p>
175         *
176         * @return the relation target path
177         */
178        public String getTarget() {
179
180            return m_target;
181        }
182
183        /**
184         * Gets the relation target structure id.<p>
185         *
186         * @return the relation target structure id
187         */
188        public CmsUUID getTargetId() {
189
190            return m_targetId;
191        }
192
193        /**
194         * Gets the relation type.<p>
195         *
196         * @return the relation type
197         */
198        public CmsRelationType getType() {
199
200            return m_type;
201        }
202
203        /**
204         * @see java.lang.Object#hashCode()
205         */
206        @Override
207        public int hashCode() {
208
209            return Objects.hashCode(m_target, m_type.getName(), m_targetId);
210
211        }
212
213    }
214
215    /** Tag for the "userinfo / entry name" attribute, contains the additional user info entry name. */
216    public static final String A_NAME = "name";
217
218    /** Tag for the "type" attribute, contains the property type. */
219    public static final String A_TYPE = "type";
220
221    /** The name of the DTD for this import version. */
222    public static final String DTD_FILENAME = "opencms-import10.dtd";
223
224    /** The location of the OpenCms configuration DTD if the default prefix is the system ID. */
225    public static final String DTD_LOCATION = "org/opencms/importexport/";
226
227    /** The version number of this import implementation.<p> */
228    public static final int IMPORT_VERSION10 = 10;
229
230    /** Tag for the "allowed" node, to identify allowed user permissions. */
231    public static final String N_ACCESSCONTROL_ALLOWEDPERMISSIONS = "allowed";
232
233    /** Tag for the "denied" node, to identify denied user permissions. */
234    public static final String N_ACCESSCONTROL_DENIEDPERMISSIONS = "denied";
235
236    /** Tag for the "accesscontrol" node, to identify access control entries. */
237    public static final String N_ACCESSCONTROL_ENTRIES = "accesscontrol";
238
239    /** Tag for the "accessentry" node, to identify a single access control entry. */
240    public static final String N_ACCESSCONTROL_ENTRY = "accessentry";
241
242    /** Tag for the "permissionset" node, to identify a permission set. */
243    public static final String N_ACCESSCONTROL_PERMISSIONSET = "permissionset";
244
245    /** Tag for the "uuidprincipal" node, to identify a principal UUID. */
246    public static final String N_ACCESSCONTROL_PRINCIPAL = "uuidprincipal";
247
248    /** Tag for the "accounts" node. */
249    public static final String N_ACCOUNTS = "accounts";
250
251    /** Tag for the "datecreated" node, contains the date created VFS file attribute. */
252    public static final String N_DATECREATED = "datecreated";
253
254    /** Tag for the "dateexpired" node, contains the expiration date VFS file attribute. */
255    public static final String N_DATEEXPIRED = "dateexpired";
256
257    /** Tag for the "datelastmodified" node, contains the date last modified VFS file attribute. */
258    public static final String N_DATELASTMODIFIED = "datelastmodified";
259
260    /** Tag for the "datereleased" node, contains the release date VFS file attribute. */
261    public static final String N_DATERELEASED = "datereleased";
262
263    /** Tag for the "description" node, contains a users description test. */
264    public static final String N_DESCRIPTION = "description";
265
266    /** Tag for the "destination" node, contains target VFS file name. */
267    public static final String N_DESTINATION = "destination";
268
269    /** Tag for the "email" node, contains a users email. */
270    public static final String N_EMAIL = "email";
271
272    /** Tag for the "file" node, container node for all VFS resources. */
273    public static final String N_FILE = "file";
274
275    /** Tag for the "files" node, container node for all VFS resources. */
276    public static final String N_FILES = "files";
277
278    /** Tag for the "firstname" node, contains a users first name. */
279    public static final String N_FIRSTNAME = "firstname";
280
281    /** Tag for the "flags" node, contains the flags of a VFS resource. */
282    public static final String N_FLAGS = "flags";
283
284    /** Tag for the "group" node, contains a group name. */
285    public static final String N_GROUP = "group";
286
287    /** Tag for the "groups" node, contains a users group data. */
288    public static final String N_GROUPS = "groups";
289
290    /** Tag for the "id" relation attribute, contains the structure id of the target resource of the relation. */
291    public static final String N_ID = "id";
292
293    /** Tag for the "lastname" node, contains a users last name. */
294    public static final String N_LASTNAME = "lastname";
295
296    /** Tag for the "managersgroup" node, contains name of the managers group of the project. */
297    public static final String N_MANAGERSGROUP = "managersgroup";
298
299    /** Tag for the "name" node, contains the name of a property. */
300    public static final String N_NAME = "name";
301
302    /** Tag for the "orgunit" node, starts the organizational unit data. */
303    public static final String N_ORGUNIT = "orgunit";
304
305    /** Tag for the "orgunits" node, starts the organizational unit data. */
306    public static final String N_ORGUNITS = "orgunits";
307
308    /** Tag for the "parentgroup" node, contains a groups parent group fqn. */
309    public static final String N_PARENTGROUP = "parentgroup";
310
311    /** Tag for the "password" node, contains a users encrypted password. */
312    public static final String N_PASSWORD = "password";
313
314    /** Tag for the "path" relation attribute, contains the path to the target resource of the relation. */
315    public static final String N_PATH = "path";
316
317    /** Tag for the "project" node, starts the project data. */
318    public static final String N_PROJECT = "project";
319
320    /** Tag for the "projects" node, starts the project data. */
321    public static final String N_PROJECTS = "projects";
322
323    /** Tag for the "properties" node, starts the list of properties of a VFS resource. */
324    public static final String N_PROPERTIES = "properties";
325
326    /** Tag for the "property" node, starts a property for a VFS resource. */
327    public static final String N_PROPERTY = "property";
328
329    /** Tag in the {@link CmsImportExportManager#EXPORT_MANIFEST} for the "relation" node, starts a relation for a VFS resource. */
330    public static final String N_RELATION = "relation";
331
332    /** Tag for the "relations" node, starts the list of relations of a VFS resources. */
333    public static final String N_RELATIONS = "relations";
334
335    /** Tag for the "resource" node, contains the a organizational unit resource name. */
336    public static final String N_RESOURCE = "resource";
337
338    /** Tag for the "resources" node, contains the list of organizational unit resources. */
339    public static final String N_RESOURCES = "resources";
340
341    /** Tag for the "source" node, contains the source path of a VFS resource in the import zip (or folder). */
342    public static final String N_SOURCE = "source";
343
344    /** Tag for the "type" node, the resource type name of a VFS resource. */
345    public static final String N_TYPE = "type";
346
347    /** Tag for the "user" node, starts the user data. */
348    public static final String N_USER = "user";
349
350    /** Tag for the "usercreated" node, contains the name of the user who created the VFS resource. */
351    public static final String N_USERCREATED = "usercreated";
352
353    /** Tag for the "usergroup" node, the name of a users group. */
354    public static final String N_USERGROUP = "usergroup";
355
356    /** Tag for the "usergroups" node, starts the users group data. */
357    public static final String N_USERGROUPS = "usergroups";
358
359    /** Tag for the "userinfo" node, contains the additional user info. */
360    public static final String N_USERINFO = "userinfo";
361
362    /** Tag for the "userinfo/entry" node, contains the additional user info entry value. */
363    public static final String N_USERINFO_ENTRY = "entry";
364
365    /** Tag for the "userlastmodified" node, contains the name of the user who last modified the VFS resource. */
366    public static final String N_USERLASTMODIFIED = "userlastmodified";
367
368    /** Tag for the "userrole" node, contains an users role name. */
369    public static final String N_USERROLE = "userrole";
370
371    /** Tag for the "userroles" node, starts the users role data. */
372    public static final String N_USERROLES = "userroles";
373
374    /** Tag for the "users" node, starts the list of users. */
375    public static final String N_USERS = "users";
376
377    /** Tag for the "usersgroup" node, contains name of the users group of the project. */
378    public static final String N_USERSGROUP = "usersgroup";
379
380    /** Tag for the "uuidresource" node, contains a the resource UUID of a VFS resource. */
381    public static final String N_UUIDRESOURCE = "uuidresource";
382
383    /** Tag for the "uuidstructure" node, only required for backward compatibility with import version 2. */
384    public static final String N_UUIDSTRUCTURE = "uuidstructure";
385
386    /** Tag for the "value" node, contains the value of a property. */
387    public static final String N_VALUE = "value";
388
389    /** Value for the "shared" property type attribute value. */
390    public static final String PROPERTY_ATTRIB_TYPE_SHARED = "shared";
391
392    /** Constant for the unspecified creation date. */
393    protected static final long DATE_CREATED_UNSPECIFIED = -1;
394
395    /** Constant for using file time as last modification date on file import. */
396    protected static final long DATE_LAST_MODIFICATION_FILETIME = -1;
397
398    /** Constant for an unspecified last modification date. */
399    protected static final long DATE_LAST_MODIFICATION_UNSPECIFIED = -2;
400
401    /** The log object for this class. */
402    private static final Log LOG = CmsLog.getLog(CmsImportVersion10.class);
403
404    /** Cumulative time spent waiting for config updates. */
405    private static final AtomicLong cumulativeConfigWaitTime = new AtomicLong(0l);
406
407    /** The ACE flags value. */
408    protected int m_aceFlags;
409
410    /** The ACE allowed permissions value. */
411    protected int m_acePermissionsAllowed;
412
413    /** The ACE denied permissions value. */
414    protected int m_acePermissionsDenied;
415
416    /** The ACE principal id value. */
417    protected CmsUUID m_acePrincipalId;
418
419    /** The list of ACEs for the current imported resource. */
420    protected List<CmsAccessControlEntry> m_aces;
421
422    /** The cms object. */
423    protected CmsObject m_cms;
424
425    /** The set of resource ids of files which actually are contained in the zip file. */
426    protected Set<CmsUUID> m_contentFiles = new HashSet<CmsUUID>();
427
428    /** The destination value. */
429    protected String m_destination;
430
431    /** The current file counter. */
432    protected int m_fileCounter;
433
434    /** The description of the current group to import. */
435    protected String m_groupDescription;
436
437    /** The flags of the current group to import. */
438    protected int m_groupFlags;
439
440    /** The name of the current group to import. */
441    protected String m_groupName;
442
443    /** The parent of the current group to import. */
444    protected String m_groupParent;
445
446    /** Map of all parent groups that could not be set immediately, because of the import order. */
447    protected Map<String, List<String>> m_groupParents;
448
449    /** True if a modification date has been set. */
450    protected boolean m_hasDateLastModified;
451
452    /** True if a structure id has been set. */
453    protected boolean m_hasStructureId;
454
455    /** The import helper. */
456    protected CmsImportHelper m_helper;
457
458    /** List of ignored properties. */
459    protected List<String> m_ignoredProperties;
460
461    /** List of immutable resources. */
462    protected List<String> m_immutables;
463
464    /** The flag to import ACEs. */
465    protected boolean m_importACEs;
466
467    /** The membership structure. */
468    protected Map<String, Map<String, Map<String, String>>> m_membership;
469
470    /** The current imported organizational unit. */
471    protected CmsOrganizationalUnit m_orgUnit;
472
473    /** The organizational unit description. */
474    protected String m_orgUnitDescription;
475
476    /** The organizational unit flags. */
477    protected int m_orgUnitFlags;
478
479    /** The organizational unit fqn. */
480    protected String m_orgUnitName;
481
482    /** The map of organizational unit resources, this is a global field that will be use at the end of the import. */
483    protected Map<String, List<String>> m_orgUnitResources;
484
485    /** The import parameters to use. */
486    protected CmsImportParameters m_parameters;
487
488    /** The list of resource to be parsed, this is a global list, which will be handled at the end of the import. */
489    protected List<CmsResource> m_parseables;
490
491    /** The project description. */
492    protected String m_projectDescription;
493
494    /** The project managers group name. */
495    protected String m_projectManagers;
496
497    /** The project fqn. */
498    protected String m_projectName;
499
500    /** The current read project resources. */
501    protected List<String> m_projectResources;
502
503    /** The project users group name. */
504    protected String m_projectUsers;
505
506    /** The map of properties for current imported resource. */
507    protected Map<String, CmsProperty> m_properties;
508
509    /** The property name value. */
510    protected String m_propertyName;
511
512    /** The property value value. */
513    protected String m_propertyValue;
514
515    /** The relation id value. */
516    protected CmsUUID m_relationId;
517
518    /** The relation path value. */
519    protected String m_relationPath;
520
521    /** Holds the relation data for the resource to be imported. */
522    protected List<RelationData> m_relationsForResource;
523
524    /** The relation type value. */
525    protected CmsRelationType m_relationType;
526
527    /** The report. */
528    protected I_CmsReport m_report;
529
530    /** The current imported resource. */
531    protected CmsResource m_resource;
532
533    /** Holds the field values for the CmsResource object to be created. */
534    protected CmsResourceBuilder m_resourceBuilder;
535
536    /** The source value. */
537    protected String m_source;
538
539    /** Possible exception during xml parsing. */
540    protected Throwable m_throwable;
541
542    /** The total number of files to import. */
543    protected int m_totalFiles;
544
545    /** The type name. */
546    protected String m_typeName;
547
548    /** The current imported user. */
549    protected CmsUser m_user;
550
551    /** The current user date created. */
552    protected long m_userDateCreated;
553
554    /** The current user email. */
555    protected String m_userEmail;
556
557    /** The current user first name. */
558    protected String m_userFirstname;
559
560    /** The current user flags. */
561    protected int m_userFlags;
562
563    /** The additional information for the current imported user. */
564    protected Map<String, Object> m_userInfos;
565
566    /** The current user last name. */
567    protected String m_userLastname;
568
569    /** The current user name. */
570    protected String m_userName;
571
572    /** The current user password. */
573    protected String m_userPassword;
574
575    /** The export version. */
576    protected int m_version;
577
578    /**
579     * Maps index of files in import to structure ids of imported resources.
580     * Necessary because not all entries in the manifest may have a structure id, and even for entries
581     * with a structure id, there may be a pre-existing resource at the same path with a different structure id.
582     */
583    private Map<Integer, CmsUUID> m_indexToStructureId;
584
585    /** Map to keep track of relation data for resources to be imported. */
586    private Multimap<Integer, RelationData> m_relationData;
587
588    /** True if the resource id has not been set. */
589    private boolean m_resourceIdWasNull;
590
591    /**
592     * Public constructor.<p>
593     */
594    public CmsImportVersion10() {
595
596        // empty
597    }
598
599    /**
600     * Parses the links.<p>
601     *
602     * @param cms the CMS context to use
603     * @param parseables the list of resources for which to parse the links
604     * @param report the report
605     */
606    public static void parseLinks(CmsObject cms, List<CmsResource> parseables, I_CmsReport report) {
607
608        int i = 0;
609
610        // group parseables into categories that need to be handled differently.
611        //
612        //  - container pages need to be rewritten before contents (because the contents' gallery titles
613        //    may reference the container page they're in)
614        //
615        // - configurations need to be rewritten *and* loaded before container pages
616        //   (because how the container page is written may depend on a sitemap configuration
617        //   in the same import).
618
619        ArrayListMultimap<LinkParsableCategory, CmsResource> resourcesByCategory = ArrayListMultimap.create();
620        for (CmsResource resource : parseables) {
621            LinkParsableCategory category = LinkParsableCategory.other;
622            if (CmsResourceTypeXmlContainerPage.isContainerPage(resource)) {
623                category = LinkParsableCategory.page;
624            } else {
625                I_CmsResourceType resType = OpenCms.getResourceManager().getResourceType(resource);
626                if ((resType instanceof CmsResourceTypeXmlAdeConfiguration)
627                    && !OpenCms.getResourceManager().matchResourceType(
628                        CmsListManager.RES_TYPE_LIST_CONFIG,
629                        resource.getTypeId())) {
630                    category = LinkParsableCategory.config;
631                }
632            }
633            resourcesByCategory.put(category, resource);
634        }
635
636        for (LinkParsableCategory category : Arrays.asList(
637            LinkParsableCategory.config,
638            LinkParsableCategory.page,
639            LinkParsableCategory.other)) {
640
641            List<CmsResource> resourcesInCurrentCategory = resourcesByCategory.get(category);
642            resourcesInCurrentCategory.sort((a, b) -> a.getRootPath().compareTo(b.getRootPath()));
643            for (CmsResource parsableRes : resourcesInCurrentCategory) {
644                String resName = cms.getSitePath(parsableRes);
645
646                report.print(
647                    org.opencms.report.Messages.get().container(
648                        org.opencms.report.Messages.RPT_SUCCESSION_2,
649                        String.valueOf(i + 1),
650                        String.valueOf(parseables.size())),
651                    I_CmsReport.FORMAT_NOTE);
652
653                LOG.info("Rewriting parsable resource: " + resName);
654                report.print(
655                    Messages.get().container(Messages.RPT_PARSE_LINKS_FOR_1, resName),
656                    I_CmsReport.FORMAT_NOTE);
657                report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
658
659                try {
660                    CmsFile file = cms.readFile(resName);
661                    // make sure the date last modified is kept...
662                    file.setDateLastModified(file.getDateLastModified());
663                    // make sure the file is locked
664                    CmsLock lock = cms.getLock(file);
665                    if (lock.isUnlocked()) {
666                        cms.lockResource(resName);
667                    } else if (!lock.isDirectlyOwnedInProjectBy(cms)) {
668                        cms.changeLock(resName);
669                    }
670                    // rewrite the file
671                    cms.getRequestContext().setAttribute(CmsXmlContent.AUTO_CORRECTION_ATTRIBUTE, Boolean.TRUE);
672                    try {
673                        cms.writeFile(file);
674                    } finally {
675                        cms.getRequestContext().removeAttribute(CmsXmlContent.AUTO_CORRECTION_ATTRIBUTE);
676                    }
677
678                    report.println(
679                        org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
680                        I_CmsReport.FORMAT_OK);
681                } catch (Throwable e) {
682                    report.addWarning(e);
683                    report.println(
684                        org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_FAILED_0),
685                        I_CmsReport.FORMAT_ERROR);
686                    if (LOG.isWarnEnabled()) {
687                        LOG.warn(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_REWRITING_1, resName));
688                        LOG.warn(e.getMessage(), e);
689                    }
690                    if (LOG.isDebugEnabled()) {
691                        LOG.debug(e.getLocalizedMessage(), e);
692                    }
693                }
694                i++;
695            }
696            if ((category == LinkParsableCategory.config) && (resourcesInCurrentCategory.size() > 0)) {
697                long start = System.currentTimeMillis();
698                OpenCms.getADEManager().waitForFormatterCache(false);
699                OpenCms.getADEManager().waitForCacheUpdate(false);
700                long end = System.currentTimeMillis();
701                long waitTime = end - start;
702                long cumulative = cumulativeConfigWaitTime.addAndGet(waitTime);
703                LOG.debug("Waited " + (waitTime / 1000.0) + "s for configuration in parseLinks, total = " + cumulative);
704
705            }
706        }
707        cms.getRequestContext().removeAttribute(CmsLogEntry.ATTR_LOG_ENTRY);
708    }
709
710    /**
711     * Adds an ACE from the current xml data.<p>
712     *
713     * @see #addResourceAceRules(Digester, String)
714     */
715    public void addAccessControlEntry() {
716
717        try {
718            if (m_throwable != null) {
719                // user or group of ACE might not exist in target system, ignore ACE
720                if (LOG.isWarnEnabled()) {
721                    LOG.warn(
722                        Messages.get().getBundle().key(
723                            Messages.LOG_IMPORTEXPORT_ERROR_IMPORTING_ACE_1,
724                            getRequestContext().removeSiteRoot(m_resource.getRootPath())),
725                        m_throwable);
726                }
727                getReport().println(m_throwable);
728                getReport().addError(m_throwable);
729                m_throwable = null;
730                return;
731            }
732            if (m_aces == null) {
733                // this list will be used and clean up in the importResource and importAccessControlEntries methods
734                m_aces = new ArrayList<CmsAccessControlEntry>();
735            }
736            m_aces.add(
737                new CmsAccessControlEntry(
738                    null,
739                    m_acePrincipalId,
740                    m_acePermissionsAllowed,
741                    m_acePermissionsDenied,
742                    m_aceFlags));
743        } finally {
744            m_acePrincipalId = null;
745            m_acePermissionsAllowed = 0;
746            m_acePermissionsDenied = 0;
747            m_aceFlags = 0;
748        }
749    }
750
751    /**
752     * Registers a file whose contents are contained in the zip file.<p>
753     *
754     * @param source the path in the zip file
755     *
756     * @param resourceId the resource id
757     */
758    public void addContentFile(String source, String resourceId) {
759
760        if ((source != null) && (resourceId != null)) {
761            try {
762                m_helper.getFileBytes(source);
763                m_contentFiles.add(new CmsUUID(resourceId));
764            } catch (@SuppressWarnings("unused") CmsImportExportException e) {
765                LOG.info("File not found in import: " + source);
766            }
767        }
768    }
769
770    /**
771     * Adds a new resource to be associated to the current organizational unit.<p>
772     *
773     * @param resourceName the resource name to add
774     */
775    public void addOrgUnitResource(String resourceName) {
776
777        if ((m_throwable != null) || (m_orgUnitName == null)) {
778            return;
779        }
780        if (m_orgUnitResources == null) {
781            m_orgUnitResources = new HashMap<String, List<String>>();
782        }
783        List<String> resources = m_orgUnitResources.get(m_orgUnitName);
784        if (resources == null) {
785            resources = new ArrayList<String>();
786            m_orgUnitResources.put(m_orgUnitName, resources);
787        }
788        resources.add(resourceName);
789    }
790
791    /**
792     * Adds a new resource to be associated to the current project.<p>
793     *
794     * @param resourceName the resource name to add
795     */
796    public void addProjectResource(String resourceName) {
797
798        if ((m_throwable != null) || (m_projectName == null)) {
799            return;
800        }
801        if (m_projectResources == null) {
802            m_projectResources = new ArrayList<String>();
803        }
804        m_projectResources.add(resourceName);
805    }
806
807    /**
808     * Adds a property from the current xml data, in case the type is implicit given.<p>
809     *
810     * @see #addResourcePropertyRules(Digester, String)
811     */
812    public void addProperty() {
813
814        addProperty("individual");
815    }
816
817    /**
818     * Adds a property from the current xml data, in case the type is explicit given.<p>
819     *
820     * @param propertyType the type of the property to be added
821     *
822     * @see #addResourcePropertyRules(Digester, String)
823     */
824    public void addProperty(String propertyType) {
825
826        if (m_properties == null) {
827            // this list will be used and clean up in the importResource method
828            m_properties = new HashMap<String, CmsProperty>();
829        }
830        try {
831            if ((m_propertyName == null) || getIgnoredProperties().contains(m_propertyName)) {
832                // continue if the current property (name) should be ignored or is null
833                return;
834            }
835            CmsProperty property = m_properties.get(m_propertyName);
836            if (property == null) {
837                property = new CmsProperty();
838                property.setName(m_propertyName);
839                property.setAutoCreatePropertyDefinition(true);
840                m_properties.put(m_propertyName, property);
841            }
842
843            if (m_propertyValue == null) {
844                m_propertyValue = "";
845            }
846
847            if ((propertyType != null) && propertyType.equals(PROPERTY_ATTRIB_TYPE_SHARED)) {
848                // it is a shared/resource property value
849                property.setResourceValue(m_propertyValue);
850            } else {
851                // it is an individual/structure value
852                property.setStructureValue(m_propertyValue);
853            }
854        } finally {
855            m_propertyName = null;
856            m_propertyValue = null;
857        }
858    }
859
860    /**
861     * Adds a relation to be imported from the current xml data.<p>
862     *
863     * @see #addResourceRelationRules(Digester, String)
864     */
865    public void addRelation() {
866
867        try {
868            if (m_throwable != null) {
869                // relation data is corrupt, ignore relation
870                if (LOG.isWarnEnabled()) {
871                    LOG.warn(
872                        Messages.get().getBundle().key(
873                            Messages.LOG_IMPORTEXPORT_ERROR_IMPORTING_RELATION_1,
874                            m_destination),
875                        m_throwable);
876                }
877                getReport().println(m_throwable);
878                getReport().addError(m_throwable);
879                m_throwable = null;
880                return;
881            }
882            RelationData relData = new RelationData(m_relationPath, m_relationId, m_relationType);
883            m_relationsForResource.add(relData);
884            m_relationData.put(Integer.valueOf(m_fileCounter), relData);
885        } finally {
886            m_relationId = null;
887            m_relationPath = null;
888            m_relationType = null;
889        }
890    }
891
892    /**
893     * Adds the XML digester rules for a single import file.<p>
894     *
895     * @param digester the digester to add the rules to
896     */
897    public void addXmlDigesterRules(Digester digester) {
898
899        // first accounts
900        String xpath = CmsImportExportManager.N_EXPORT + "/" + N_ACCOUNTS + "/" + N_ORGUNITS + "/" + N_ORGUNIT + "/";
901        addAccountsOrgunitRules(digester, xpath);
902        addAccountsGroupRules(digester, xpath);
903        addAccountsUserRules(digester, xpath);
904        digester.addCallMethod(
905            CmsImportExportManager.N_EXPORT + "/" + N_ACCOUNTS + "/" + N_ORGUNITS + "/" + N_ORGUNIT,
906            "setMembership");
907
908        // then resources
909
910        // When encountering opening files tag, initialize some fields which keep track of multiple resources'  data
911        digester.addRule(CmsImportExportManager.N_EXPORT + "/" + N_FILES, new Rule() {
912
913            @SuppressWarnings("synthetic-access")
914            @Override
915            public void begin(String namespace, String name, Attributes attributes) throws Exception {
916
917                m_indexToStructureId = new HashMap<>();
918                m_relationData = ArrayListMultimap.create();
919
920            }
921        });
922
923        digester.addRule(CmsImportExportManager.N_EXPORT + "/" + N_FILES + "/" + N_FILE, new Rule() {
924
925            @Override
926            public void begin(String namespace, String name, Attributes attributes) throws Exception {
927
928                m_importACEs = true;
929                m_resourceBuilder = new CmsResourceBuilder();
930                m_resourceBuilder.setDateLastModified(DATE_LAST_MODIFICATION_UNSPECIFIED);
931                m_resourceBuilder.setDateReleased(CmsResource.DATE_RELEASED_DEFAULT);
932                m_resourceBuilder.setDateExpired(CmsResource.DATE_EXPIRED_DEFAULT);
933                m_resourceBuilder.setDateCreated(DATE_CREATED_UNSPECIFIED);
934                m_resourceBuilder.setUserCreated(CmsUUID.getNullUUID());
935                m_relationsForResource = new ArrayList<>();
936                m_hasStructureId = false;
937                m_hasDateLastModified = false;
938            }
939        });
940
941        xpath = CmsImportExportManager.N_EXPORT + "/" + N_FILES + "/" + N_FILE + "/";
942        addResourceAttributesRules(digester, xpath);
943        digester.addCallMethod(xpath, "importResourceAll");
944        addResourcePropertyRules(digester, xpath);
945        addResourceRelationRules(digester, xpath);
946        addResourceAceRules(digester, xpath);
947
948        digester.addCallMethod(CmsImportExportManager.N_EXPORT + "/" + N_FILES, "importRelations");
949        digester.addCallMethod(CmsImportExportManager.N_EXPORT + "/" + N_FILES, "rewriteParseables");
950
951        // and now the organizational unit resources
952        digester.addCallMethod(CmsImportExportManager.N_EXPORT + "/" + N_FILES, "associateOrgUnitResources");
953
954        // then projects
955        xpath = CmsImportExportManager.N_EXPORT + "/" + N_PROJECTS + "/" + N_PROJECT + "/";
956        addProjectRules(digester, xpath);
957    }
958
959    /**
960     * Adds the XML digester rules for pre-processing a single import file.<p>
961     *
962     * @param digester the digester to add the rules to
963     */
964    public void addXmlPreprocessingDigesterRules(Digester digester) {
965
966        digester.addCallMethod(CmsImportExportManager.N_EXPORT + "/" + N_FILES + "/" + N_FILE, "increaseTotalFiles");
967        digester.addCallMethod(
968            CmsImportExportManager.N_EXPORT
969                + "/"
970                + CmsImportExportManager.N_INFO
971                + "/"
972                + CmsImportExportManager.N_VERSION,
973            "setVersion",
974            0);
975    }
976
977    /**
978     * Associates the stored resources to the created organizational units.<p>
979     *
980     * This is a global process that occurs only once at the end of the import,
981     * after all resources have been imported, to make sure that the resources
982     * of the organizational units are available.<p>
983     *
984     * @see #addAccountsOrgunitRules(Digester, String)
985     * @see #addXmlDigesterRules(Digester)
986     */
987    public void associateOrgUnitResources() {
988
989        if ((m_orgUnitResources == null) || m_orgUnitResources.isEmpty()) {
990            // no organizational resources to associate
991            return;
992        }
993
994        String site = getRequestContext().getSiteRoot();
995        try {
996            getRequestContext().setSiteRoot("");
997            List<String> orgUnits = new ArrayList<String>(m_orgUnitResources.keySet());
998            Collections.sort(orgUnits);
999            Iterator<String> it = orgUnits.iterator();
1000            while (it.hasNext()) {
1001                String orgUnitName = it.next();
1002                List<String> resources = m_orgUnitResources.get(orgUnitName);
1003
1004                if (orgUnitName.equals("")) {
1005                    continue;
1006                }
1007
1008                Iterator<String> itResources = resources.iterator();
1009                while (itResources.hasNext()) {
1010                    String resourceName = itResources.next();
1011                    try {
1012                        // Add the resource to the organizational unit
1013                        OpenCms.getOrgUnitManager().addResourceToOrgUnit(getCms(), orgUnitName, resourceName);
1014                    } catch (CmsException e) {
1015                        getReport().addWarning(e);
1016                        if (LOG.isWarnEnabled()) {
1017                            LOG.warn(e.getLocalizedMessage());
1018                        }
1019                        if (LOG.isDebugEnabled()) {
1020                            LOG.debug(e.getLocalizedMessage(), e);
1021                        }
1022                    }
1023                }
1024
1025                // remove the meanwhile used first resource of the parent organizational unit
1026                try {
1027                    String resName = (OpenCms.getOrgUnitManager().getResourcesForOrganizationalUnit(
1028                        getCms(),
1029                        CmsOrganizationalUnit.getParentFqn(orgUnitName)).get(0)).getRootPath();
1030                    if (!resources.contains(resName)) {
1031                        OpenCms.getOrgUnitManager().removeResourceFromOrgUnit(getCms(), orgUnitName, resName);
1032                    }
1033                } catch (CmsException e) {
1034                    getReport().addWarning(e);
1035                    if (LOG.isWarnEnabled()) {
1036                        LOG.warn(e.getLocalizedMessage());
1037                    }
1038                    if (LOG.isDebugEnabled()) {
1039                        LOG.debug(e.getLocalizedMessage(), e);
1040                    }
1041                }
1042
1043            }
1044        } finally {
1045            getRequestContext().setSiteRoot(site);
1046        }
1047
1048        m_orgUnitResources = null;
1049    }
1050
1051    /**
1052     * Returns the ace Flags.<p>
1053     *
1054     * @return the ace Flags
1055     *
1056     * @see #N_FLAGS
1057     * @see #addResourceAceRules(Digester, String)
1058     */
1059    public int getAceFlags() {
1060
1061        return m_aceFlags;
1062    }
1063
1064    /**
1065     * Returns the ace Permissions Allowed.<p>
1066     *
1067     * @return the ace Permissions Allowed
1068     *
1069     * @see #N_ACCESSCONTROL_ALLOWEDPERMISSIONS
1070     * @see #addResourceAceRules(Digester, String)
1071     */
1072    public int getAcePermissionsAllowed() {
1073
1074        return m_acePermissionsAllowed;
1075    }
1076
1077    /**
1078     * Returns the acePermissionsDenied.<p>
1079     *
1080     * @return the acePermissionsDenied
1081     *
1082     * @see #N_ACCESSCONTROL_DENIEDPERMISSIONS
1083     * @see #addResourceAceRules(Digester, String)
1084     */
1085    public int getAcePermissionsDenied() {
1086
1087        return m_acePermissionsDenied;
1088    }
1089
1090    /**
1091     * Returns the acePrincipalId.<p>
1092     *
1093     * @return the acePrincipalId
1094     *
1095     * @see #N_ACCESSCONTROL_PRINCIPAL
1096     * @see #addResourceAceRules(Digester, String)
1097     */
1098    public CmsUUID getAcePrincipalId() {
1099
1100        return m_acePrincipalId;
1101    }
1102
1103    /**
1104     * Returns the cms object.<p>
1105     *
1106     * @return the cms object
1107     */
1108    public CmsObject getCms() {
1109
1110        return m_cms;
1111    }
1112
1113    /**
1114     * Returns the dateCreated.<p>
1115     *
1116     * @return the dateCreated
1117     *
1118     * @see #N_DATECREATED
1119     * @see #addResourceAttributesRules(Digester, String)
1120     */
1121    public long getDateCreated() {
1122
1123        return m_resourceBuilder.getDateCreated();
1124    }
1125
1126    /**
1127     * Returns the dateExpired.<p>
1128     *
1129     * @return the dateExpired
1130     *
1131     * @see #N_DATEEXPIRED
1132     * @see #addResourceAttributesRules(Digester, String)
1133     */
1134    public long getDateExpired() {
1135
1136        return m_resourceBuilder.getDateExpired();
1137    }
1138
1139    /**
1140     * Returns the dateLastModified.<p>
1141     *
1142     * @return the dateLastModified
1143     *
1144     * @see #N_DATELASTMODIFIED
1145     * @see #addResourceAttributesRules(Digester, String)
1146     */
1147    public long getDateLastModified() {
1148
1149        return m_resourceBuilder.getDateLastModified();
1150    }
1151
1152    /**
1153     * Returns the dateReleased.<p>
1154     *
1155     * @return the dateReleased
1156     *
1157     * @see #N_DATERELEASED
1158     * @see #addResourceAttributesRules(Digester, String)
1159     */
1160    public long getDateReleased() {
1161
1162        return m_resourceBuilder.getDateReleased();
1163    }
1164
1165    /**
1166     * Returns the destination.<p>
1167     *
1168     * @return the destination
1169     *
1170     * @see #N_DESTINATION
1171     * @see #addResourceAttributesRules(Digester, String)
1172     */
1173    public String getDestination() {
1174
1175        return m_destination;
1176    }
1177
1178    /**
1179     * Returns the flags.<p>
1180     *
1181     * @return the flags
1182     *
1183     * @see #N_FLAGS
1184     * @see #addResourceAttributesRules(Digester, String)
1185     */
1186    public int getFlags() {
1187
1188        return m_resourceBuilder.getFlags();
1189    }
1190
1191    /**
1192     * Returns the group Description.<p>
1193     *
1194     * @return the group Description
1195     */
1196    public String getGroupDescription() {
1197
1198        return m_groupDescription;
1199    }
1200
1201    /**
1202     * Returns the group Flags.<p>
1203     *
1204     * @return the group Flags
1205     */
1206    public int getGroupFlags() {
1207
1208        return m_groupFlags;
1209    }
1210
1211    /**
1212     * Returns the group Name.<p>
1213     *
1214     * @return the group Name
1215     */
1216    public String getGroupName() {
1217
1218        return m_groupName;
1219    }
1220
1221    /**
1222     * Returns the group Parent.<p>
1223     *
1224     * @return the group Parent
1225     */
1226    public String getGroupParent() {
1227
1228        return m_groupParent;
1229    }
1230
1231    /**
1232     * Returns the organizational unit description.<p>
1233     *
1234     * @return the organizational unit description
1235     */
1236    public String getOrgUnitDescription() {
1237
1238        return m_orgUnitDescription;
1239    }
1240
1241    /**
1242     * Returns the organizational unit flags.<p>
1243     *
1244     * @return the organizational unit flags
1245     */
1246    public int getOrgUnitFlags() {
1247
1248        return m_orgUnitFlags;
1249    }
1250
1251    /**
1252     * Returns the organizational unit name.<p>
1253     *
1254     * @return the organizational unit name
1255     */
1256    public String getOrgUnitName() {
1257
1258        return m_orgUnitName;
1259    }
1260
1261    /**
1262     * Returns the project Description.<p>
1263     *
1264     * @return the project Description
1265     */
1266    public String getProjectDescription() {
1267
1268        return m_projectDescription;
1269    }
1270
1271    /**
1272     * Returns the project Managers group name.<p>
1273     *
1274     * @return the project Managers group name
1275     */
1276    public String getProjectManagers() {
1277
1278        return m_projectManagers;
1279    }
1280
1281    /**
1282     * Returns the project Name.<p>
1283     *
1284     * @return the project Name
1285     */
1286    public String getProjectName() {
1287
1288        return m_projectName;
1289    }
1290
1291    /**
1292     * Returns the project Users group name.<p>
1293     *
1294     * @return the project Users group name
1295     */
1296    public String getProjectUsers() {
1297
1298        return m_projectUsers;
1299    }
1300
1301    /**
1302     * Returns the propertyName.<p>
1303     *
1304     * @return the propertyName
1305     *
1306     * @see #N_NAME
1307     * @see #addResourcePropertyRules(Digester, String)
1308     */
1309    public String getPropertyName() {
1310
1311        return m_propertyName;
1312    }
1313
1314    /**
1315     * Returns the propertyValue.<p>
1316     *
1317     * @return the propertyValue
1318     *
1319     * @see #N_VALUE
1320     * @see #addResourcePropertyRules(Digester, String)
1321     */
1322    public String getPropertyValue() {
1323
1324        return m_propertyValue;
1325    }
1326
1327    /**
1328     * Returns the relationId.<p>
1329     *
1330     * @return the relationId
1331     *
1332     * @see #N_ID
1333     * @see #addResourceRelationRules(Digester, String)
1334     */
1335    public CmsUUID getRelationId() {
1336
1337        return m_relationId;
1338    }
1339
1340    /**
1341     * Returns the relationPath.<p>
1342     *
1343     * @return the relationPath
1344     *
1345     * @see #N_PATH
1346     * @see #addResourceRelationRules(Digester, String)
1347     */
1348    public String getRelationPath() {
1349
1350        return m_relationPath;
1351    }
1352
1353    /**
1354     * Returns the relationType.<p>
1355     *
1356     * @return the relationType
1357     *
1358     * @see #N_TYPE
1359     * @see #addResourceRelationRules(Digester, String)
1360     */
1361    public CmsRelationType getRelationType() {
1362
1363        return m_relationType;
1364    }
1365
1366    /**
1367     * Returns the report.<p>
1368     *
1369     * @return the report
1370     */
1371    public I_CmsReport getReport() {
1372
1373        return m_report;
1374    }
1375
1376    /**
1377     * Gets the request context of the currently used CmsObject.<p>
1378     *
1379     * @return the current request context
1380     */
1381    public CmsRequestContext getRequestContext() {
1382
1383        return getCms().getRequestContext();
1384    }
1385
1386    /**
1387     * Returns the resourceId.<p>
1388     *
1389     * @return the resourceId
1390     *
1391     * @see #N_UUIDRESOURCE
1392     * @see #addResourceAttributesRules(Digester, String)
1393     */
1394    public CmsUUID getResourceId() {
1395
1396        return m_resourceBuilder.getResourceId();
1397    }
1398
1399    /**
1400     * Returns the source.<p>
1401     *
1402     * @return the source
1403     *
1404     * @see #N_SOURCE
1405     * @see #addResourceAttributesRules(Digester, String)
1406     */
1407    public String getSource() {
1408
1409        return m_source;
1410    }
1411
1412    /**
1413     * Returns the structureId.<p>
1414     *
1415     * @return the structureId
1416     *
1417     * @see #N_UUIDSTRUCTURE
1418     * @see #addResourceAttributesRules(Digester, String)
1419     */
1420    public CmsUUID getStructureId() {
1421
1422        return m_resourceBuilder.getStructureId();
1423    }
1424
1425    /**
1426     * Returns the throwable.<p>
1427     *
1428     * @return the throwable
1429     */
1430    public Throwable getThrowable() {
1431
1432        return m_throwable;
1433    }
1434
1435    /**
1436     * Returns the type.<p>
1437     *
1438     * @return the type
1439     *
1440     * @see #N_TYPE
1441     * @see #addResourceAttributesRules(Digester, String)
1442     */
1443    public I_CmsResourceType getType() {
1444
1445        return null;
1446    }
1447
1448    /**
1449     * Returns the userCreated.<p>
1450     *
1451     * @return the userCreated
1452     *
1453     * @see #N_USERCREATED
1454     * @see #addResourceAttributesRules(Digester, String)
1455     */
1456    public CmsUUID getUserCreated() {
1457
1458        return m_resourceBuilder.getUserCreated();
1459    }
1460
1461    /**
1462     * Returns the user Date Created.<p>
1463     *
1464     * @return the user Date Created
1465     */
1466    public long getUserDateCreated() {
1467
1468        return m_userDateCreated;
1469    }
1470
1471    /**
1472     * Returns the user Email address.<p>
1473     *
1474     * @return the user Email address
1475     */
1476    public String getUserEmail() {
1477
1478        return m_userEmail;
1479    }
1480
1481    /**
1482     * Returns the user First name.<p>
1483     *
1484     * @return the user First name
1485     */
1486    public String getUserFirstname() {
1487
1488        return m_userFirstname;
1489    }
1490
1491    /**
1492     * Returns the user Flags.<p>
1493     *
1494     * @return the user Flags
1495     */
1496    public int getUserFlags() {
1497
1498        return m_userFlags;
1499    }
1500
1501    /**
1502     * Returns the userLastModified.<p>
1503     *
1504     * @return the userLastModified
1505     *
1506     * @see #N_USERLASTMODIFIED
1507     * @see #addResourceAttributesRules(Digester, String)
1508     */
1509    public CmsUUID getUserLastModified() {
1510
1511        return m_resourceBuilder.getUserLastModified();
1512    }
1513
1514    /**
1515     * Returns the user Last name.<p>
1516     *
1517     * @return the user Last name
1518     */
1519    public String getUserLastname() {
1520
1521        return m_userLastname;
1522    }
1523
1524    /**
1525     * Returns the user Name.<p>
1526     *
1527     * @return the user Name
1528     */
1529    public String getUserName() {
1530
1531        return m_userName;
1532    }
1533
1534    /**
1535     * Returns the user Password.<p>
1536     *
1537     * @return the user Password
1538     */
1539    public String getUserPassword() {
1540
1541        return m_userPassword;
1542    }
1543
1544    /**
1545     * @see org.opencms.importexport.I_CmsImport#getVersion()
1546     */
1547    public int getVersion() {
1548
1549        return IMPORT_VERSION10;
1550    }
1551
1552    /**
1553     * Imports an ACE from the current xml data.<p>
1554     *
1555     * @see #addResourceAceRules(Digester, String)
1556     */
1557    public void importAccessControlEntries() {
1558
1559        // only set permissions if the resource did not exists or if the keep permissions flag is not set
1560        if ((m_resource == null) || !m_importACEs) {
1561            return;
1562        }
1563        if ((m_aces == null) || (m_aces.size() == 0)) {
1564            // no ACE in the list
1565            return;
1566        }
1567        // if the resource was imported add the access control entries if available
1568        try {
1569            getCms().importAccessControlEntries(m_resource, m_aces);
1570        } catch (@SuppressWarnings("unused") CmsException exc) {
1571            getReport().println(
1572                Messages.get().container(Messages.RPT_IMPORT_ACL_DATA_FAILED_0),
1573                I_CmsReport.FORMAT_WARNING);
1574        } finally {
1575            m_aces = null;
1576        }
1577    }
1578
1579    /**
1580     * @see org.opencms.importexport.I_CmsImport#importData(CmsObject, I_CmsReport, CmsImportParameters)
1581     */
1582    public void importData(CmsObject cms, I_CmsReport report, CmsImportParameters parameters) {
1583
1584        m_cms = cms;
1585        m_report = report;
1586        m_parameters = parameters;
1587
1588        // instantiate Digester and enable XML validation
1589        Digester digester = new Digester();
1590        digester.setUseContextClassLoader(true);
1591        digester.setValidating(m_parameters.isXmlValidation());
1592        digester.setEntityResolver(new CmsXmlEntityResolver(null));
1593        digester.setRuleNamespaceURI(null);
1594        digester.setErrorHandler(new CmsXmlErrorHandler(CmsImportExportManager.EXPORT_MANIFEST));
1595
1596        // add this object to the Digester
1597        digester.push(this);
1598
1599        addXmlDigesterRules(digester);
1600
1601        InputStream stream = null;
1602        m_helper = new CmsImportHelper(m_parameters);
1603        try {
1604            m_helper.openFile();
1605            m_helper.cacheDtdSystemId(DTD_LOCATION, DTD_FILENAME, CmsConfigurationManager.DEFAULT_DTD_PREFIX);
1606            findContentFiles();
1607            // start the parsing process
1608            stream = m_helper.getFileStream(CmsImportExportManager.EXPORT_MANIFEST);
1609            digester.parse(stream);
1610        } catch (Exception ioe) {
1611            if (LOG.isErrorEnabled()) {
1612                LOG.error(
1613                    Messages.get().getBundle().key(
1614                        Messages.ERR_IMPORTEXPORT_ERROR_READING_FILE_1,
1615                        CmsImportExportManager.EXPORT_MANIFEST),
1616                    ioe);
1617            }
1618            getReport().println(ioe);
1619        } finally {
1620            try {
1621                if (stream != null) {
1622                    stream.close();
1623                }
1624            } catch (@SuppressWarnings("unused") Exception e) {
1625                // noop
1626            }
1627            m_helper.closeFile();
1628        }
1629    }
1630
1631    /**
1632     * Import the current group from xml data.<p>
1633     */
1634    public void importGroup() {
1635
1636        if (m_orgUnit == null) {
1637            return;
1638        }
1639        if (m_groupDescription == null) {
1640            m_groupDescription = "";
1641        }
1642        if (m_groupParents == null) {
1643            m_groupParents = new HashMap<String, List<String>>();
1644        }
1645
1646        String groupName = m_orgUnit.getName() + m_groupName;
1647        try {
1648            if (m_throwable != null) {
1649                getReport().println(m_throwable);
1650
1651                CmsMessageContainer message = Messages.get().container(
1652                    Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_GROUP_1,
1653                    groupName);
1654                if (LOG.isDebugEnabled()) {
1655                    LOG.debug(message.key(), m_throwable);
1656                }
1657                m_throwable = null;
1658                return;
1659            }
1660
1661            getReport().print(Messages.get().container(Messages.RPT_IMPORT_GROUP_0), I_CmsReport.FORMAT_NOTE);
1662            getReport().print(
1663                org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_ARGUMENT_1, groupName));
1664            getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
1665
1666            try {
1667                getCms().readGroup(groupName);
1668                // the group already exists and will not be created
1669                getReport().println(Messages.get().container(Messages.RPT_NOT_CREATED_0), I_CmsReport.FORMAT_OK);
1670            } catch (@SuppressWarnings("unused") CmsDbEntryNotFoundException e) {
1671                // ok, let's create it
1672                // first check the parent group
1673                CmsUUID parentGroupId = null;
1674                if (CmsStringUtil.isNotEmpty(m_groupParent)) {
1675                    try {
1676                        // parent group exists
1677                        parentGroupId = getCms().readGroup(m_groupParent).getId();
1678                    } catch (@SuppressWarnings("unused") CmsDbEntryNotFoundException exc) {
1679                        // parent group does not exist, remember to set the parent group later
1680                        List<String> childs = m_groupParents.get(m_groupParent);
1681                        if (childs == null) {
1682                            childs = new ArrayList<String>();
1683                            m_groupParents.put(m_groupParent, childs);
1684                        }
1685                        childs.add(groupName);
1686                    }
1687                }
1688
1689                getCms().createGroup(
1690                    groupName,
1691                    m_groupDescription,
1692                    m_groupFlags,
1693                    parentGroupId == null ? null : m_groupParent);
1694                getReport().println(
1695                    org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
1696                    I_CmsReport.FORMAT_OK);
1697
1698                // set parents that could not be set before
1699                List<String> childs = m_groupParents.remove(groupName);
1700                if (childs != null) {
1701                    Iterator<String> it = childs.iterator();
1702                    while (it.hasNext()) {
1703                        String childGroup = it.next();
1704                        getCms().setParentGroup(childGroup, groupName);
1705                    }
1706                }
1707            }
1708        } catch (Exception e) {
1709            getReport().println(e);
1710
1711            CmsMessageContainer message = Messages.get().container(
1712                Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_GROUP_1,
1713                groupName);
1714            if (LOG.isDebugEnabled()) {
1715                LOG.debug(message.key(), e);
1716            }
1717        } finally {
1718            m_groupDescription = null;
1719            m_groupFlags = 0;
1720            m_groupName = null;
1721            m_groupParent = null;
1722            m_throwable = null;
1723        }
1724    }
1725
1726    /**
1727     * Imports the current organizational unit.<p>
1728     */
1729    public void importOrgUnit() {
1730
1731        try {
1732            if (m_throwable != null) {
1733                getReport().println(m_throwable);
1734                getReport().addError(m_throwable);
1735
1736                CmsMessageContainer message = Messages.get().container(
1737                    Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_ORGUNITS_0);
1738                if (LOG.isDebugEnabled()) {
1739                    LOG.debug(message.key(), m_throwable);
1740                }
1741                m_throwable = null;
1742                m_orgUnit = null;
1743
1744                return;
1745            }
1746
1747            getReport().print(Messages.get().container(Messages.RPT_IMPORT_ORGUNIT_0), I_CmsReport.FORMAT_NOTE);
1748            getReport().print(
1749                org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_ARGUMENT_1, m_orgUnitName));
1750            getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
1751
1752            try {
1753                m_orgUnit = OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(), m_orgUnitName);
1754                // the organizational unit already exists and will not be created
1755                getReport().println(Messages.get().container(Messages.RPT_NOT_CREATED_0), I_CmsReport.FORMAT_OK);
1756                m_orgUnitResources.remove(m_orgUnitName);
1757                return;
1758            } catch (@SuppressWarnings("unused") CmsDataAccessException e) {
1759                // ok, continue creating the ou
1760            }
1761
1762            // get the resources that already exist for the organizational unit
1763            // if there are resources that does not exist jet, there will be a second try after importing resources
1764            List<CmsResource> resources = new ArrayList<CmsResource>();
1765            String site = getRequestContext().getSiteRoot();
1766            try {
1767                getRequestContext().setSiteRoot("");
1768
1769                boolean remove = true;
1770                List<String> ouResources = CmsCollectionsGenericWrapper.list(m_orgUnitResources.get(m_orgUnitName));
1771                if (ouResources != null) {
1772                    Iterator<String> itResNames = ouResources.iterator();
1773                    while (itResNames.hasNext()) {
1774                        String resName = itResNames.next();
1775                        try {
1776                            resources.add(getCms().readResource(resName, CmsResourceFilter.ALL));
1777                            itResNames.remove();
1778                        } catch (@SuppressWarnings("unused") CmsVfsResourceNotFoundException e) {
1779                            // resource does not exist yet, skip it for now
1780                            remove = false;
1781                        }
1782                    }
1783                }
1784
1785                if (remove) {
1786                    m_orgUnitResources.remove(m_orgUnitName);
1787                }
1788            } finally {
1789                getRequestContext().setSiteRoot(site);
1790            }
1791
1792            // if no resource available
1793            if (resources.isEmpty()) {
1794                // meanwhile use the first one of the parent organizational unit
1795                resources.add(
1796                    OpenCms.getOrgUnitManager().getResourcesForOrganizationalUnit(
1797                        getCms(),
1798                        CmsOrganizationalUnit.getParentFqn(m_orgUnitName)).get(0));
1799            }
1800
1801            // create the organizational unit with a dummy resource, which will be corrected later
1802            m_orgUnit = OpenCms.getOrgUnitManager().createOrganizationalUnit(
1803                getCms(),
1804                m_orgUnitName,
1805                m_orgUnitDescription,
1806                m_orgUnitFlags,
1807                resources.get(0).getRootPath());
1808            for (int i = 1; i < resources.size(); i++) {
1809                OpenCms.getOrgUnitManager().addResourceToOrgUnit(
1810                    getCms(),
1811                    m_orgUnitName,
1812                    resources.get(i).getRootPath());
1813            }
1814
1815            getReport().println(
1816                org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
1817                I_CmsReport.FORMAT_OK);
1818        } catch (CmsException e) {
1819            getReport().println(e);
1820            getReport().addError(e);
1821
1822            CmsMessageContainer message = Messages.get().container(
1823                Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_ORGUNITS_0);
1824            if (LOG.isDebugEnabled()) {
1825                LOG.debug(message.key(), e);
1826            }
1827            m_throwable = null;
1828            m_orgUnit = null;
1829        } finally {
1830            m_orgUnitName = null;
1831            m_orgUnitDescription = null;
1832            m_orgUnitFlags = 0;
1833        }
1834
1835    }
1836
1837    /**
1838     * Imports the current project.<p>
1839     */
1840    public void importProject() {
1841
1842        try {
1843            if (m_throwable != null) {
1844                getReport().println(m_throwable);
1845                getReport().addError(m_throwable);
1846
1847                CmsMessageContainer message = Messages.get().container(
1848                    Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_PROJECTS_0);
1849                if (LOG.isDebugEnabled()) {
1850                    LOG.debug(message.key(), m_throwable);
1851                }
1852                m_throwable = null;
1853
1854                return;
1855            }
1856
1857            getReport().print(Messages.get().container(Messages.RPT_IMPORT_PROJECT_0), I_CmsReport.FORMAT_NOTE);
1858            getReport().print(
1859                org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_ARGUMENT_1, m_projectName));
1860            getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
1861
1862            try {
1863                getCms().readProject(m_projectName);
1864                // the project already exists and will not be created
1865                getReport().println(Messages.get().container(Messages.RPT_NOT_CREATED_0), I_CmsReport.FORMAT_OK);
1866                return;
1867            } catch (@SuppressWarnings("unused") CmsDataAccessException e) {
1868                // ok, continue creating the project
1869            }
1870
1871            // create the project
1872            CmsProject project = getCms().createProject(
1873                m_projectName,
1874                m_projectDescription,
1875                m_projectUsers,
1876                m_projectManagers,
1877                CmsProject.PROJECT_TYPE_NORMAL);
1878            // set the resources
1879            if (m_projectResources != null) {
1880                String site = getRequestContext().getSiteRoot();
1881                CmsProject currentProject = getRequestContext().getCurrentProject();
1882                try {
1883                    getRequestContext().setSiteRoot("");
1884                    getRequestContext().setCurrentProject(project);
1885
1886                    Iterator<String> itResNames = m_projectResources.iterator();
1887                    while (itResNames.hasNext()) {
1888                        String resName = itResNames.next();
1889                        try {
1890                            getCms().copyResourceToProject(resName);
1891                        } catch (@SuppressWarnings("unused") CmsVfsResourceNotFoundException e) {
1892                            // resource does not exist, skip
1893                        }
1894                    }
1895                } finally {
1896                    getRequestContext().setSiteRoot(site);
1897                    getRequestContext().setCurrentProject(currentProject);
1898                }
1899            }
1900            getReport().println(
1901                org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
1902                I_CmsReport.FORMAT_OK);
1903        } catch (CmsException e) {
1904            getReport().println(e);
1905            getReport().addError(e);
1906
1907            CmsMessageContainer message = Messages.get().container(
1908                Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_PROJECTS_0);
1909            if (LOG.isDebugEnabled()) {
1910                LOG.debug(message.key(), e);
1911            }
1912            m_throwable = null;
1913        } finally {
1914            m_projectName = null;
1915            m_projectDescription = null;
1916            m_projectManagers = null;
1917            m_projectUsers = null;
1918            m_projectResources = null;
1919        }
1920
1921    }
1922
1923    /**
1924     * Imports all relations from the current xml data.<p>
1925     *
1926     * This is a global process that occurs only once at the end of the import,
1927     * after all resources have been imported, to make sure that both resources
1928     * of the relations are available.<p>
1929     *
1930     * @see #addResourceRelationRules(Digester, String)
1931     * @see #addXmlDigesterRules(Digester)
1932     */
1933    public void importRelations() {
1934
1935        if ((m_relationData == null) || m_relationData.isEmpty()) {
1936            // no relations to add
1937            return;
1938        }
1939
1940        getReport().println(
1941            Messages.get().container(Messages.RPT_START_IMPORT_RELATIONS_0),
1942            I_CmsReport.FORMAT_HEADLINE);
1943
1944        int i = 0;
1945        CmsResourceFilter filter = CmsResourceFilter.ALL;
1946        for (Integer importIndex : m_relationData.keySet()) {
1947            CmsUUID structureId = m_indexToStructureId.get(importIndex);
1948            if (structureId == null) {
1949                continue;
1950            }
1951            Collection<RelationData> relationDataList = m_relationData.get(importIndex);
1952            try {
1953                CmsResource src = m_cms.readResource(structureId, filter);
1954                if (checkImmutable(src.getRootPath())) {
1955                    continue;
1956                }
1957                getReport().print(
1958                    org.opencms.report.Messages.get().container(
1959                        org.opencms.report.Messages.RPT_SUCCESSION_2,
1960                        String.valueOf(i + 1),
1961                        String.valueOf(m_relationData.keySet().size())),
1962                    I_CmsReport.FORMAT_NOTE);
1963
1964                getReport().print(
1965                    Messages.get().container(
1966                        Messages.RPT_IMPORTING_RELATIONS_FOR_2,
1967                        src.getRootPath(),
1968                        new Integer(m_relationData.keySet().size())),
1969                    I_CmsReport.FORMAT_NOTE);
1970                getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
1971                boolean withErrors = false;
1972                for (RelationData relationData : relationDataList) {
1973                    CmsResource target = null;
1974                    if (relationData.getTargetId() != null) {
1975                        try {
1976                            target = m_cms.readResource(relationData.getTargetId(), filter);
1977                        } catch (CmsVfsResourceNotFoundException e) {
1978                            // ignore
1979                        }
1980                    }
1981                    if (target == null) {
1982                        try {
1983                            target = m_cms.readResource(relationData.getTarget(), filter);
1984                        } catch (CmsVfsResourceNotFoundException e) {
1985                            // ignore
1986                        }
1987                    }
1988
1989                    if (target != null) {
1990                        try {
1991                            getCms().importRelation(
1992                                m_cms.getSitePath(src),
1993                                m_cms.getSitePath(target),
1994                                relationData.getType().toString());
1995                        } catch (CmsException e) {
1996                            getReport().addWarning(e);
1997                            withErrors = true;
1998                            if (LOG.isWarnEnabled()) {
1999                                LOG.warn(e.getLocalizedMessage());
2000                            }
2001                            if (LOG.isDebugEnabled()) {
2002                                LOG.debug(e.getLocalizedMessage(), e);
2003                            }
2004                        }
2005                    }
2006                }
2007                if (!withErrors) {
2008                    getReport().println(
2009                        org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
2010                        I_CmsReport.FORMAT_OK);
2011                } else {
2012                    getReport().println(
2013                        org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_FAILED_0),
2014                        I_CmsReport.FORMAT_ERROR);
2015                }
2016                i += 1;
2017
2018            } catch (CmsException e) {
2019                getReport().addError(e);
2020                LOG.error(e.getLocalizedMessage(), e);
2021                continue;
2022            }
2023        }
2024    }
2025
2026    /**
2027     * Imports a resource from the current xml data.<p>
2028     *
2029     * @see #addResourceAttributesRules(Digester, String)
2030     * @see #addResourcePropertyRules(Digester, String)
2031     */
2032    public void importResource() {
2033
2034        m_resourceIdWasNull = false;
2035
2036        try {
2037            if (m_throwable != null) {
2038                getReport().println(m_throwable);
2039                getReport().addError(m_throwable);
2040
2041                CmsMessageContainer message = Messages.get().container(
2042                    Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0);
2043                if (LOG.isDebugEnabled()) {
2044                    LOG.debug(message.key(), m_throwable);
2045                }
2046                m_throwable = null;
2047                m_importACEs = false;
2048                m_resource = null;
2049
2050                return;
2051            }
2052
2053            // apply name translation and import path
2054            String translatedName = getRequestContext().addSiteRoot(
2055                CmsStringUtil.joinPaths(m_parameters.getDestinationPath(), m_destination));
2056
2057            boolean resourceImmutable = checkImmutable(translatedName);
2058            translatedName = getRequestContext().removeSiteRoot(translatedName);
2059            // if the resource is not immutable and not on the exclude list, import it
2060            if (!resourceImmutable) {
2061                // print out the information to the report
2062                getReport().print(Messages.get().container(Messages.RPT_IMPORTING_0), I_CmsReport.FORMAT_NOTE);
2063                getReport().print(
2064                    org.opencms.report.Messages.get().container(
2065                        org.opencms.report.Messages.RPT_ARGUMENT_1,
2066                        translatedName));
2067                getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
2068
2069                boolean exists = getCms().existsResource(translatedName, CmsResourceFilter.ALL);
2070
2071                byte[] content = null;
2072                // get the file content
2073
2074                if (m_source != null) {
2075                    content = m_helper.getFileBytes(m_source);
2076                }
2077                int size = 0;
2078                if (content != null) {
2079                    size = content.length;
2080                }
2081                setDefaultsForEmptyResourceFields();
2082                // create a new CmsResource
2083                CmsResource resource = createResourceObjectFromFields(translatedName, size);
2084                if (!OpenCms.getResourceManager().hasResourceType(m_typeName)) {
2085                    m_properties.put(
2086                        CmsPropertyDefinition.PROPERTY_EXPORT_TYPE,
2087                        new CmsProperty(CmsPropertyDefinition.PROPERTY_EXPORT_TYPE, null, m_typeName, true));
2088                }
2089                if (m_resourceBuilder.getType().isFolder()
2090                    || m_resourceIdWasNull
2091                    || hasContentInVfsOrImport(resource)) {
2092                    // import this resource in the VFS
2093                    m_resource = getCms().importResource(
2094                        translatedName,
2095                        resource,
2096                        content,
2097                        new ArrayList<CmsProperty>(m_properties.values()));
2098                }
2099
2100                if (m_resource != null) {
2101                    m_indexToStructureId.put(Integer.valueOf(m_fileCounter), m_resource.getStructureId());
2102                }
2103
2104                // only set permissions if the resource did not exists or if the keep permissions flag is not set
2105                m_importACEs = (m_resource != null) && (!exists || !m_parameters.isKeepPermissions());
2106
2107                if (m_resource != null) {
2108                    getReport().println(
2109                        org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
2110                        I_CmsReport.FORMAT_OK);
2111
2112                    if (OpenCms.getResourceManager().getResourceType(
2113                        m_resource.getTypeId()) instanceof I_CmsLinkParseable) {
2114                        // store for later use
2115                        m_parseables.add(m_resource);
2116                    }
2117                    if (LOG.isInfoEnabled()) {
2118                        LOG.info(
2119                            Messages.get().getBundle().key(
2120                                Messages.LOG_IMPORTING_4,
2121                                new Object[] {
2122                                    String.valueOf(m_fileCounter),
2123                                    String.valueOf(m_totalFiles),
2124                                    translatedName,
2125                                    m_destination}));
2126                    }
2127                } else {
2128                    // resource import failed, since no CmsResource was created
2129                    getReport().print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE);
2130                    getReport().println(
2131                        org.opencms.report.Messages.get().container(
2132                            org.opencms.report.Messages.RPT_ARGUMENT_1,
2133                            translatedName));
2134
2135                    if (LOG.isInfoEnabled()) {
2136                        LOG.info(
2137                            Messages.get().getBundle().key(
2138                                Messages.LOG_SKIPPING_3,
2139                                String.valueOf(m_fileCounter),
2140                                String.valueOf(m_totalFiles),
2141                                translatedName));
2142                    }
2143                }
2144            } else {
2145                m_resource = null;
2146                // skip the file import, just print out the information to the report
2147                getReport().print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE);
2148                getReport().println(
2149                    org.opencms.report.Messages.get().container(
2150                        org.opencms.report.Messages.RPT_ARGUMENT_1,
2151                        translatedName));
2152
2153                if (LOG.isInfoEnabled()) {
2154                    LOG.info(
2155                        Messages.get().getBundle().key(
2156                            Messages.LOG_SKIPPING_3,
2157                            String.valueOf(m_fileCounter),
2158                            String.valueOf(m_totalFiles),
2159                            translatedName));
2160                }
2161                // do not import ACEs
2162                m_importACEs = false;
2163            }
2164        } catch (Exception e) {
2165            m_resource = null;
2166            m_importACEs = false;
2167
2168            getReport().println(e);
2169            getReport().addError(e);
2170
2171            CmsMessageContainer message = Messages.get().container(
2172                Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0);
2173            if (LOG.isDebugEnabled()) {
2174                LOG.debug(message.key(), e);
2175            }
2176
2177            return;
2178        }
2179    }
2180
2181    /**
2182     * Imports the resource and access control entries.<p>
2183     */
2184    public void importResourceAll() {
2185
2186        try {
2187            importResource();
2188            importAccessControlEntries();
2189            increaseCounter();
2190        } finally {
2191            m_destination = null;
2192            m_source = null;
2193            m_throwable = null;
2194            m_properties = null;
2195            m_aces = null;
2196        }
2197    }
2198
2199    /**
2200     * @see org.opencms.importexport.I_CmsImport#importResources(org.opencms.file.CmsObject, java.lang.String, org.opencms.report.I_CmsReport, java.io.File, java.util.zip.ZipFile, org.dom4j.Document)
2201     *
2202     * @deprecated use {@link #importData(CmsObject, I_CmsReport, CmsImportParameters)} instead
2203     */
2204    @Deprecated
2205    public void importResources(
2206        CmsObject cms,
2207        String importPath,
2208        I_CmsReport report,
2209        File importResource,
2210        ZipFile importZip,
2211        Document docXml) {
2212
2213        CmsImportParameters params = new CmsImportParameters(importResource.getAbsolutePath(), importPath, true);
2214
2215        importData(cms, report, params);
2216    }
2217
2218    /**
2219     * Imports a new user from the current xml data.<p>
2220     */
2221    public void importUser() {
2222
2223        // create a new user id
2224        String userName = m_orgUnit.getName() + m_userName;
2225        try {
2226            if (m_throwable != null) {
2227                m_user = null;
2228                getReport().println(m_throwable);
2229
2230                CmsMessageContainer message = Messages.get().container(
2231                    Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_USER_1,
2232                    userName);
2233                if (LOG.isDebugEnabled()) {
2234                    LOG.debug(message.key(), m_throwable);
2235                }
2236                m_throwable = null;
2237                return;
2238            }
2239
2240            getReport().print(Messages.get().container(Messages.RPT_IMPORT_USER_0), I_CmsReport.FORMAT_NOTE);
2241            getReport().print(
2242                org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_ARGUMENT_1, userName));
2243            getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
2244
2245            try {
2246                getCms().readUser(userName);
2247                // user exists already
2248                getReport().println(Messages.get().container(Messages.RPT_NOT_CREATED_0), I_CmsReport.FORMAT_OK);
2249                m_user = null;
2250                return;
2251            } catch (@SuppressWarnings("unused") CmsDbEntryNotFoundException e) {
2252                // user does not exist
2253            }
2254
2255            CmsParameterConfiguration config = OpenCms.getPasswordHandler().getConfiguration();
2256            if ((config != null) && config.containsKey(I_CmsPasswordHandler.CONVERT_DIGEST_ENCODING)) {
2257                if (config.getBoolean(I_CmsPasswordHandler.CONVERT_DIGEST_ENCODING, false)) {
2258                    m_userPassword = convertDigestEncoding(m_userPassword);
2259                }
2260            }
2261
2262            m_user = getCms().importUser(
2263                new CmsUUID().toString(),
2264                userName,
2265                m_userPassword,
2266                m_userFirstname,
2267                m_userLastname,
2268                m_userEmail,
2269                m_userFlags,
2270                m_userDateCreated,
2271                m_userInfos);
2272
2273            getReport().println(
2274                org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
2275                I_CmsReport.FORMAT_OK);
2276        } catch (Throwable e) {
2277            m_user = null;
2278            getReport().println(e);
2279
2280            CmsMessageContainer message = Messages.get().container(
2281                Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_USER_1,
2282                userName);
2283            if (LOG.isDebugEnabled()) {
2284                LOG.debug(message.key(), e);
2285            }
2286        } finally {
2287            m_userName = null;
2288            m_userPassword = null;
2289            m_userFirstname = null;
2290            m_userLastname = null;
2291            m_userEmail = null;
2292            m_userFlags = 0;
2293            m_userDateCreated = 0;
2294            m_userInfos = null;
2295        }
2296    }
2297
2298    /**
2299     * Sets the current user as member of the given group.<p>
2300     *
2301     * It can happen that the organizational unit has not been imported jet,
2302     * in this case, the data is kept for later.<p>
2303     *
2304     * @param groupName the name of the group to set
2305     *
2306     * @see #setMembership()
2307     */
2308    public void importUserGroup(String groupName) {
2309
2310        if ((m_throwable != null) || (m_user == null)) {
2311            return;
2312        }
2313        groupName = OpenCms.getImportExportManager().translateGroup(groupName);
2314        try {
2315            String ouName = CmsOrganizationalUnit.getParentFqn(groupName);
2316            try {
2317                // check if the organizational unit exists
2318                OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(), ouName);
2319                // set the user group
2320                getCms().addUserToGroup(m_user.getName(), groupName);
2321                return;
2322            } catch (@SuppressWarnings("unused") CmsDbEntryNotFoundException e) {
2323                // organizational unit does not exist
2324            }
2325            // remember the user and group for later
2326            Map<String, Map<String, String>> membership = m_membership.get(ouName);
2327            if (membership == null) {
2328                membership = new HashMap<String, Map<String, String>>();
2329                m_membership.put(ouName, membership);
2330            }
2331            Map<String, String> groups = membership.get(I_CmsPrincipal.PRINCIPAL_GROUP);
2332            if (groups == null) {
2333                groups = new HashMap<String, String>();
2334                membership.put(I_CmsPrincipal.PRINCIPAL_GROUP, groups);
2335            }
2336            groups.put(m_user.getName(), groupName);
2337        } catch (Throwable e) {
2338            getReport().println(
2339                Messages.get().container(Messages.RPT_USER_COULDNT_BE_ADDED_TO_GROUP_2, m_user.getName(), groupName),
2340                I_CmsReport.FORMAT_WARNING);
2341            if (LOG.isDebugEnabled()) {
2342                LOG.debug(e.getLocalizedMessage(), e);
2343            }
2344        }
2345    }
2346
2347    /**
2348     * Creates a new additional information entry for the current user.<p>
2349     *
2350     * @param infoName the name of the additional information entry
2351     * @param infoType the type of the additional information entry
2352     * @param infoValue the value of the additional information entry
2353     */
2354    public void importUserInfo(String infoName, String infoType, String infoValue) {
2355
2356        if (m_userInfos == null) {
2357            m_userInfos = new HashMap<String, Object>();
2358        }
2359        try {
2360            m_userInfos.put(infoName, CmsDataTypeUtil.dataImport(infoValue, infoType));
2361        } catch (Throwable e) {
2362            if (LOG.isErrorEnabled()) {
2363                LOG.error(e.getLocalizedMessage(), e);
2364            }
2365        }
2366    }
2367
2368    /**
2369     * Sets the current user as member of the given role.<p>
2370     *
2371     * It can happen that the organizational unit has not been imported jet,
2372     * in this case, the data is kept for later.<p>
2373     *
2374     * @param roleName the name of the role to set
2375     *
2376     * @see #setMembership()
2377     */
2378    public void importUserRole(String roleName) {
2379
2380        if ((m_throwable != null) || (m_user == null)) {
2381            return;
2382        }
2383        try {
2384            CmsRole role = CmsRole.valueOfRoleName(roleName);
2385            try {
2386                // check if the organizational unit exists
2387                OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(), role.getOuFqn());
2388                // set the user role
2389                OpenCms.getRoleManager().addUserToRole(getCms(), role, m_user.getName());
2390                return;
2391            } catch (@SuppressWarnings("unused") CmsDbEntryNotFoundException e) {
2392                // organizational unit does not exist
2393            }
2394            // remember the user and role for later
2395            Map<String, Map<String, String>> membership = m_membership.get(role.getOuFqn());
2396            if (membership == null) {
2397                membership = new HashMap<String, Map<String, String>>();
2398                m_membership.put(role.getOuFqn(), membership);
2399            }
2400            Map<String, String> roles = membership.get(I_CmsPrincipal.PRINCIPAL_USER);
2401            if (roles == null) {
2402                roles = new HashMap<String, String>();
2403                membership.put(I_CmsPrincipal.PRINCIPAL_USER, roles);
2404            }
2405            roles.put(m_user.getName(), role.getFqn());
2406        } catch (Throwable e) {
2407            getReport().println(
2408                Messages.get().container(Messages.RPT_USER_COULDNT_BE_ADDED_TO_ROLE_2, m_user.getName(), roleName),
2409                I_CmsReport.FORMAT_WARNING);
2410            if (LOG.isDebugEnabled()) {
2411                LOG.debug(e.getLocalizedMessage(), e);
2412            }
2413        }
2414    }
2415
2416    /**
2417     * Increases the file counter.<p>
2418     */
2419    public void increaseCounter() {
2420
2421        m_fileCounter++;
2422    }
2423
2424    /**
2425     * Increases the total number of files.<p>
2426     */
2427    public void increaseTotalFiles() {
2428
2429        m_totalFiles++;
2430    }
2431
2432    /**
2433     * @see org.opencms.importexport.I_CmsImport#matches(org.opencms.importexport.CmsImportParameters)
2434     */
2435    @SuppressWarnings("resource") //stream is closed always in finally block - don't know why the compiler complains
2436    public boolean matches(CmsImportParameters parameters) throws CmsImportExportException {
2437
2438        m_fileCounter = 1;
2439        m_totalFiles = 0;
2440        m_parseables = new ArrayList<CmsResource>();
2441
2442        m_parameters = parameters;
2443
2444        // instantiate Digester and enable XML validation
2445        Digester digester = new Digester();
2446        digester.setUseContextClassLoader(true);
2447        digester.setValidating(m_parameters.isXmlValidation());
2448        digester.setEntityResolver(new CmsXmlEntityResolver(null));
2449        digester.setRuleNamespaceURI(null);
2450        digester.setErrorHandler(new CmsXmlErrorHandler(CmsImportExportManager.EXPORT_MANIFEST));
2451
2452        // add this object to the Digester
2453        digester.push(this);
2454
2455        addXmlPreprocessingDigesterRules(digester);
2456
2457        InputStream stream = null;
2458        m_helper = new CmsImportHelper(m_parameters);
2459        m_helper.cacheDtdSystemId(DTD_LOCATION, DTD_FILENAME, CmsConfigurationManager.DEFAULT_DTD_PREFIX);
2460        try {
2461            m_helper.openFile();
2462            // start the parsing process
2463            // this will set the version attribute
2464            stream = m_helper.getFileStream(CmsImportExportManager.EXPORT_MANIFEST);
2465            digester.parse(stream);
2466        } catch (Exception ioe) {
2467            CmsMessageContainer msg = Messages.get().container(
2468                Messages.ERR_IMPORTEXPORT_ERROR_READING_FILE_1,
2469                CmsImportExportManager.EXPORT_MANIFEST);
2470            if (LOG.isErrorEnabled()) {
2471                LOG.error(msg.key(), ioe);
2472            }
2473            throw new CmsImportExportException(msg, ioe);
2474        } finally {
2475            try {
2476                if (stream != null) {
2477                    stream.close();
2478                }
2479            } catch (@SuppressWarnings("unused") Exception e) {
2480                // noop
2481            }
2482            m_helper.closeFile();
2483        }
2484        return (m_version == getVersion());
2485    }
2486
2487    /**
2488     * Rewrites all parseable files, to assure link check.<p>
2489     *
2490     * This is a global process, that is executed only once at the
2491     * end of the import to be sure that all link targets are
2492     * available.<p>
2493     *
2494     * @see #addXmlDigesterRules(Digester)
2495     */
2496    public void rewriteParseables() {
2497
2498        if (m_parseables.isEmpty()) {
2499            return;
2500        }
2501
2502        I_CmsReport report = getReport();
2503        CmsObject cms = getCms();
2504        cms.getRequestContext().setAttribute(CmsLogEntry.ATTR_LOG_ENTRY, Boolean.FALSE);
2505        report.println(Messages.get().container(Messages.RPT_START_PARSE_LINKS_0), I_CmsReport.FORMAT_HEADLINE);
2506        parseLinks(cms, m_parseables, report);
2507        report.println(Messages.get().container(Messages.RPT_END_PARSE_LINKS_0), I_CmsReport.FORMAT_HEADLINE);
2508        m_parseables = null;
2509    }
2510
2511    /**
2512     * Sets the aceFlags.<p>
2513     *
2514     * @param aceFlags the aceFlags to set
2515     *
2516     * @see #N_FLAGS
2517     * @see #addResourceAceRules(Digester, String)
2518     */
2519    public void setAceFlags(String aceFlags) {
2520
2521        try {
2522            m_aceFlags = Integer.parseInt(aceFlags);
2523        } catch (Throwable e) {
2524            m_throwable = e;
2525        }
2526    }
2527
2528    /**
2529     * Sets the acePermissionsAllowed.<p>
2530     *
2531     * @param acePermissionsAllowed the acePermissionsAllowed to set
2532     *
2533     * @see #N_ACCESSCONTROL_ALLOWEDPERMISSIONS
2534     * @see #addResourceAceRules(Digester, String)
2535     */
2536    public void setAcePermissionsAllowed(String acePermissionsAllowed) {
2537
2538        try {
2539            m_acePermissionsAllowed = Integer.parseInt(acePermissionsAllowed);
2540        } catch (Throwable e) {
2541            m_throwable = e;
2542        }
2543    }
2544
2545    /**
2546     * Sets the acePermissionsDenied.<p>
2547     *
2548     * @param acePermissionsDenied the acePermissionsDenied to set
2549     *
2550     * @see #N_ACCESSCONTROL_DENIEDPERMISSIONS
2551     * @see #addResourceAceRules(Digester, String)
2552     */
2553    public void setAcePermissionsDenied(String acePermissionsDenied) {
2554
2555        try {
2556            m_acePermissionsDenied = Integer.parseInt(acePermissionsDenied);
2557        } catch (Throwable e) {
2558            m_throwable = e;
2559        }
2560    }
2561
2562    /**
2563     * Sets the acePrincipalId.<p>
2564     *
2565     * @param acePrincipalId the acePrincipalId to set
2566     *
2567     * @see #N_ACCESSCONTROL_PRINCIPAL
2568     * @see #addResourceAceRules(Digester, String)
2569     */
2570    public void setAcePrincipalId(String acePrincipalId) {
2571
2572        try {
2573            CmsUUID principalId = null;
2574            String principal = acePrincipalId.substring(acePrincipalId.indexOf('.') + 1, acePrincipalId.length());
2575            if (acePrincipalId.startsWith(I_CmsPrincipal.PRINCIPAL_GROUP)) {
2576                principal = OpenCms.getImportExportManager().translateGroup(principal);
2577                principalId = getCms().readGroup(principal).getId();
2578            } else if (acePrincipalId.startsWith(I_CmsPrincipal.PRINCIPAL_USER)) {
2579                principal = OpenCms.getImportExportManager().translateUser(principal);
2580                principalId = getCms().readUser(principal).getId();
2581            } else if (acePrincipalId.startsWith(CmsRole.PRINCIPAL_ROLE)) {
2582                principalId = CmsRole.valueOfRoleName(principal).getId();
2583            } else if (acePrincipalId.equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME)) {
2584                principalId = CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID;
2585            } else if (acePrincipalId.equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME)) {
2586                principalId = CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID;
2587            } else {
2588                if (LOG.isWarnEnabled()) {
2589                    LOG.warn(
2590                        Messages.get().getBundle().key(
2591                            Messages.LOG_IMPORTEXPORT_ERROR_IMPORTING_ACE_1,
2592                            acePrincipalId));
2593                }
2594                throw new CmsIllegalStateException(
2595                    Messages.get().container(Messages.LOG_IMPORTEXPORT_ERROR_IMPORTING_ACE_1, acePrincipalId));
2596            }
2597            m_acePrincipalId = principalId;
2598        } catch (Throwable e) {
2599            setThrowable(e);
2600        }
2601    }
2602
2603    /**
2604     * Sets the dateCreated.<p>
2605     *
2606     * @param dateCreated the dateCreated to set
2607     *
2608     * @see #N_DATECREATED
2609     * @see #addResourceAttributesRules(Digester, String)
2610     */
2611    public void setDateCreated(String dateCreated) {
2612
2613        try {
2614            if (dateCreated != null) {
2615                m_resourceBuilder.setDateCreated(convertTimestamp(dateCreated));
2616            } else {
2617                m_resourceBuilder.setDateCreated(System.currentTimeMillis());
2618            }
2619        } catch (Throwable e) {
2620            setThrowable(e);
2621        }
2622    }
2623
2624    /**
2625     * Sets the dateExpired.<p>
2626     *
2627     * @param dateExpired the dateExpired to set
2628     *
2629     * @see #N_DATEEXPIRED
2630     * @see #addResourceAttributesRules(Digester, String)
2631     */
2632    public void setDateExpired(String dateExpired) {
2633
2634        try {
2635            if (dateExpired != null) {
2636                m_resourceBuilder.setDateExpired(convertTimestamp(dateExpired));
2637            } else {
2638                m_resourceBuilder.setDateExpired(CmsResource.DATE_EXPIRED_DEFAULT);
2639            }
2640        } catch (Throwable e) {
2641            setThrowable(e);
2642        }
2643    }
2644
2645    /**
2646     * Sets the dateLastModified.<p>
2647     *
2648     * @param dateLastModified the dateLastModified to set
2649     *
2650     * @see #N_DATELASTMODIFIED
2651     * @see #addResourceAttributesRules(Digester, String)
2652     */
2653    public void setDateLastModified(String dateLastModified) {
2654
2655        m_hasDateLastModified = true;
2656        try {
2657            if (dateLastModified != null) {
2658                TimestampMode timeMode = TimestampMode.getEnum(CmsMacroResolver.stripMacro(dateLastModified));
2659                switch (timeMode) {
2660                    case FILETIME:
2661                        m_resourceBuilder.setDateLastModified(-1); //Can't get the information right now, must set it afterward.
2662                        break;
2663                    case IMPORTTIME:
2664                        m_resourceBuilder.setDateLastModified(System.currentTimeMillis());
2665                        break;
2666                    case VFSTIME:
2667                    default:
2668                        m_resourceBuilder.setDateLastModified(convertTimestamp(dateLastModified));
2669                        break;
2670                }
2671            } else {
2672                m_resourceBuilder.setDateLastModified(System.currentTimeMillis());
2673            }
2674        } catch (Throwable e) {
2675            setThrowable(e);
2676        }
2677    }
2678
2679    /**
2680     * Sets the dateReleased.<p>
2681     *
2682     * @param dateReleased the dateReleased to set
2683     *
2684     * @see #N_DATERELEASED
2685     * @see #addResourceAttributesRules(Digester, String)
2686     */
2687    public void setDateReleased(String dateReleased) {
2688
2689        try {
2690            if (dateReleased != null) {
2691                m_resourceBuilder.setDateReleased(convertTimestamp(dateReleased));
2692            } else {
2693                m_resourceBuilder.setDateReleased(CmsResource.DATE_RELEASED_DEFAULT);
2694            }
2695        } catch (Throwable e) {
2696            setThrowable(e);
2697        }
2698    }
2699
2700    /**
2701     * Sets the destination.<p>
2702     *
2703     * @param destination the destination to set
2704     *
2705     * @see #N_DESTINATION
2706     * @see #addResourceAttributesRules(Digester, String)
2707     */
2708    public void setDestination(String destination) {
2709
2710        m_destination = destination;
2711    }
2712
2713    /**
2714     * Sets the flags.<p>
2715     *
2716     * @param flags the flags to set
2717     *
2718     * @see #N_FLAGS
2719     * @see #addResourceAttributesRules(Digester, String)
2720     */
2721    public void setFlags(String flags) {
2722
2723        try {
2724            m_resourceBuilder.setFlags(Integer.parseInt(flags));
2725        } catch (Throwable e) {
2726            setThrowable(e);
2727        }
2728    }
2729
2730    /**
2731     * Sets the group Description.<p>
2732     *
2733     * @param groupDescription the description to set
2734     */
2735    public void setGroupDescription(String groupDescription) {
2736
2737        m_groupDescription = groupDescription;
2738    }
2739
2740    /**
2741     * Sets the group Flags.<p>
2742     *
2743     * @param groupFlags the flags to set
2744     */
2745    public void setGroupFlags(String groupFlags) {
2746
2747        try {
2748            m_groupFlags = Integer.parseInt(groupFlags);
2749        } catch (Throwable e) {
2750            setThrowable(e);
2751        }
2752    }
2753
2754    /**
2755     * Sets the group Name.<p>
2756     *
2757     * @param groupName the name to set
2758     */
2759    public void setGroupName(String groupName) {
2760
2761        m_groupName = OpenCms.getImportExportManager().translateGroup(groupName);
2762    }
2763
2764    /**
2765     * Sets the group Parent.<p>
2766     *
2767     * @param groupParent the group Parent to set
2768     */
2769    public void setGroupParent(String groupParent) {
2770
2771        m_groupParent = OpenCms.getImportExportManager().translateGroup(groupParent);
2772    }
2773
2774    /**
2775     * Sets the membership information that could not been set immediately,
2776     * because of import order issues.<p>
2777     */
2778    public void setMembership() {
2779
2780        if ((m_orgUnit == null) || (m_membership == null)) {
2781            return;
2782        }
2783
2784        // get the membership data to set
2785        Map<String, Map<String, String>> membership = m_membership.get(m_orgUnit.getName());
2786        if (membership == null) {
2787            return;
2788        }
2789
2790        // set group membership
2791        Map<String, String> groups = membership.get(I_CmsPrincipal.PRINCIPAL_GROUP);
2792        if (groups != null) {
2793            Iterator<Entry<String, String>> it = groups.entrySet().iterator();
2794            while (it.hasNext()) {
2795                Entry<String, String> entry = it.next();
2796                String userName = entry.getKey();
2797                String groupName = entry.getValue();
2798
2799                // set the users group
2800                try {
2801                    getCms().addUserToGroup(userName, groupName);
2802                } catch (Throwable e) {
2803                    getReport().println(
2804                        Messages.get().container(Messages.RPT_USER_COULDNT_BE_ADDED_TO_GROUP_2, userName, groupName),
2805                        I_CmsReport.FORMAT_WARNING);
2806                    if (LOG.isDebugEnabled()) {
2807                        LOG.debug(e.getLocalizedMessage(), e);
2808                    }
2809                }
2810            }
2811        }
2812
2813        // set role membership
2814        Map<String, String> roles = membership.get(I_CmsPrincipal.PRINCIPAL_USER);
2815        if (roles != null) {
2816            Iterator<Entry<String, String>> it = roles.entrySet().iterator();
2817            while (it.hasNext()) {
2818                Entry<String, String> entry = it.next();
2819                String userName = entry.getKey();
2820                String roleName = entry.getValue();
2821
2822                // set the users roles
2823                CmsRole role = CmsRole.valueOfRoleName(roleName);
2824                try {
2825                    // set the user role
2826                    OpenCms.getRoleManager().addUserToRole(getCms(), role, userName);
2827                    return;
2828                } catch (Throwable e) {
2829                    getReport().println(
2830                        Messages.get().container(Messages.RPT_USER_COULDNT_BE_ADDED_TO_ROLE_2, userName, roleName),
2831                        I_CmsReport.FORMAT_WARNING);
2832                    if (LOG.isDebugEnabled()) {
2833                        LOG.debug(e.getLocalizedMessage(), e);
2834                    }
2835                }
2836            }
2837        }
2838    }
2839
2840    /**
2841     * Sets the organizational unit description.<p>
2842     *
2843     * @param orgUnitDescription the description to set
2844     */
2845    public void setOrgUnitDescription(String orgUnitDescription) {
2846
2847        m_orgUnitDescription = orgUnitDescription;
2848    }
2849
2850    /**
2851     * Sets the organizational unit flags.<p>
2852     *
2853     * @param orgUnitFlags the flags to set
2854     */
2855    public void setOrgUnitFlags(String orgUnitFlags) {
2856
2857        try {
2858            m_orgUnitFlags = Integer.parseInt(orgUnitFlags);
2859        } catch (Throwable e) {
2860            setThrowable(e);
2861        }
2862    }
2863
2864    /**
2865     * Sets the organizational unit name.<p>
2866     *
2867     * @param orgUnitName the name to set
2868     */
2869    public void setOrgUnitName(String orgUnitName) {
2870
2871        m_orgUnitName = orgUnitName;
2872    }
2873
2874    /**
2875     * Sets the project Description.<p>
2876     *
2877     * @param projectDescription the description to set
2878     */
2879    public void setProjectDescription(String projectDescription) {
2880
2881        m_projectDescription = projectDescription;
2882    }
2883
2884    /**
2885     * Sets the project Managers group name.<p>
2886     *
2887     * @param projectManagers the managers group to set
2888     */
2889    public void setProjectManagers(String projectManagers) {
2890
2891        m_projectManagers = projectManagers;
2892    }
2893
2894    /**
2895     * Sets the project Name.<p>
2896     *
2897     * @param projectName the name to set
2898     */
2899    public void setProjectName(String projectName) {
2900
2901        m_projectName = projectName;
2902    }
2903
2904    /**
2905     * Sets the project Users group name.<p>
2906     *
2907     * @param projectUsers the Users group to set
2908     */
2909    public void setProjectUsers(String projectUsers) {
2910
2911        m_projectUsers = projectUsers;
2912    }
2913
2914    /**
2915     * Sets the propertyName.<p>
2916     *
2917     * @param propertyName the propertyName to set
2918     *
2919     * @see #N_NAME
2920     * @see #addResourcePropertyRules(Digester, String)
2921     */
2922    public void setPropertyName(String propertyName) {
2923
2924        m_propertyName = propertyName;
2925    }
2926
2927    /**
2928     * Sets the propertyValue.<p>
2929     *
2930     * @param propertyValue the propertyValue to set
2931     *
2932     * @see #N_VALUE
2933     * @see #addResourcePropertyRules(Digester, String)
2934     */
2935    public void setPropertyValue(String propertyValue) {
2936
2937        m_propertyValue = propertyValue;
2938    }
2939
2940    /**
2941     * Sets the relationId.<p>
2942     *
2943     * @param relationId the relationId to set
2944     *
2945     * @see #N_ID
2946     * @see #addResourceRelationRules(Digester, String)
2947     */
2948    public void setRelationId(String relationId) {
2949
2950        try {
2951            m_relationId = new CmsUUID(relationId);
2952        } catch (Throwable e) {
2953            setThrowable(e);
2954        }
2955    }
2956
2957    /**
2958     * Sets the relationPath.<p>
2959     *
2960     * @param relationPath the relationPath to set
2961     *
2962     * @see #N_PATH
2963     * @see #addResourceRelationRules(Digester, String)
2964     */
2965    public void setRelationPath(String relationPath) {
2966
2967        m_relationPath = relationPath;
2968    }
2969
2970    /**
2971     * Sets the relationType.<p>
2972     *
2973     * @param relationType the relationType to set
2974     *
2975     * @see #N_TYPE
2976     * @see #addResourceRelationRules(Digester, String)
2977     */
2978    public void setRelationType(String relationType) {
2979
2980        try {
2981            m_relationType = CmsRelationType.valueOf(relationType);
2982        } catch (Throwable e) {
2983            setThrowable(e);
2984        }
2985    }
2986
2987    /**
2988     * Sets the resourceId.<p>
2989     *
2990     * @param resourceId the resourceId to set
2991     *
2992     * @see #N_UUIDRESOURCE
2993     * @see #addResourceAttributesRules(Digester, String)
2994     */
2995    public void setResourceId(String resourceId) {
2996
2997        try {
2998            if (!m_resourceBuilder.isFolder()) {
2999                m_resourceBuilder.setResourceId(new CmsUUID(resourceId));
3000            } else {
3001                m_resourceBuilder.setResourceId(new CmsUUID());
3002            }
3003        } catch (Throwable e) {
3004            setThrowable(e);
3005        }
3006    }
3007
3008    /**
3009     * Sets the source.<p>
3010     *
3011     * @param source the source to set
3012     *
3013     * @see #N_SOURCE
3014     * @see #addResourceAttributesRules(Digester, String)
3015     */
3016    public void setSource(String source) {
3017
3018        m_source = source;
3019    }
3020
3021    /**
3022     * Sets the structureId.<p>
3023     *
3024     * @param structureId the structureId to set
3025     *
3026     * @see #N_UUIDSTRUCTURE
3027     * @see #addResourceAttributesRules(Digester, String)
3028     */
3029    public void setStructureId(String structureId) {
3030
3031        try {
3032            m_resourceBuilder.setStructureId(new CmsUUID(structureId));
3033            m_hasStructureId = true;
3034
3035        } catch (Throwable e) {
3036            setThrowable(e);
3037        }
3038
3039    }
3040
3041    /**
3042     * Sets the throwable.<p>
3043     *
3044     * @param throwable the throwable to set
3045     */
3046    public void setThrowable(Throwable throwable) {
3047
3048        m_throwable = throwable;
3049    }
3050
3051    /**
3052     * Sets the type.<p>
3053     *
3054     * @param typeName the type to set
3055     *
3056     * @see #N_TYPE
3057     * @see #addResourceAttributesRules(Digester, String)
3058     */
3059    public void setType(String typeName) {
3060
3061        m_typeName = typeName;
3062        try {
3063            try {
3064                m_resourceBuilder.setType(OpenCms.getResourceManager().getResourceType(typeName));
3065            } catch (@SuppressWarnings("unused") CmsLoaderException e) {
3066                // TODO: what happens if the resource type is a specialized folder and is not configured??
3067                try {
3068                    m_resourceBuilder.setType(
3069                        OpenCms.getResourceManager().getResourceType(CmsResourceTypePlain.getStaticTypeName()));
3070                } catch (@SuppressWarnings("unused") CmsLoaderException e1) {
3071                    // this should really never happen
3072                    m_resourceBuilder.setType(
3073                        OpenCms.getResourceManager().getResourceType(CmsResourceTypePlain.getStaticTypeName()));
3074                }
3075            }
3076            if (m_resourceBuilder.getType().isFolder()) {
3077                // ensure folders end with a "/"
3078                if (!CmsResource.isFolder(m_destination)) {
3079                    m_destination += "/";
3080                }
3081            }
3082        } catch (Throwable e) {
3083            setThrowable(e);
3084        }
3085    }
3086
3087    /**
3088     * Sets the user Created.<p>
3089     *
3090     * @param userCreated the user Created to set
3091     */
3092    public void setUserCreated(CmsUUID userCreated) {
3093
3094        m_resourceBuilder.setUserCreated(userCreated);
3095    }
3096
3097    /**
3098     * Sets the userCreated.<p>
3099     *
3100     * @param userCreated the userCreated to set
3101     *
3102     * @see #N_USERCREATED
3103     * @see #addResourceAttributesRules(Digester, String)
3104     */
3105    public void setUserCreated(String userCreated) {
3106
3107        try {
3108            String userCreatedName = OpenCms.getImportExportManager().translateUser(userCreated);
3109            try {
3110                m_resourceBuilder.setUserCreated(getCms().readUser(userCreatedName).getId());
3111            } catch (@SuppressWarnings("unused") CmsDbEntryNotFoundException e) {
3112                m_resourceBuilder.setUserCreated(getRequestContext().getCurrentUser().getId());
3113            }
3114        } catch (Throwable e) {
3115            setThrowable(e);
3116        }
3117    }
3118
3119    /**
3120     * Sets the user Date Created.<p>
3121     *
3122     * @param userDateCreated the date to set
3123     */
3124    public void setUserDateCreated(String userDateCreated) {
3125
3126        try {
3127            m_userDateCreated = convertTimestamp(userDateCreated);
3128        } catch (Throwable e) {
3129            setThrowable(e);
3130        }
3131    }
3132
3133    /**
3134     * Sets the user email address.<p>
3135     *
3136     * @param userEmail the email address to set
3137     */
3138    public void setUserEmail(String userEmail) {
3139
3140        m_userEmail = userEmail;
3141    }
3142
3143    /**
3144     * Sets the user First name.<p>
3145     *
3146     * @param userFirstname the first name to set
3147     */
3148    public void setUserFirstname(String userFirstname) {
3149
3150        m_userFirstname = userFirstname;
3151    }
3152
3153    /**
3154     * Sets the user Flags.<p>
3155     *
3156     * @param userFlags the flags to set
3157     */
3158    public void setUserFlags(String userFlags) {
3159
3160        try {
3161            m_userFlags = Integer.parseInt(userFlags);
3162        } catch (Throwable e) {
3163            setThrowable(e);
3164        }
3165    }
3166
3167    /**
3168     * Sets the user Last Modified.<p>
3169     *
3170     * @param userLastModified the user Last Modified to set
3171     */
3172    public void setUserLastModified(CmsUUID userLastModified) {
3173
3174        m_resourceBuilder.setUserLastModified(userLastModified);
3175    }
3176
3177    /**
3178     * Sets the userLastModified.<p>
3179     *
3180     * @param userLastModified the userLastModified to set
3181     *
3182     * @see #N_USERLASTMODIFIED
3183     * @see #addResourceAttributesRules(Digester, String)
3184     */
3185    public void setUserLastModified(String userLastModified) {
3186
3187        if (null == userLastModified) { // The optional user last modified information is not provided
3188            m_resourceBuilder.setUserLastModified(getRequestContext().getCurrentUser().getId());
3189        } else { // use the user last modified information from the manifest
3190            try {
3191                String userLastModifiedName = OpenCms.getImportExportManager().translateUser(userLastModified);
3192                try {
3193                    m_resourceBuilder.setUserLastModified(getCms().readUser(userLastModifiedName).getId());
3194                } catch (@SuppressWarnings("unused") CmsDbEntryNotFoundException e) {
3195                    m_resourceBuilder.setUserLastModified(getRequestContext().getCurrentUser().getId());
3196                }
3197            } catch (Throwable e) {
3198                setThrowable(e);
3199            }
3200        }
3201
3202    }
3203
3204    /**
3205     * Sets the user Last name.<p>
3206     *
3207     * @param userLastname the last name to set
3208     */
3209    public void setUserLastname(String userLastname) {
3210
3211        m_userLastname = userLastname;
3212    }
3213
3214    /**
3215     * Sets the user Name.<p>
3216     *
3217     * @param userName the name to set
3218     */
3219    public void setUserName(String userName) {
3220
3221        m_userName = OpenCms.getImportExportManager().translateUser(userName);
3222    }
3223
3224    /**
3225     * Sets the user Password.<p>
3226     *
3227     * @param userPassword the password to set
3228     */
3229    public void setUserPassword(String userPassword) {
3230
3231        m_userPassword = new String(Base64.decodeBase64(userPassword.trim().getBytes()));
3232    }
3233
3234    /**
3235     * Sets the export version from the manifest file.<p>
3236     *
3237     * @param version the export version to set
3238     */
3239    public void setVersion(String version) {
3240
3241        m_version = Integer.parseInt(version);
3242    }
3243
3244    /**
3245     * Adds the XML digester rules for groups.<p>
3246     *
3247     * @param digester the digester to add the rules to
3248     * @param xpath the base xpath for the rules
3249     */
3250    protected void addAccountsGroupRules(Digester digester, String xpath) {
3251
3252        String xp_group = xpath + N_GROUPS + "/" + N_GROUP;
3253        digester.addCallMethod(xp_group, "importGroup");
3254        xp_group += "/";
3255        digester.addCallMethod(xp_group + N_NAME, "setGroupName", 0);
3256        digester.addCallMethod(xp_group + N_DESCRIPTION, "setGroupDescription", 0);
3257        digester.addCallMethod(xp_group + N_FLAGS, "setGroupFlags", 0);
3258        digester.addCallMethod(xp_group + N_PARENTGROUP, "setGroupParent", 0);
3259    }
3260
3261    /**
3262     * Adds the XML digester rules for organizational units.<p>
3263     *
3264     * @param digester the digester to add the rules to
3265     * @param xpath the base xpath for the rules
3266     */
3267    protected void addAccountsOrgunitRules(Digester digester, String xpath) {
3268
3269        digester.addCallMethod(xpath + N_NAME, "setOrgUnitName", 0);
3270        digester.addCallMethod(xpath + N_DESCRIPTION, "setOrgUnitDescription", 0);
3271        digester.addCallMethod(xpath + N_FLAGS, "setOrgUnitFlags", 0);
3272        digester.addCallMethod(xpath + N_RESOURCES + "/" + N_RESOURCE, "addOrgUnitResource", 0);
3273        digester.addCallMethod(xpath + N_RESOURCES, "importOrgUnit");
3274    }
3275
3276    /**
3277     * Adds the XML digester rules for users.<p>
3278     *
3279     * @param digester the digester to add the rules to
3280     * @param xpath the base xpath for the rules
3281     */
3282    protected void addAccountsUserRules(Digester digester, String xpath) {
3283
3284        String xp_user = xpath + N_USERS + "/" + N_USER + "/";
3285        digester.addCallMethod(xp_user + N_NAME, "setUserName", 0);
3286        digester.addCallMethod(xp_user + N_PASSWORD, "setUserPassword", 0);
3287        digester.addCallMethod(xp_user + N_FIRSTNAME, "setUserFirstname", 0);
3288        digester.addCallMethod(xp_user + N_LASTNAME, "setUserLastname", 0);
3289        digester.addCallMethod(xp_user + N_EMAIL, "setUserEmail", 0);
3290        digester.addCallMethod(xp_user + N_FLAGS, "setUserFlags", 0);
3291        digester.addCallMethod(xp_user + N_DATECREATED, "setUserDateCreated", 0);
3292        digester.addCallMethod(xp_user + N_USERINFO, "importUser");
3293
3294        String xp_info = xp_user + N_USERINFO + "/" + N_USERINFO_ENTRY;
3295        digester.addCallMethod(xp_info, "importUserInfo", 3);
3296        digester.addCallParam(xp_info, 0, A_NAME);
3297        digester.addCallParam(xp_info, 1, A_TYPE);
3298        digester.addCallParam(xp_info, 2);
3299
3300        digester.addCallMethod(xp_user + N_USERROLES + "/" + N_USERROLE, "importUserRole", 0);
3301        digester.addCallMethod(xp_user + N_USERGROUPS + "/" + N_USERGROUP, "importUserGroup", 0);
3302    }
3303
3304    /**
3305     * Adds the XML digester rules for projects.<p>
3306     *
3307     * @param digester the digester to add the rules to
3308     * @param xpath the base xpath for the rules
3309     */
3310    protected void addProjectRules(Digester digester, String xpath) {
3311
3312        digester.addCallMethod(xpath + N_NAME, "setProjectName", 0);
3313        digester.addCallMethod(xpath + N_DESCRIPTION, "setProjectDescription", 0);
3314        digester.addCallMethod(xpath + N_MANAGERSGROUP, "setProjectManagers", 0);
3315        digester.addCallMethod(xpath + N_USERSGROUP, "setProjectUsers", 0);
3316        digester.addCallMethod(xpath + N_RESOURCES + "/" + N_RESOURCE, "addProjectResource", 0);
3317        digester.addCallMethod(xpath + N_RESOURCES, "importProject");
3318    }
3319
3320    /**
3321     * Adds the XML digester rules for resource access control entries.<p>
3322     *
3323     * @param digester the digester to add the rules to
3324     * @param xpath the base xpath for the rules
3325     */
3326    protected void addResourceAceRules(Digester digester, String xpath) {
3327
3328        String xp_ace = xpath + N_ACCESSCONTROL_ENTRIES + "/" + N_ACCESSCONTROL_ENTRY;
3329        digester.addCallMethod(xp_ace, "addAccessControlEntry");
3330        digester.addCallMethod(xp_ace + "/" + N_ACCESSCONTROL_PRINCIPAL, "setAcePrincipalId", 0);
3331        digester.addCallMethod(xp_ace + "/" + N_FLAGS, "setAceFlags", 0);
3332        String xp_perms = xp_ace + "/" + N_ACCESSCONTROL_PERMISSIONSET + "/";
3333        digester.addCallMethod(xp_perms + N_ACCESSCONTROL_ALLOWEDPERMISSIONS, "setAcePermissionsAllowed", 0);
3334        digester.addCallMethod(xp_perms + N_ACCESSCONTROL_DENIEDPERMISSIONS, "setAcePermissionsDenied", 0);
3335    }
3336
3337    /**
3338     * Adds the XML digester rules for resource attributes.<p>
3339     *
3340     * @param digester the digester to add the rules to
3341     * @param xpath the base xpath for the rules
3342     */
3343    protected void addResourceAttributesRules(Digester digester, String xpath) {
3344
3345        digester.addCallMethod(xpath + N_SOURCE, "setSource", 0);
3346        digester.addCallMethod(xpath + N_DESTINATION, "setDestination", 0);
3347        digester.addCallMethod(xpath + N_TYPE, "setType", 0);
3348        digester.addCallMethod(xpath + N_UUIDSTRUCTURE, "setStructureId", 0);
3349        digester.addCallMethod(xpath + N_UUIDRESOURCE, "setResourceId", 0);
3350        digester.addCallMethod(xpath + N_DATELASTMODIFIED, "setDateLastModified", 0);
3351        digester.addCallMethod(xpath + N_USERLASTMODIFIED, "setUserLastModified", 0);
3352        digester.addCallMethod(xpath + N_DATECREATED, "setDateCreated", 0);
3353        digester.addCallMethod(xpath + N_USERCREATED, "setUserCreated", 0);
3354        digester.addCallMethod(xpath + N_DATERELEASED, "setDateReleased", 0);
3355        digester.addCallMethod(xpath + N_DATEEXPIRED, "setDateExpired", 0);
3356        digester.addCallMethod(xpath + N_FLAGS, "setFlags", 0);
3357    }
3358
3359    /**
3360     * Adds the XML digester rules for resource properties.<p>
3361     *
3362     * @param digester the digester to add the rules to
3363     * @param xpath the base xpath for the rules
3364     */
3365    protected void addResourcePropertyRules(Digester digester, String xpath) {
3366
3367        String xp_props = xpath + N_PROPERTIES + "/" + N_PROPERTY;
3368        // first rule in case the type is implicit
3369        digester.addCallMethod(xp_props, "addProperty");
3370        // second rule in case the type is given
3371        digester.addCallMethod(xp_props, "addProperty", 1);
3372        digester.addCallParam(xp_props, 0, A_TYPE);
3373
3374        digester.addCallMethod(xp_props + "/" + N_NAME, "setPropertyName", 0);
3375        digester.addCallMethod(xp_props + "/" + N_VALUE, "setPropertyValue", 0);
3376
3377    }
3378
3379    /**
3380     * Adds the XML digester rules for resource relations.<p>
3381     *
3382     * @param digester the digester to add the rules to
3383     * @param xpath the base xpath for the rules
3384     */
3385    protected void addResourceRelationRules(Digester digester, String xpath) {
3386
3387        String xp_rels = xpath + N_RELATIONS + "/" + N_RELATION;
3388        digester.addCallMethod(xp_rels, "addRelation");
3389        digester.addCallMethod(xp_rels + "/" + N_ID, "setRelationId", 0);
3390        digester.addCallMethod(xp_rels + "/" + N_PATH, "setRelationPath", 0);
3391        digester.addCallMethod(xp_rels + "/" + N_TYPE, "setRelationType", 0);
3392    }
3393
3394    /**
3395     * Checks if the resources is in the list of immutable resources.<p>
3396     *
3397     * @param resourceName the name of the resource
3398     *
3399     * @return <code>true</code> or <code>false</code>
3400     */
3401    protected boolean checkImmutable(String resourceName) {
3402
3403        boolean resourceImmutable = false;
3404        if (getImmutableResources().contains(resourceName)) {
3405            if (LOG.isDebugEnabled()) {
3406                LOG.debug(
3407                    Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_RESOURCENAME_IMMUTABLE_1, resourceName));
3408            }
3409            // this resource must not be modified by an import if it already exists
3410            String storedSiteRoot = getRequestContext().getSiteRoot();
3411            try {
3412                getRequestContext().setSiteRoot("/");
3413                getCms().readResource(resourceName);
3414                resourceImmutable = true;
3415                if (LOG.isDebugEnabled()) {
3416                    LOG.debug(
3417                        Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_IMMUTABLE_FLAG_SET_1, resourceName));
3418                }
3419            } catch (CmsException e) {
3420                // resourceNotImmutable will be true
3421                if (LOG.isDebugEnabled()) {
3422                    LOG.debug(
3423                        Messages.get().getBundle().key(
3424                            Messages.LOG_IMPORTEXPORT_ERROR_ON_TEST_IMMUTABLE_1,
3425                            resourceName),
3426                        e);
3427                }
3428            } finally {
3429                getRequestContext().setSiteRoot(storedSiteRoot);
3430            }
3431        }
3432        return resourceImmutable;
3433    }
3434
3435    /**
3436     * Converts a given digest to base64 encoding.<p>
3437     *
3438     * @param value the digest value in the legacy encoding
3439     *
3440     * @return the digest in the new encoding
3441     */
3442    protected String convertDigestEncoding(String value) {
3443
3444        byte[] data = new byte[value.length() / 2];
3445
3446        for (int i = 0; i < data.length; i++) {
3447            data[i] = (byte)(Integer.parseInt(value.substring(i * 2, (i * 2) + 2), 16) - 128);
3448        }
3449        return new String(Base64.encodeBase64(data));
3450    }
3451
3452    /**
3453     * Convert a given time stamp from a String format to a long value.<p>
3454     *
3455     * The time stamp is either the string representation of a long value (old export format)
3456     * or a user-readable string format.<p>
3457     *
3458     * @param timestamp time stamp to convert
3459     *
3460     * @return long value of the time stamp
3461     */
3462    protected long convertTimestamp(String timestamp) {
3463
3464        long value = 0;
3465        // try to parse the time stamp string
3466        // if it successes, its an old style long value
3467        try {
3468            value = Long.parseLong(timestamp);
3469        } catch (@SuppressWarnings("unused") NumberFormatException e) {
3470            // the time stamp was in in a user-readable string format, create the long value form it
3471            try {
3472                value = CmsDateUtil.parseHeaderDate(timestamp);
3473            } catch (@SuppressWarnings("unused") ParseException pe) {
3474                value = System.currentTimeMillis();
3475            }
3476        }
3477        return value;
3478    }
3479
3480    /**
3481     * Create a CmsResource object from the currently set field values.<p>
3482     *
3483     * @param translatedName the resource name
3484     * @param size the size
3485     * @return the new CmsResource object
3486     */
3487    protected CmsResource createResourceObjectFromFields(String translatedName, int size) {
3488
3489        m_resourceBuilder.setRootPath(translatedName);
3490        m_resourceBuilder.setState(CmsResource.STATE_NEW);
3491        m_resourceBuilder.setProjectLastModified(getRequestContext().getCurrentProject().getUuid());
3492        m_resourceBuilder.setLength(size);
3493        m_resourceBuilder.setSiblingCount(1);
3494        m_resourceBuilder.setVersion(0);
3495        m_resourceBuilder.setDateContent(System.currentTimeMillis());
3496        return m_resourceBuilder.buildResource();
3497    }
3498
3499    /**
3500     * This method goes through the manifest, records all files from the manifest for which the content also
3501     * exists in the zip file, and stores their resource ids in m_contentFiles.<p>
3502     *
3503     * @throws CmsImportExportException thrown when the manifest.xml can't be opened as stream.
3504     * @throws IOException thrown if the manifest.xml stream causes problems during parsing and/or closing.
3505     * @throws SAXException thrown if parsing the manifest.xml fails
3506     */
3507    protected void findContentFiles() throws CmsImportExportException, IOException, SAXException {
3508
3509        Digester digester = new Digester();
3510        digester.setUseContextClassLoader(true);
3511        digester.setValidating(false);
3512        digester.setEntityResolver(new CmsXmlEntityResolver(null));
3513        digester.setRuleNamespaceURI(null);
3514        digester.setErrorHandler(new CmsXmlErrorHandler(CmsImportExportManager.EXPORT_MANIFEST));
3515
3516        digester.addCallMethod("export/files/file", "addContentFile", 2);
3517        digester.addCallParam("export/files/file/source", 0);
3518        digester.addCallParam("export/files/file/uuidresource", 1);
3519        m_contentFiles.clear();
3520        digester.push(this);
3521        InputStream stream = null;
3522        try {
3523            stream = m_helper.getFileStream(CmsImportExportManager.EXPORT_MANIFEST);
3524            digester.parse(stream);
3525        } finally {
3526            if (stream != null) {
3527                stream.close();
3528            }
3529        }
3530    }
3531
3532    /**
3533     * Gets the import helper instance.<p>
3534     *
3535     * @return the import helper
3536     */
3537    protected CmsImportHelper getHelper() {
3538
3539        return m_helper;
3540    }
3541
3542    /**
3543     * Returns the list of properties to ignore during import.<p>
3544     *
3545     * @return the list of properties to ignore during import
3546     */
3547    protected List<String> getIgnoredProperties() {
3548
3549        if (m_ignoredProperties == null) {
3550            // get list of ignored properties
3551            m_ignoredProperties = OpenCms.getImportExportManager().getIgnoredProperties();
3552            if (m_ignoredProperties == null) {
3553                m_ignoredProperties = Collections.emptyList();
3554            }
3555        }
3556        return m_ignoredProperties;
3557    }
3558
3559    /**
3560     * Returns the list of immutable resources.<p>
3561     *
3562     * @return the list of immutable resources
3563     */
3564    protected List<String> getImmutableResources() {
3565
3566        if (m_immutables == null) {
3567            // get list of immutable resources
3568            m_immutables = OpenCms.getImportExportManager().getImmutableResources();
3569            if (m_immutables == null) {
3570                m_immutables = Collections.emptyList();
3571            }
3572            if (LOG.isDebugEnabled()) {
3573                LOG.debug(
3574                    Messages.get().getBundle().key(
3575                        Messages.LOG_IMPORTEXPORT_IMMUTABLE_RESOURCES_SIZE_1,
3576                        Integer.toString(m_immutables.size())));
3577            }
3578        }
3579        return m_immutables;
3580    }
3581
3582    /**
3583     * Fills the unset fields for an imported resource with default values.<p>
3584     *
3585     * @throws CmsImportExportException if something goes wrong
3586     */
3587    protected void setDefaultsForEmptyResourceFields() throws CmsImportExportException {
3588
3589        // get UUID for the structure
3590        if (m_resourceBuilder.getStructureId() == null) {
3591            // if null generate a new structure id
3592            m_resourceBuilder.setStructureId(new CmsUUID());
3593        }
3594
3595        // get UUIDs for the resource
3596        if ((m_resourceBuilder.getResourceId() == null) || (m_resourceBuilder.getType().isFolder())) {
3597            // folders get always a new resource UUID
3598            m_resourceBuilder.setResourceId(new CmsUUID());
3599            m_resourceIdWasNull = true;
3600        }
3601
3602        // read date last modified from the resource, default to currentTime for folders
3603        if (m_resourceBuilder.getDateLastModified() == DATE_LAST_MODIFICATION_FILETIME) {
3604            if (null != m_source) {
3605                m_resourceBuilder.setDateLastModified(m_helper.getFileModification(m_source));
3606            } else {
3607                m_resourceBuilder.setDateLastModified(System.currentTimeMillis());
3608            }
3609        }
3610
3611        if (m_resourceBuilder.getDateLastModified() == DATE_LAST_MODIFICATION_UNSPECIFIED) {
3612            m_resourceBuilder.setDateLastModified(System.currentTimeMillis());
3613        }
3614
3615        if (null == m_resourceBuilder.getUserLastModified()) {
3616            m_resourceBuilder.setUserLastModified(m_cms.getRequestContext().getCurrentUser().getId());
3617        }
3618
3619        if (m_resourceBuilder.getDateCreated() == DATE_CREATED_UNSPECIFIED) {
3620            m_resourceBuilder.setDateCreated(System.currentTimeMillis());
3621        }
3622
3623        if (m_resourceBuilder.getUserCreated().isNullUUID()) {
3624            m_resourceBuilder.setUserCreated(getRequestContext().getCurrentUser().getId());
3625        }
3626
3627        if (m_properties == null) {
3628            m_properties = new HashMap<String, CmsProperty>();
3629        }
3630    }
3631
3632    /**
3633     * Checks whether the content for the resource being imported exists either in the VFS or in the import file.<p>
3634     *
3635     * @param resource the resource which should be checked
3636     *
3637     * @return true if the content exists in the VFS or import file
3638     */
3639    private boolean hasContentInVfsOrImport(CmsResource resource) {
3640
3641        if (m_contentFiles.contains(resource.getResourceId())) {
3642            return true;
3643        }
3644        try {
3645            List<CmsResource> resources = getCms().readSiblings(resource, CmsResourceFilter.ALL);
3646            if (!resources.isEmpty()) {
3647                return true;
3648            }
3649        } catch (CmsException e) {
3650            LOG.warn(e.getLocalizedMessage(), e);
3651        }
3652        return false;
3653
3654    }
3655}