001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.lar;
016    
017    import com.liferay.portal.NoSuchRoleException;
018    import com.liferay.portal.NoSuchTeamException;
019    import com.liferay.portal.kernel.bean.BeanPropertiesUtil;
020    import com.liferay.portal.kernel.dao.orm.Conjunction;
021    import com.liferay.portal.kernel.dao.orm.Criterion;
022    import com.liferay.portal.kernel.dao.orm.DynamicQuery;
023    import com.liferay.portal.kernel.dao.orm.Property;
024    import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
025    import com.liferay.portal.kernel.dao.orm.RestrictionsFactoryUtil;
026    import com.liferay.portal.kernel.exception.PortalException;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.lar.ExportImportClassedModelUtil;
029    import com.liferay.portal.kernel.lar.ExportImportPathUtil;
030    import com.liferay.portal.kernel.lar.ExportImportThreadLocal;
031    import com.liferay.portal.kernel.lar.ManifestSummary;
032    import com.liferay.portal.kernel.lar.PortletDataContext;
033    import com.liferay.portal.kernel.lar.PortletDataContextListener;
034    import com.liferay.portal.kernel.lar.PortletDataHandlerControl;
035    import com.liferay.portal.kernel.lar.PortletDataHandlerKeys;
036    import com.liferay.portal.kernel.lar.StagedModelDataHandlerUtil;
037    import com.liferay.portal.kernel.lar.StagedModelType;
038    import com.liferay.portal.kernel.lar.UserIdStrategy;
039    import com.liferay.portal.kernel.log.Log;
040    import com.liferay.portal.kernel.log.LogFactoryUtil;
041    import com.liferay.portal.kernel.util.ArrayUtil;
042    import com.liferay.portal.kernel.util.DateRange;
043    import com.liferay.portal.kernel.util.GetterUtil;
044    import com.liferay.portal.kernel.util.HtmlUtil;
045    import com.liferay.portal.kernel.util.KeyValuePair;
046    import com.liferay.portal.kernel.util.ListUtil;
047    import com.liferay.portal.kernel.util.MapUtil;
048    import com.liferay.portal.kernel.util.PrimitiveLongList;
049    import com.liferay.portal.kernel.util.StringBundler;
050    import com.liferay.portal.kernel.util.StringPool;
051    import com.liferay.portal.kernel.util.StringUtil;
052    import com.liferay.portal.kernel.util.Validator;
053    import com.liferay.portal.kernel.workflow.WorkflowConstants;
054    import com.liferay.portal.kernel.xml.Attribute;
055    import com.liferay.portal.kernel.xml.Element;
056    import com.liferay.portal.kernel.xml.Node;
057    import com.liferay.portal.kernel.xml.SAXReaderUtil;
058    import com.liferay.portal.kernel.xml.XPath;
059    import com.liferay.portal.kernel.zip.ZipReader;
060    import com.liferay.portal.kernel.zip.ZipWriter;
061    import com.liferay.portal.model.AttachedModel;
062    import com.liferay.portal.model.AuditedModel;
063    import com.liferay.portal.model.ClassedModel;
064    import com.liferay.portal.model.Group;
065    import com.liferay.portal.model.Layout;
066    import com.liferay.portal.model.Lock;
067    import com.liferay.portal.model.OrgLabor;
068    import com.liferay.portal.model.Portlet;
069    import com.liferay.portal.model.PortletModel;
070    import com.liferay.portal.model.ResourceConstants;
071    import com.liferay.portal.model.ResourcedModel;
072    import com.liferay.portal.model.Role;
073    import com.liferay.portal.model.RoleConstants;
074    import com.liferay.portal.model.StagedGroupedModel;
075    import com.liferay.portal.model.StagedModel;
076    import com.liferay.portal.model.Team;
077    import com.liferay.portal.model.impl.LockImpl;
078    import com.liferay.portal.security.permission.ResourceActionsUtil;
079    import com.liferay.portal.service.GroupLocalServiceUtil;
080    import com.liferay.portal.service.LockLocalServiceUtil;
081    import com.liferay.portal.service.ResourceBlockLocalServiceUtil;
082    import com.liferay.portal.service.ResourceBlockPermissionLocalServiceUtil;
083    import com.liferay.portal.service.ResourcePermissionLocalServiceUtil;
084    import com.liferay.portal.service.RoleLocalServiceUtil;
085    import com.liferay.portal.service.ServiceContext;
086    import com.liferay.portal.service.TeamLocalServiceUtil;
087    import com.liferay.portal.util.PortalUtil;
088    import com.liferay.portal.util.PortletKeys;
089    import com.liferay.portal.util.PropsValues;
090    import com.liferay.portlet.asset.model.AssetCategory;
091    import com.liferay.portlet.asset.model.AssetEntry;
092    import com.liferay.portlet.asset.model.AssetLink;
093    import com.liferay.portlet.asset.model.AssetTag;
094    import com.liferay.portlet.asset.service.AssetCategoryLocalServiceUtil;
095    import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
096    import com.liferay.portlet.asset.service.AssetLinkLocalServiceUtil;
097    import com.liferay.portlet.asset.service.AssetTagLocalServiceUtil;
098    import com.liferay.portlet.blogs.model.impl.BlogsEntryImpl;
099    import com.liferay.portlet.bookmarks.model.impl.BookmarksEntryImpl;
100    import com.liferay.portlet.bookmarks.model.impl.BookmarksFolderImpl;
101    import com.liferay.portlet.documentlibrary.lar.xstream.FileEntryConverter;
102    import com.liferay.portlet.documentlibrary.lar.xstream.FileVersionConverter;
103    import com.liferay.portlet.documentlibrary.lar.xstream.FolderConverter;
104    import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryImpl;
105    import com.liferay.portlet.documentlibrary.model.impl.DLFileShortcutImpl;
106    import com.liferay.portlet.documentlibrary.model.impl.DLFolderImpl;
107    import com.liferay.portlet.dynamicdatamapping.storage.Field;
108    import com.liferay.portlet.dynamicdatamapping.storage.Fields;
109    import com.liferay.portlet.expando.model.ExpandoBridge;
110    import com.liferay.portlet.expando.model.ExpandoColumn;
111    import com.liferay.portlet.expando.service.ExpandoColumnLocalServiceUtil;
112    import com.liferay.portlet.journal.model.impl.JournalArticleImpl;
113    import com.liferay.portlet.journal.model.impl.JournalFeedImpl;
114    import com.liferay.portlet.messageboards.model.MBDiscussion;
115    import com.liferay.portlet.messageboards.model.MBMessage;
116    import com.liferay.portlet.messageboards.model.MBThread;
117    import com.liferay.portlet.messageboards.model.impl.MBBanImpl;
118    import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
119    import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
120    import com.liferay.portlet.messageboards.model.impl.MBThreadFlagImpl;
121    import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
122    import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
123    import com.liferay.portlet.messageboards.service.persistence.MBDiscussionUtil;
124    import com.liferay.portlet.messageboards.service.persistence.MBMessageUtil;
125    import com.liferay.portlet.polls.model.impl.PollsChoiceImpl;
126    import com.liferay.portlet.polls.model.impl.PollsQuestionImpl;
127    import com.liferay.portlet.polls.model.impl.PollsVoteImpl;
128    import com.liferay.portlet.ratings.model.RatingsEntry;
129    import com.liferay.portlet.ratings.model.impl.RatingsEntryImpl;
130    import com.liferay.portlet.ratings.service.RatingsEntryLocalServiceUtil;
131    import com.liferay.portlet.wiki.model.impl.WikiNodeImpl;
132    import com.liferay.portlet.wiki.model.impl.WikiPageImpl;
133    
134    import com.thoughtworks.xstream.XStream;
135    import com.thoughtworks.xstream.security.NoTypePermission;
136    import com.thoughtworks.xstream.security.PrimitiveTypePermission;
137    
138    import java.io.IOException;
139    import java.io.InputStream;
140    import java.io.Serializable;
141    
142    import java.math.BigDecimal;
143    
144    import java.sql.Time;
145    import java.sql.Timestamp;
146    
147    import java.util.ArrayList;
148    import java.util.Collections;
149    import java.util.Date;
150    import java.util.HashMap;
151    import java.util.HashSet;
152    import java.util.List;
153    import java.util.Locale;
154    import java.util.Map;
155    import java.util.Set;
156    
157    import jodd.bean.BeanUtil;
158    
159    /**
160     * <p>
161     * Holds context information that is used during exporting and importing portlet
162     * data.
163     * </p>
164     *
165     * @author Brian Wing Shun Chan
166     * @author Raymond Aug??
167     * @author Bruno Farache
168     * @author Alexander Chow
169     * @author Mate Thurzo
170     */
171    public class PortletDataContextImpl implements PortletDataContext {
172    
173            public PortletDataContextImpl() {
174                    initXStream();
175            }
176    
177            @Override
178            public void addAssetCategories(Class<?> clazz, long classPK)
179                    throws SystemException {
180    
181                    List<AssetCategory> assetCategories =
182                            AssetCategoryLocalServiceUtil.getCategories(
183                                    clazz.getName(), classPK);
184    
185                    _assetCategoryUuidsMap.put(
186                            getPrimaryKeyString(clazz, classPK),
187                            StringUtil.split(
188                                    ListUtil.toString(
189                                            assetCategories, AssetCategory.UUID_ACCESSOR)));
190                    _assetCategoryIdsMap.put(
191                            getPrimaryKeyString(clazz, classPK),
192                            StringUtil.split(
193                                    ListUtil.toString(
194                                            assetCategories, AssetCategory.CATEGORY_ID_ACCESSOR), 0L));
195            }
196    
197            @Override
198            public void addAssetCategories(
199                    String className, long classPK, long[] assetCategoryIds) {
200    
201                    _assetCategoryIdsMap.put(
202                            getPrimaryKeyString(className, classPK), assetCategoryIds);
203            }
204    
205            public void addAssetLinks(Class<?> clazz, long classPK)
206                    throws SystemException {
207    
208                    AssetEntry assetEntry = AssetEntryLocalServiceUtil.fetchEntry(
209                            clazz.getName(), classPK);
210    
211                    if (assetEntry == null) {
212                            return;
213                    }
214    
215                    List<AssetLink> directAssetLinks =
216                            AssetLinkLocalServiceUtil.getDirectLinks(assetEntry.getEntryId());
217    
218                    if (directAssetLinks.isEmpty()) {
219                            return;
220                    }
221    
222                    Map<Integer, List<AssetLink>> assetLinksMap =
223                            new HashMap<Integer, List<AssetLink>>();
224    
225                    for (AssetLink assetLink : directAssetLinks) {
226                            List<AssetLink> assetLinks = assetLinksMap.get(assetLink.getType());
227    
228                            if (assetLinks == null) {
229                                    assetLinks = new ArrayList<AssetLink>();
230    
231                                    assetLinksMap.put(assetLink.getType(), assetLinks);
232                            }
233    
234                            assetLinks.add(assetLink);
235                    }
236    
237                    for (Map.Entry<Integer, List<AssetLink>> entry :
238                                    assetLinksMap.entrySet()) {
239    
240                            _assetLinksMap.put(
241                                    getPrimaryKeyString(assetEntry.getClassUuid(), entry.getKey()),
242                                    entry.getValue());
243                    }
244            }
245    
246            @Override
247            public void addAssetTags(Class<?> clazz, long classPK)
248                    throws SystemException {
249    
250                    String[] tagNames = AssetTagLocalServiceUtil.getTagNames(
251                            clazz.getName(), classPK);
252    
253                    _assetTagNamesMap.put(getPrimaryKeyString(clazz, classPK), tagNames);
254            }
255    
256            @Override
257            public void addAssetTags(
258                    String className, long classPK, String[] assetTagNames) {
259    
260                    _assetTagNamesMap.put(
261                            getPrimaryKeyString(className, classPK), assetTagNames);
262            }
263    
264            @Override
265            public void addClassedModel(
266                            Element element, String path, ClassedModel classedModel)
267                    throws PortalException, SystemException {
268    
269                    addClassedModel(
270                            element, path, classedModel, classedModel.getModelClass());
271            }
272    
273            @Override
274            public void addClassedModel(
275                            Element element, String path, ClassedModel classedModel,
276                            Class<?> clazz)
277                    throws PortalException, SystemException {
278    
279                    element.addAttribute("path", path);
280    
281                    if (classedModel instanceof AttachedModel) {
282                            AttachedModel attachedModel = (AttachedModel)classedModel;
283    
284                            element.addAttribute("class-name", attachedModel.getClassName());
285                    }
286                    else if (BeanUtil.hasProperty(classedModel, "className")) {
287                            String className = BeanPropertiesUtil.getStringSilent(
288                                    classedModel, "className");
289    
290                            if (className != null) {
291                                    element.addAttribute("class-name", className);
292                            }
293                    }
294    
295                    if (isPathProcessed(path)) {
296                            return;
297                    }
298    
299                    if (classedModel instanceof AuditedModel) {
300                            AuditedModel auditedModel = (AuditedModel)classedModel;
301    
302                            auditedModel.setUserUuid(auditedModel.getUserUuid());
303                    }
304    
305                    if (isResourceMain(classedModel)) {
306                            long classPK = getClassPK(classedModel);
307    
308                            addAssetCategories(clazz, classPK);
309    
310                            if (classedModel instanceof ResourcedModel) {
311                                    updateAssetCategoriesPrimaryKeyString(clazz, classedModel);
312                            }
313    
314                            addAssetLinks(clazz, classPK);
315                            addAssetTags(clazz, classPK);
316                            addExpando(element, path, classedModel, clazz);
317                            addLocks(clazz, String.valueOf(classPK));
318                            addPermissions(clazz, classPK);
319    
320                            boolean portletDataAll = MapUtil.getBoolean(
321                                    getParameterMap(), PortletDataHandlerKeys.PORTLET_DATA_ALL);
322    
323                            if (portletDataAll ||
324                                    MapUtil.getBoolean(
325                                            getParameterMap(), PortletDataHandlerKeys.COMMENTS)) {
326    
327                                    addComments(clazz, classPK);
328                            }
329    
330                            if (portletDataAll ||
331                                    MapUtil.getBoolean(
332                                            getParameterMap(), PortletDataHandlerKeys.RATINGS)) {
333    
334                                    addRatingsEntries(clazz, classPK);
335                            }
336                    }
337    
338                    _references.add(getReferenceKey(classedModel));
339    
340                    addZipEntry(path, classedModel);
341            }
342    
343            /**
344             * @deprecated As of 6.2.0, replaced by {@link #addClassedModel(Element,
345             *             String, ClassedModel, Class)}
346             */
347            @Override
348            public void addClassedModel(
349                            Element element, String path, ClassedModel classedModel,
350                            Class<?> clazz, String namespace)
351                    throws PortalException, SystemException {
352    
353                    addClassedModel(element, path, classedModel, clazz);
354            }
355    
356            /**
357             * @deprecated As of 6.2.0, replaced by {@link #addClassedModel(Element,
358             *             String, ClassedModel)}
359             */
360            @Override
361            public void addClassedModel(
362                            Element element, String path, ClassedModel classedModel,
363                            String namespace)
364                    throws PortalException, SystemException {
365    
366                    addClassedModel(element, path, classedModel);
367            }
368    
369            @Override
370            public void addComments(Class<?> clazz, long classPK)
371                    throws SystemException {
372    
373                    long classNameId = PortalUtil.getClassNameId(clazz);
374    
375                    MBDiscussion discussion = MBDiscussionUtil.fetchByC_C(
376                            classNameId, classPK);
377    
378                    if (discussion == null) {
379                            return;
380                    }
381    
382                    List<MBMessage> messages = MBMessageLocalServiceUtil.getThreadMessages(
383                            discussion.getThreadId(), WorkflowConstants.STATUS_APPROVED);
384    
385                    if (messages.isEmpty()) {
386                            return;
387                    }
388    
389                    MBMessage firstMessage = messages.get(0);
390    
391                    if ((messages.size() == 1) && firstMessage.isRoot()) {
392                            return;
393                    }
394    
395                    for (MBMessage message : messages) {
396                            addRatingsEntries(MBDiscussion.class, message.getPrimaryKey());
397                    }
398    
399                    _commentsMap.put(getPrimaryKeyString(clazz, classPK), messages);
400            }
401    
402            @Override
403            public void addComments(
404                    String className, long classPK, List<MBMessage> messages) {
405    
406                    _commentsMap.put(getPrimaryKeyString(className, classPK), messages);
407            }
408    
409            /**
410             * @see #isWithinDateRange(Date)
411             */
412            @Override
413            public void addDateRangeCriteria(
414                    DynamicQuery dynamicQuery, String propertyName) {
415    
416                    Criterion criterion = getDateRangeCriteria(propertyName);
417    
418                    if (criterion == null) {
419                            return;
420                    }
421    
422                    dynamicQuery.add(criterion);
423            }
424    
425            @Override
426            public void addDeletionSystemEventStagedModelTypes(
427                    StagedModelType... stagedModelTypes) {
428    
429                    for (StagedModelType stagedModelType : stagedModelTypes) {
430                            _deletionSystemEventModelTypes.add(stagedModelType);
431                    }
432            }
433    
434            @Override
435            public void addExpando(
436                            Element element, String path, ClassedModel classedModel)
437                    throws PortalException, SystemException {
438    
439                    addExpando(element, path, classedModel, classedModel.getModelClass());
440            }
441    
442            @Override
443            public void addLocks(Class<?> clazz, String key)
444                    throws PortalException, SystemException {
445    
446                    if (!_locksMap.containsKey(getPrimaryKeyString(clazz, key)) &&
447                            LockLocalServiceUtil.isLocked(clazz.getName(), key)) {
448    
449                            Lock lock = LockLocalServiceUtil.getLock(clazz.getName(), key);
450    
451                            addLocks(clazz.getName(), key, lock);
452                    }
453            }
454    
455            @Override
456            public void addLocks(String className, String key, Lock lock) {
457                    _locksMap.put(getPrimaryKeyString(className, key), lock);
458            }
459    
460            @Override
461            public void addPermissions(Class<?> clazz, long classPK)
462                    throws PortalException, SystemException {
463    
464                    addPermissions(clazz.getName(), classPK);
465            }
466    
467            @Override
468            public void addPermissions(String resourceName, long resourcePK)
469                    throws PortalException, SystemException {
470    
471                    if (!MapUtil.getBoolean(
472                                    _parameterMap, PortletDataHandlerKeys.PERMISSIONS)) {
473    
474                            return;
475                    }
476    
477                    List<KeyValuePair> permissions = new ArrayList<KeyValuePair>();
478    
479                    List<Role> roles = RoleLocalServiceUtil.getGroupRelatedRoles(_groupId);
480    
481                    PrimitiveLongList roleIds = new PrimitiveLongList(roles.size());
482                    Map<Long, String> roleIdsToNames = new HashMap<Long, String>();
483    
484                    for (Role role : roles) {
485                            String roleName = role.getName();
486    
487                            int roleType = role.getType();
488    
489                            if ((roleType == RoleConstants.TYPE_PROVIDER) && role.isTeam()) {
490                                    Team team = TeamLocalServiceUtil.getTeam(role.getClassPK());
491    
492                                    roleName = PermissionExporter.ROLE_TEAM_PREFIX + team.getName();
493                            }
494    
495                            roleIds.add(role.getRoleId());
496                            roleIdsToNames.put(role.getRoleId(), roleName);
497                    }
498    
499                    List<String> actionIds = ResourceActionsUtil.getModelResourceActions(
500                            resourceName);
501    
502                    Map<Long, Set<String>> roleIdsToActionIds = getActionIds(
503                            _companyId, roleIds.getArray(), resourceName, resourcePK,
504                            actionIds);
505    
506                    for (Map.Entry<Long, String> entry : roleIdsToNames.entrySet()) {
507                            long roleId = entry.getKey();
508                            String name = entry.getValue();
509    
510                            Set<String> availableActionIds = roleIdsToActionIds.get(roleId);
511    
512                            if (availableActionIds == null) {
513                                    availableActionIds = Collections.emptySet();
514                            }
515    
516                            KeyValuePair permission = new KeyValuePair(
517                                    name, StringUtil.merge(availableActionIds));
518    
519                            permissions.add(permission);
520                    }
521    
522                    _permissionsMap.put(
523                            getPrimaryKeyString(resourceName, resourcePK), permissions);
524            }
525    
526            @Override
527            public void addPermissions(
528                    String resourceName, long resourcePK, List<KeyValuePair> permissions) {
529    
530                    _permissionsMap.put(
531                            getPrimaryKeyString(resourceName, resourcePK), permissions);
532            }
533    
534            @Override
535            public void addPortalPermissions() throws PortalException, SystemException {
536                    addPermissions(PortletKeys.PORTAL, getCompanyId());
537            }
538    
539            @Override
540            public void addPortletPermissions(String resourceName)
541                    throws PortalException, SystemException {
542    
543                    long groupId = getGroupId();
544    
545                    Group group = GroupLocalServiceUtil.getGroup(groupId);
546    
547                    if (group.isStagingGroup()) {
548                            if (group.isStagedRemotely()) {
549                                    groupId = group.getLiveGroupId();
550                            }
551                            else {
552                                    return;
553                            }
554                    }
555    
556                    addPermissions(resourceName, groupId);
557            }
558    
559            @Override
560            public boolean addPrimaryKey(Class<?> clazz, String primaryKey) {
561                    boolean value = hasPrimaryKey(clazz, primaryKey);
562    
563                    if (!value) {
564                            _primaryKeys.add(getPrimaryKeyString(clazz, primaryKey));
565                    }
566    
567                    return value;
568            }
569    
570            @Override
571            public void addRatingsEntries(Class<?> clazz, long classPK)
572                    throws SystemException {
573    
574                    List<RatingsEntry> ratingsEntries =
575                            RatingsEntryLocalServiceUtil.getEntries(clazz.getName(), classPK);
576    
577                    if (ratingsEntries.size() == 0) {
578                            return;
579                    }
580    
581                    _ratingsEntriesMap.put(
582                            getPrimaryKeyString(clazz, classPK), ratingsEntries);
583            }
584    
585            @Override
586            public void addRatingsEntries(
587                    String className, long classPK, List<RatingsEntry> ratingsEntries) {
588    
589                    _ratingsEntriesMap.put(
590                            getPrimaryKeyString(className, classPK), ratingsEntries);
591            }
592    
593            /**
594             * @deprecated As of 7.0.0, with no direct replacement
595             */
596            @Deprecated
597            @Override
598            public Element addReferenceElement(
599                    ClassedModel referrerClassedModel, Element element,
600                    ClassedModel classedModel, Class<?> clazz, String referenceType,
601                    boolean missing) {
602    
603                    return addReferenceElement(
604                            referrerClassedModel, element, classedModel, clazz.getName(),
605                            StringPool.BLANK, referenceType, missing);
606            }
607    
608            @Override
609            public Element addReferenceElement(
610                    ClassedModel referrerClassedModel, Element element,
611                    ClassedModel classedModel, String referenceType, boolean missing) {
612    
613                    return addReferenceElement(
614                            referrerClassedModel, element, classedModel,
615                            ExportImportClassedModelUtil.getClassName(classedModel),
616                            StringPool.BLANK, referenceType, missing);
617            }
618    
619            @Override
620            public Element addReferenceElement(
621                    ClassedModel referrerClassedModel, Element element,
622                    ClassedModel classedModel, String binPath, String referenceType,
623                    boolean missing) {
624    
625                    return addReferenceElement(
626                            referrerClassedModel, element, classedModel,
627                            ExportImportClassedModelUtil.getClassName(classedModel), binPath,
628                            referenceType, missing);
629            }
630    
631            @Override
632            public Element addReferenceElement(
633                    ClassedModel referrerClassedModel, Element element,
634                    ClassedModel classedModel, String className, String binPath,
635                    String referenceType, boolean missing) {
636    
637                    Element referenceElement = doAddReferenceElement(
638                            referrerClassedModel, element, classedModel, className, binPath,
639                            referenceType, false);
640    
641                    String referenceKey = getReferenceKey(classedModel);
642    
643                    if (missing) {
644                            if (_references.contains(referenceKey)) {
645                                    return referenceElement;
646                            }
647    
648                            referenceElement.addAttribute("missing", Boolean.TRUE.toString());
649    
650                            if (!_missingReferences.contains(referenceKey)) {
651                                    _missingReferences.add(referenceKey);
652    
653                                    doAddReferenceElement(
654                                            referrerClassedModel, null, classedModel, className,
655                                            binPath, referenceType, true);
656                            }
657                    }
658                    else {
659                            _references.add(referenceKey);
660    
661                            cleanUpMissingReferences(classedModel);
662                    }
663    
664                    return referenceElement;
665            }
666    
667            @Override
668            public boolean addScopedPrimaryKey(Class<?> clazz, String primaryKey) {
669                    boolean value = hasScopedPrimaryKey(clazz, primaryKey);
670    
671                    if (!value) {
672                            _scopedPrimaryKeys.add(getPrimaryKeyString(clazz, primaryKey));
673                    }
674    
675                    return value;
676            }
677    
678            @Override
679            public void addZipEntry(String path, byte[] bytes) throws SystemException {
680                    if (_portletDataContextListener != null) {
681                            _portletDataContextListener.onAddZipEntry(path);
682                    }
683    
684                    try {
685                            ZipWriter zipWriter = getZipWriter();
686    
687                            zipWriter.addEntry(path, bytes);
688                    }
689                    catch (IOException ioe) {
690                            throw new SystemException(ioe);
691                    }
692            }
693    
694            @Override
695            public void addZipEntry(String path, InputStream is)
696                    throws SystemException {
697    
698                    if (_portletDataContextListener != null) {
699                            _portletDataContextListener.onAddZipEntry(path);
700                    }
701    
702                    try {
703                            ZipWriter zipWriter = getZipWriter();
704    
705                            zipWriter.addEntry(path, is);
706                    }
707                    catch (IOException ioe) {
708                            throw new SystemException(ioe);
709                    }
710            }
711    
712            @Override
713            public void addZipEntry(String path, Object object) throws SystemException {
714                    addZipEntry(path, toXML(object));
715            }
716    
717            @Override
718            public void addZipEntry(String path, String s) throws SystemException {
719                    if (_portletDataContextListener != null) {
720                            _portletDataContextListener.onAddZipEntry(path);
721                    }
722    
723                    try {
724                            ZipWriter zipWriter = getZipWriter();
725    
726                            zipWriter.addEntry(path, s);
727                    }
728                    catch (IOException ioe) {
729                            throw new SystemException(ioe);
730                    }
731            }
732    
733            @Override
734            public void addZipEntry(String path, StringBuilder sb)
735                    throws SystemException {
736    
737                    if (_portletDataContextListener != null) {
738                            _portletDataContextListener.onAddZipEntry(path);
739                    }
740    
741                    try {
742                            ZipWriter zipWriter = getZipWriter();
743    
744                            zipWriter.addEntry(path, sb);
745                    }
746                    catch (IOException ioe) {
747                            throw new SystemException(ioe);
748                    }
749            }
750    
751            @Override
752            public void cleanUpMissingReferences(ClassedModel classedModel) {
753                    String referenceKey = getReferenceKey(classedModel);
754    
755                    if (_missingReferences.contains(referenceKey)) {
756                            _missingReferences.remove(referenceKey);
757    
758                            Element missingReferenceElement = getMissingReferenceElement(
759                                    classedModel);
760    
761                            _missingReferencesElement.remove(missingReferenceElement);
762                    }
763            }
764    
765            @Override
766            public void clearScopedPrimaryKeys() {
767                    _scopedPrimaryKeys.clear();
768            }
769    
770            @Override
771            public ServiceContext createServiceContext(
772                    Element element, ClassedModel classedModel) {
773    
774                    return createServiceContext(
775                            element, null, classedModel, classedModel.getModelClass());
776            }
777    
778            /**
779             * @deprecated As of 6.2.0, replaced by {@link
780             *             #createServiceContext(Element, ClassedModel)}
781             */
782            @Override
783            public ServiceContext createServiceContext(
784                    Element element, ClassedModel classedModel, String namespace) {
785    
786                    return createServiceContext(element, classedModel);
787            }
788    
789            @Override
790            public ServiceContext createServiceContext(StagedModel stagedModel) {
791    
792                    return createServiceContext(stagedModel, stagedModel.getModelClass());
793            }
794    
795            @Override
796            public ServiceContext createServiceContext(
797                    StagedModel stagedModel, Class<?> clazz) {
798    
799                    return createServiceContext(
800                            null, ExportImportPathUtil.getModelPath(stagedModel), stagedModel,
801                            clazz);
802            }
803    
804            @Override
805            public ServiceContext createServiceContext(
806                    String path, ClassedModel classedModel) {
807    
808                    return createServiceContext(
809                            null, path, classedModel, classedModel.getModelClass());
810            }
811    
812            /**
813             * @deprecated As of 6.2.0, replaced by {@link #createServiceContext(String,
814             *             ClassedModel)}
815             */
816            @Override
817            public ServiceContext createServiceContext(
818                    String path, ClassedModel classedModel, String namespace) {
819    
820                    return createServiceContext(path, classedModel);
821            }
822    
823            @Override
824            public Object fromXML(byte[] bytes) {
825                    if (ArrayUtil.isEmpty(bytes)) {
826                            return null;
827                    }
828    
829                    return _xStream.fromXML(new String(bytes));
830            }
831    
832            @Override
833            public Object fromXML(String xml) {
834                    if (Validator.isNull(xml)) {
835                            return null;
836                    }
837    
838                    return _xStream.fromXML(xml);
839            }
840    
841            @Override
842            public long[] getAssetCategoryIds(Class<?> clazz, long classPK) {
843                    return _assetCategoryIdsMap.get(getPrimaryKeyString(clazz, classPK));
844            }
845    
846            /**
847             * @deprecated As of 7.0.0
848             */
849            @Deprecated
850            @Override
851            public Map<String, long[]> getAssetCategoryIdsMap() {
852                    return _assetCategoryIdsMap;
853            }
854    
855            @Override
856            public Map<String, String[]> getAssetCategoryUuidsMap() {
857                    return _assetCategoryUuidsMap;
858            }
859    
860            @Override
861            public Map<String, List<AssetLink>> getAssetLinksMap() {
862                    return _assetLinksMap;
863            }
864    
865            @Override
866            public String[] getAssetTagNames(Class<?> clazz, long classPK) {
867                    return _assetTagNamesMap.get(getPrimaryKeyString(clazz, classPK));
868            }
869    
870            @Override
871            public String[] getAssetTagNames(String className, long classPK) {
872                    return _assetTagNamesMap.get(getPrimaryKeyString(className, classPK));
873            }
874    
875            @Override
876            public Map<String, String[]> getAssetTagNamesMap() {
877                    return _assetTagNamesMap;
878            }
879    
880            @Override
881            public boolean getBooleanParameter(String namespace, String name) {
882                    return getBooleanParameter(namespace, name, true);
883            }
884    
885            @Override
886            public boolean getBooleanParameter(
887                    String namespace, String name, boolean useDefaultValue) {
888    
889                    if (!useDefaultValue) {
890                            return MapUtil.getBoolean(
891                                    getParameterMap(),
892                                    PortletDataHandlerControl.getNamespacedControlName(
893                                            namespace, name));
894                    }
895    
896                    boolean defaultValue = MapUtil.getBoolean(
897                            getParameterMap(),
898                            PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT, true);
899    
900                    return MapUtil.getBoolean(
901                            getParameterMap(),
902                            PortletDataHandlerControl.getNamespacedControlName(namespace, name),
903                            defaultValue);
904            }
905    
906            @Override
907            public ClassLoader getClassLoader() {
908                    return _xStream.getClassLoader();
909            }
910    
911            @Override
912            public Map<String, List<MBMessage>> getComments() {
913                    return _commentsMap;
914            }
915    
916            @Override
917            public long getCompanyGroupId() {
918                    return _companyGroupId;
919            }
920    
921            @Override
922            public long getCompanyId() {
923                    return _companyId;
924            }
925    
926            @Override
927            public String getDataStrategy() {
928                    return _dataStrategy;
929            }
930    
931            @Override
932            public DateRange getDateRange() {
933                    DateRange dateRange = null;
934    
935                    if (hasDateRange()) {
936                            dateRange = new DateRange(_startDate, _endDate);
937                    }
938    
939                    return dateRange;
940            }
941    
942            @Override
943            public Criterion getDateRangeCriteria(String propertyName) {
944                    if (!hasDateRange()) {
945                            return null;
946                    }
947    
948                    Conjunction conjunction = RestrictionsFactoryUtil.conjunction();
949    
950                    Property property = PropertyFactoryUtil.forName(propertyName);
951    
952                    conjunction.add(property.le(_endDate));
953                    conjunction.add(property.ge(_startDate));
954    
955                    return conjunction;
956            }
957    
958            @Override
959            public Map<String, List<String>> getDeletionKeysMap() {
960                    return _deletionKeysMap;
961            }
962    
963            @Override
964            public Set<StagedModelType> getDeletionSystemEventStagedModelTypes() {
965                    return _deletionSystemEventModelTypes;
966            }
967    
968            @Override
969            public Date getEndDate() {
970                    return _endDate;
971            }
972    
973            @Override
974            public Map<String, List<ExpandoColumn>> getExpandoColumns() {
975                    return _expandoColumnsMap;
976            }
977    
978            @Override
979            public Element getExportDataElement(ClassedModel classedModel) {
980                    return getExportDataElement(
981                            classedModel,
982                            ExportImportClassedModelUtil.getClassSimpleName(classedModel));
983            }
984    
985            /**
986             * @deprecated As of 7.0.0, replaced by {@link
987             *             #getExportDataElement(ClassedModel, String)}
988             */
989            @Deprecated
990            @Override
991            public Element getExportDataElement(
992                    ClassedModel classedModel, Class<?> modelClass) {
993    
994                    return getExportDataElement(classedModel, modelClass.getSimpleName());
995            }
996    
997            @Override
998            public Element getExportDataElement(
999                    ClassedModel classedModel, String modelClassSimpleName) {
1000    
1001                    Element groupElement = getExportDataGroupElement(modelClassSimpleName);
1002    
1003                    Element element = null;
1004    
1005                    if (classedModel instanceof StagedModel) {
1006                            StagedModel stagedModel = (StagedModel)classedModel;
1007    
1008                            String path = ExportImportPathUtil.getModelPath(stagedModel);
1009    
1010                            element = getDataElement(groupElement, "path", path);
1011    
1012                            if (element != null) {
1013                                    return element;
1014                            }
1015    
1016                            element = getDataElement(
1017                                    groupElement, "uuid", stagedModel.getUuid());
1018    
1019                            if (element != null) {
1020                                    return element;
1021                            }
1022                    }
1023    
1024                    element = groupElement.addElement("staged-model");
1025    
1026                    if (classedModel instanceof StagedGroupedModel) {
1027                            StagedGroupedModel stagedGroupedModel =
1028                                    (StagedGroupedModel)classedModel;
1029    
1030                            element.addAttribute(
1031                                    "group-id",String.valueOf(stagedGroupedModel.getGroupId()));
1032                            element.addAttribute("uuid", stagedGroupedModel.getUuid());
1033                    }
1034                    else if (classedModel instanceof StagedModel) {
1035                            StagedModel stagedModel = (StagedModel)classedModel;
1036    
1037                            element.addAttribute("uuid", stagedModel.getUuid());
1038                    }
1039    
1040                    return element;
1041            }
1042    
1043            @Override
1044            public Element getExportDataGroupElement(
1045                    Class<? extends StagedModel> clazz) {
1046    
1047                    return getExportDataGroupElement(clazz.getSimpleName());
1048            }
1049    
1050            @Override
1051            public Element getExportDataRootElement() {
1052                    return _exportDataRootElement;
1053            }
1054    
1055            @Override
1056            public long getGroupId() {
1057                    return _groupId;
1058            }
1059    
1060            @Override
1061            public Element getImportDataElement(StagedModel stagedModel) {
1062                    return getImportDataElement(
1063                            ExportImportClassedModelUtil.getClassSimpleName(stagedModel),
1064                            "uuid", stagedModel.getUuid());
1065            }
1066    
1067            @Override
1068            public Element getImportDataElement(
1069                    String name, String attribute, String value) {
1070    
1071                    Element groupElement = getImportDataGroupElement(name);
1072    
1073                    return getDataElement(groupElement, attribute, value);
1074            }
1075    
1076            @Override
1077            public Element getImportDataGroupElement(
1078                    Class<? extends StagedModel> clazz) {
1079    
1080                    return getImportDataGroupElement(clazz.getSimpleName());
1081            }
1082    
1083            @Override
1084            public Element getImportDataRootElement() {
1085                    return _importDataRootElement;
1086            }
1087    
1088            @Override
1089            public Element getImportDataStagedModelElement(StagedModel stagedModel) {
1090                    String path = ExportImportPathUtil.getModelPath(stagedModel);
1091    
1092                    return getImportDataElement(
1093                            ExportImportClassedModelUtil.getClassSimpleName(stagedModel),
1094                            "path", path);
1095            }
1096    
1097            @Override
1098            public String getLayoutPath(long plid) {
1099                    return ExportImportPathUtil.getLayoutPath(this, plid);
1100            }
1101    
1102            @Override
1103            public Map<String, Lock> getLocks() {
1104                    return _locksMap;
1105            }
1106    
1107            @Override
1108            public ManifestSummary getManifestSummary() {
1109                    return _manifestSummary;
1110            }
1111    
1112            @Override
1113            public Element getMissingReferencesElement() {
1114                    return _missingReferencesElement;
1115            }
1116    
1117            @Override
1118            public List<Layout> getNewLayouts() {
1119                    return _newLayouts;
1120            }
1121    
1122            @Override
1123            public Map<?, ?> getNewPrimaryKeysMap(Class<?> clazz) {
1124                    return getNewPrimaryKeysMap(clazz.getName());
1125            }
1126    
1127            @Override
1128            public Map<String, Map<?, ?>> getNewPrimaryKeysMaps() {
1129                    return _newPrimaryKeysMaps;
1130            }
1131    
1132            @Override
1133            public Map<?, ?> getNewPrimaryKeysMap(String className) {
1134                    Map<?, ?> map = _newPrimaryKeysMaps.get(className);
1135    
1136                    if (map == null) {
1137                            map = new HashMap<Object, Object>();
1138    
1139                            _newPrimaryKeysMaps.put(className, map);
1140                    }
1141    
1142                    return map;
1143            }
1144    
1145            /**
1146             * @deprecated As of 7.0.0
1147             */
1148            @Deprecated
1149            @Override
1150            public long getOldPlid() {
1151                    return _oldPlid;
1152            }
1153    
1154            @Override
1155            public Map<String, String[]> getParameterMap() {
1156                    return _parameterMap;
1157            }
1158    
1159            @Override
1160            public Map<String, List<KeyValuePair>> getPermissions() {
1161                    return _permissionsMap;
1162            }
1163    
1164            @Override
1165            public long getPlid() {
1166                    return _plid;
1167            }
1168    
1169            @Override
1170            public String getRootPortletId() {
1171                    return _rootPortletId;
1172            }
1173    
1174            @Override
1175            public String getPortletPath(String portletId) {
1176                    return ExportImportPathUtil.getPortletPath(this, portletId);
1177            }
1178    
1179            @Override
1180            public Set<String> getPrimaryKeys() {
1181                    return _primaryKeys;
1182            }
1183    
1184            @Override
1185            public Map<String, List<RatingsEntry>> getRatingsEntries() {
1186                    return _ratingsEntriesMap;
1187            }
1188    
1189            @Override
1190            public Element getReferenceDataElement(
1191                    Element parentElement, Class<?> clazz, long classPK) {
1192    
1193                    List<Element> referenceElements = getReferenceElements(
1194                            parentElement, clazz, 0, null, classPK, null);
1195    
1196                    List<Element> referenceDataElements = getReferenceDataElements(
1197                            referenceElements, clazz);
1198    
1199                    if (referenceDataElements.isEmpty()) {
1200                            return null;
1201                    }
1202    
1203                    return referenceDataElements.get(0);
1204            }
1205    
1206            @Override
1207            public Element getReferenceDataElement(
1208                    Element parentElement, Class<?> clazz, long groupId, String uuid) {
1209    
1210                    List<Element> referenceElements = getReferenceElements(
1211                            parentElement, clazz, groupId, uuid, 0, null);
1212    
1213                    List<Element> referenceDataElements = getReferenceDataElements(
1214                            referenceElements, clazz);
1215    
1216                    if (referenceDataElements.isEmpty()) {
1217                            return null;
1218                    }
1219    
1220                    return referenceDataElements.get(0);
1221            }
1222    
1223            @Override
1224            public Element getReferenceDataElement(
1225                    StagedModel parentStagedModel, Class<?> clazz, long classPK) {
1226    
1227                    Element parentElement = getImportDataStagedModelElement(
1228                            parentStagedModel);
1229    
1230                    return getReferenceDataElement(parentElement, clazz, classPK);
1231            }
1232    
1233            @Override
1234            public Element getReferenceDataElement(
1235                    StagedModel parentStagedModel, Class<?> clazz, long groupId,
1236                    String uuid) {
1237    
1238                    Element parentElement = getImportDataStagedModelElement(
1239                            parentStagedModel);
1240    
1241                    return getReferenceDataElement(parentElement, clazz, groupId, uuid);
1242            }
1243    
1244            /**
1245             * @deprecated As of 7.0.0
1246             */
1247            @Deprecated
1248            @Override
1249            public List<Element> getReferenceDataElements(
1250                    Element parentElement, Class<?> clazz) {
1251    
1252                    return getReferenceDataElements(parentElement, clazz, null);
1253            }
1254    
1255            @Override
1256            public List<Element> getReferenceDataElements(
1257                    Element parentElement, Class<?> clazz, String referenceType) {
1258    
1259                    List<Element> referenceElements = getReferenceElements(
1260                            parentElement, clazz, 0, null, 0, referenceType);
1261    
1262                    return getReferenceDataElements(referenceElements, clazz);
1263            }
1264    
1265            @Override
1266            public List<Element> getReferenceDataElements(
1267                    StagedModel parentStagedModel, Class<?> clazz) {
1268    
1269                    return getReferenceDataElements(parentStagedModel, clazz, null);
1270            }
1271    
1272            @Override
1273            public List<Element> getReferenceDataElements(
1274                    StagedModel parentStagedModel, Class<?> clazz, String referenceType) {
1275    
1276                    List<Element> referenceElements = getReferenceElements(
1277                            parentStagedModel, clazz, 0, referenceType);
1278    
1279                    return getReferenceDataElements(referenceElements, clazz);
1280            }
1281    
1282            @Override
1283            public Element getReferenceElement(
1284                    Element parentElement, Class<?> clazz, long groupId, String uuid,
1285                    String referenceType) {
1286    
1287                    List<Element> referenceElements = getReferenceElements(
1288                            parentElement, clazz, groupId, uuid, 0, referenceType);
1289    
1290                    if (!referenceElements.isEmpty()) {
1291                            return referenceElements.get(0);
1292                    }
1293    
1294                    return null;
1295            }
1296    
1297            @Override
1298            public Element getReferenceElement(
1299                    StagedModel parentStagedModel, Class<?> clazz, long classPK) {
1300    
1301                    List<Element> referenceElements = getReferenceElements(
1302                            parentStagedModel, clazz, classPK, null);
1303    
1304                    if (!referenceElements.isEmpty()) {
1305                            return referenceElements.get(0);
1306                    }
1307    
1308                    return null;
1309            }
1310    
1311            @Override
1312            public List<Element> getReferenceElements(
1313                    StagedModel parentStagedModel, Class<?> clazz) {
1314    
1315                    return getReferenceElements(parentStagedModel, clazz, 0, null);
1316            }
1317    
1318            @Override
1319            public String getRootPath() {
1320                    return ExportImportPathUtil.getRootPath(this);
1321            }
1322    
1323            /**
1324             * @deprecated As of 7.0.0
1325             */
1326            @Deprecated
1327            @Override
1328            public Set<String> getScopedPrimaryKeys() {
1329                    return _scopedPrimaryKeys;
1330            }
1331    
1332            @Override
1333            public long getScopeGroupId() {
1334                    return _scopeGroupId;
1335            }
1336    
1337            @Override
1338            public String getScopeLayoutUuid() {
1339                    return _scopeLayoutUuid;
1340            }
1341    
1342            @Override
1343            public String getScopeType() {
1344                    return _scopeType;
1345            }
1346    
1347            @Override
1348            public long getSourceCompanyGroupId() {
1349                    return _sourceCompanyGroupId;
1350            }
1351    
1352            @Override
1353            public long getSourceCompanyId() {
1354                    return _sourceCompanyId;
1355            }
1356    
1357            @Override
1358            public long getSourceGroupId() {
1359                    return _sourceGroupId;
1360            }
1361    
1362            @Override
1363            public String getSourceLayoutPath(long layoutId) {
1364                    return ExportImportPathUtil.getSourceLayoutPath(this, layoutId);
1365            }
1366    
1367            @Override
1368            public String getSourcePortletPath(String portletId) {
1369                    return ExportImportPathUtil.getSourcePortletPath(this, portletId);
1370            }
1371    
1372            @Override
1373            public String getSourceRootPath() {
1374                    return ExportImportPathUtil.getSourceRootPath(this);
1375            }
1376    
1377            @Override
1378            public long getSourceUserPersonalSiteGroupId() {
1379                    return _sourceUserPersonalSiteGroupId;
1380            }
1381    
1382            @Override
1383            public Date getStartDate() {
1384                    return _startDate;
1385            }
1386    
1387            @Override
1388            public long getUserId(String userUuid) {
1389                    return _userIdStrategy.getUserId(userUuid);
1390            }
1391    
1392            @Override
1393            public UserIdStrategy getUserIdStrategy() {
1394                    return _userIdStrategy;
1395            }
1396    
1397            @Override
1398            public long getUserPersonalSiteGroupId() {
1399                    return _userPersonalSiteGroupId;
1400            }
1401    
1402            /**
1403             * @deprecated As of 7.0.0
1404             */
1405            @Deprecated
1406            @Override
1407            public List<String> getZipEntries() {
1408                    return getZipReader().getEntries();
1409            }
1410    
1411            @Override
1412            public byte[] getZipEntryAsByteArray(String path) {
1413                    if (!Validator.isFilePath(path, false)) {
1414                            return null;
1415                    }
1416    
1417                    if (_portletDataContextListener != null) {
1418                            _portletDataContextListener.onGetZipEntry(path);
1419                    }
1420    
1421                    return getZipReader().getEntryAsByteArray(path);
1422            }
1423    
1424            @Override
1425            public InputStream getZipEntryAsInputStream(String path) {
1426                    if (!Validator.isFilePath(path, false)) {
1427                            return null;
1428                    }
1429    
1430                    if (_portletDataContextListener != null) {
1431                            _portletDataContextListener.onGetZipEntry(path);
1432                    }
1433    
1434                    return getZipReader().getEntryAsInputStream(path);
1435            }
1436    
1437            @Override
1438            public Object getZipEntryAsObject(Element element, String path) {
1439                    Object object = fromXML(getZipEntryAsString(path));
1440    
1441                    Attribute classNameAttribute = element.attribute("class-name");
1442    
1443                    if (classNameAttribute != null) {
1444                            BeanPropertiesUtil.setProperty(
1445                                    object, "className", classNameAttribute.getText());
1446                    }
1447    
1448                    return object;
1449            }
1450    
1451            @Override
1452            public Object getZipEntryAsObject(String path) {
1453                    return fromXML(getZipEntryAsString(path));
1454            }
1455    
1456            @Override
1457            public String getZipEntryAsString(String path) {
1458                    if (!Validator.isFilePath(path, false)) {
1459                            return null;
1460                    }
1461    
1462                    if (_portletDataContextListener != null) {
1463                            _portletDataContextListener.onGetZipEntry(path);
1464                    }
1465    
1466                    return getZipReader().getEntryAsString(path);
1467            }
1468    
1469            /**
1470             * @deprecated As of 7.0.0
1471             */
1472            @Deprecated
1473            @Override
1474            public List<String> getZipFolderEntries() {
1475                    return getZipFolderEntries(StringPool.SLASH);
1476            }
1477    
1478            @Override
1479            public List<String> getZipFolderEntries(String path) {
1480                    if (!Validator.isFilePath(path, false)) {
1481                            return null;
1482                    }
1483    
1484                    return getZipReader().getFolderEntries(path);
1485            }
1486    
1487            @Override
1488            public ZipReader getZipReader() {
1489                    return _zipReader;
1490            }
1491    
1492            @Override
1493            public ZipWriter getZipWriter() {
1494                    return _zipWriter;
1495            }
1496    
1497            @Override
1498            public boolean hasDateRange() {
1499                    if (_startDate != null) {
1500                            return true;
1501                    }
1502                    else {
1503                            return false;
1504                    }
1505            }
1506    
1507            @Override
1508            public boolean hasNotUniquePerLayout(String dataKey) {
1509                    return _notUniquePerLayout.contains(dataKey);
1510            }
1511    
1512            @Override
1513            public boolean hasPrimaryKey(Class<?> clazz, String primaryKey) {
1514                    return _primaryKeys.contains(getPrimaryKeyString(clazz, primaryKey));
1515            }
1516    
1517            @Override
1518            public boolean hasScopedPrimaryKey(Class<?> clazz, String primaryKey) {
1519                    return _scopedPrimaryKeys.contains(
1520                            getPrimaryKeyString(clazz, primaryKey));
1521            }
1522    
1523            @Override
1524            public void importClassedModel(
1525                            ClassedModel classedModel, ClassedModel newClassedModel)
1526                    throws PortalException, SystemException {
1527    
1528                    importClassedModel(
1529                            classedModel, newClassedModel, classedModel.getModelClass());
1530            }
1531    
1532            @Override
1533            public void importClassedModel(
1534                            ClassedModel classedModel, ClassedModel newClassedModel,
1535                            Class<?> clazz)
1536                    throws PortalException, SystemException {
1537    
1538                    if (!isResourceMain(classedModel)) {
1539                            return;
1540                    }
1541    
1542                    long classPK = getClassPK(classedModel);
1543    
1544                    long newClassPK = getClassPK(newClassedModel);
1545    
1546                    Map<Long, Long> newPrimaryKeysMap =
1547                            (Map<Long, Long>)getNewPrimaryKeysMap(clazz);
1548    
1549                    newPrimaryKeysMap.put(classPK, newClassPK);
1550    
1551                    importLocks(clazz, String.valueOf(classPK), String.valueOf(newClassPK));
1552                    importPermissions(clazz, classPK, newClassPK);
1553    
1554                    boolean portletDataAll = MapUtil.getBoolean(
1555                            getParameterMap(), PortletDataHandlerKeys.PORTLET_DATA_ALL);
1556    
1557                    if (portletDataAll ||
1558                            MapUtil.getBoolean(
1559                                    getParameterMap(), PortletDataHandlerKeys.COMMENTS)) {
1560    
1561                            importComments(clazz, classPK, newClassPK, getScopeGroupId());
1562                    }
1563    
1564                    if (portletDataAll ||
1565                            MapUtil.getBoolean(
1566                                    getParameterMap(), PortletDataHandlerKeys.RATINGS)) {
1567    
1568                            importRatingsEntries(clazz, classPK, newClassPK);
1569                    }
1570            }
1571    
1572            /**
1573             * @deprecated As of 6.2.0, replaced by {@link
1574             *             #importClassedModel(ClassedModel, ClassedModel, Class)}
1575             */
1576            @Override
1577            public void importClassedModel(
1578                            ClassedModel classedModel, ClassedModel newClassedModel,
1579                            Class<?> clazz, String namespace)
1580                    throws PortalException, SystemException {
1581    
1582                    importClassedModel(classedModel, newClassedModel, clazz);
1583            }
1584    
1585            /**
1586             * @deprecated As of 6.2.0, replaced by {@link
1587             *             #importClassedModel(ClassedModel, ClassedModel)}
1588             */
1589            @Override
1590            public void importClassedModel(
1591                            ClassedModel classedModel, ClassedModel newClassedModel,
1592                            String namespace)
1593                    throws PortalException, SystemException {
1594    
1595                    importClassedModel(
1596                            classedModel, newClassedModel, classedModel.getModelClass());
1597            }
1598    
1599            @Override
1600            public void importComments(
1601                            Class<?> clazz, long classPK, long newClassPK, long groupId)
1602                    throws PortalException, SystemException {
1603    
1604                    Map<Long, Long> messagePKs = new HashMap<Long, Long>();
1605                    Map<Long, Long> threadPKs = new HashMap<Long, Long>();
1606    
1607                    List<MBMessage> messages = _commentsMap.get(
1608                            getPrimaryKeyString(clazz, classPK));
1609    
1610                    if ((messages == null) || messages.isEmpty()) {
1611                            return;
1612                    }
1613    
1614                    MBMessage firstMessage = messages.get(0);
1615    
1616                    if ((messages.size() == 1) && firstMessage.isRoot()) {
1617                            return;
1618                    }
1619    
1620                    long classNameId = PortalUtil.getClassNameId(clazz);
1621    
1622                    MBDiscussion discussion = MBDiscussionUtil.fetchByC_C(
1623                            classNameId, newClassPK);
1624    
1625                    for (MBMessage message : messages) {
1626                            long userId = getUserId(message.getUserUuid());
1627                            long parentMessageId = MapUtil.getLong(
1628                                    messagePKs, message.getParentMessageId(),
1629                                    message.getParentMessageId());
1630                            long threadId = MapUtil.getLong(
1631                                    threadPKs, message.getThreadId(), message.getThreadId());
1632    
1633                            if (message.isRoot()) {
1634                                    if (discussion != null) {
1635                                            MBThread thread = MBThreadLocalServiceUtil.getThread(
1636                                                    discussion.getThreadId());
1637    
1638                                            long rootMessageId = thread.getRootMessageId();
1639    
1640                                            messagePKs.put(message.getMessageId(), rootMessageId);
1641                                            threadPKs.put(message.getThreadId(), thread.getThreadId());
1642                                    }
1643                                    else if (clazz == Layout.class) {
1644                                            MBMessage importedMessage =
1645                                                    MBMessageLocalServiceUtil.addDiscussionMessage(
1646                                                            userId, message.getUserName(), groupId,
1647                                                            clazz.getName(), newClassPK,
1648                                                            WorkflowConstants.ACTION_PUBLISH);
1649    
1650                                            messagePKs.put(
1651                                                    message.getMessageId(), importedMessage.getMessageId());
1652                                            threadPKs.put(
1653                                                    message.getThreadId(), importedMessage.getThreadId());
1654                                    }
1655                            }
1656                            else {
1657                                    ServiceContext serviceContext = new ServiceContext();
1658    
1659                                    serviceContext.setCreateDate(message.getCreateDate());
1660                                    serviceContext.setModifiedDate(message.getModifiedDate());
1661                                    serviceContext.setScopeGroupId(groupId);
1662    
1663                                    MBMessage importedMessage = null;
1664    
1665                                    if (_dataStrategy.equals(
1666                                                    PortletDataHandlerKeys.DATA_STRATEGY_MIRROR) ||
1667                                            _dataStrategy.equals(
1668                                                    PortletDataHandlerKeys.
1669                                                            DATA_STRATEGY_MIRROR_OVERWRITE)) {
1670    
1671                                            MBMessage existingMessage = MBMessageUtil.fetchByUUID_G(
1672                                                    message.getUuid(), groupId);
1673    
1674                                            if (existingMessage == null) {
1675                                                    serviceContext.setUuid(message.getUuid());
1676    
1677                                                    importedMessage =
1678                                                            MBMessageLocalServiceUtil.addDiscussionMessage(
1679                                                                    userId, message.getUserName(), groupId,
1680                                                                    clazz.getName(), newClassPK, threadId,
1681                                                                    parentMessageId, message.getSubject(),
1682                                                                    message.getBody(), serviceContext);
1683                                            }
1684                                            else {
1685                                                    serviceContext.setWorkflowAction(
1686                                                            WorkflowConstants.ACTION_PUBLISH);
1687    
1688                                                    importedMessage =
1689                                                            MBMessageLocalServiceUtil.updateDiscussionMessage(
1690                                                                    userId, existingMessage.getMessageId(),
1691                                                                    clazz.getName(), newClassPK,
1692                                                                    message.getSubject(), message.getBody(),
1693                                                                    serviceContext);
1694                                            }
1695                                    }
1696                                    else {
1697                                            importedMessage =
1698                                                    MBMessageLocalServiceUtil.addDiscussionMessage(
1699                                                            userId, message.getUserName(), groupId,
1700                                                            clazz.getName(), newClassPK, threadId,
1701                                                            parentMessageId, message.getSubject(),
1702                                                            message.getBody(), serviceContext);
1703                                    }
1704    
1705                                    messagePKs.put(
1706                                            message.getMessageId(), importedMessage.getMessageId());
1707                                    threadPKs.put(
1708                                            message.getThreadId(), importedMessage.getThreadId());
1709                            }
1710    
1711                            importRatingsEntries(
1712                                    MBDiscussion.class, message.getPrimaryKey(),
1713                                    messagePKs.get(message.getPrimaryKey()));
1714                    }
1715            }
1716    
1717            @Override
1718            public void importLocks(Class<?> clazz, String key, String newKey)
1719                    throws PortalException, SystemException {
1720    
1721                    Lock lock = _locksMap.get(getPrimaryKeyString(clazz, key));
1722    
1723                    if (lock == null) {
1724                            return;
1725                    }
1726    
1727                    long userId = getUserId(lock.getUserUuid());
1728    
1729                    long expirationTime = 0;
1730    
1731                    if (lock.getExpirationDate() != null) {
1732                            Date expirationDate = lock.getExpirationDate();
1733    
1734                            expirationTime = expirationDate.getTime();
1735                    }
1736    
1737                    LockLocalServiceUtil.lock(
1738                            userId, clazz.getName(), newKey, lock.getOwner(),
1739                            lock.isInheritable(), expirationTime);
1740            }
1741    
1742            @Override
1743            public void importPermissions(Class<?> clazz, long classPK, long newClassPK)
1744                    throws PortalException, SystemException {
1745    
1746                    importPermissions(clazz.getName(), classPK, newClassPK);
1747            }
1748    
1749            @Override
1750            public void importPermissions(
1751                            String resourceName, long resourcePK, long newResourcePK)
1752                    throws PortalException, SystemException {
1753    
1754                    if (!MapUtil.getBoolean(
1755                                    _parameterMap, PortletDataHandlerKeys.PERMISSIONS)) {
1756    
1757                            return;
1758                    }
1759    
1760                    List<KeyValuePair> permissions = _permissionsMap.get(
1761                            getPrimaryKeyString(resourceName, resourcePK));
1762    
1763                    if (permissions == null) {
1764                            return;
1765                    }
1766    
1767                    Map<Long, String[]> roleIdsToActionIds = new HashMap<Long, String[]>();
1768    
1769                    for (KeyValuePair permission : permissions) {
1770                            String roleName = permission.getKey();
1771    
1772                            Role role = null;
1773    
1774                            Team team = null;
1775    
1776                            if (roleName.startsWith(PermissionExporter.ROLE_TEAM_PREFIX)) {
1777                                    roleName = roleName.substring(
1778                                            PermissionExporter.ROLE_TEAM_PREFIX.length());
1779    
1780                                    try {
1781                                            team = TeamLocalServiceUtil.getTeam(_groupId, roleName);
1782                                    }
1783                                    catch (NoSuchTeamException nste) {
1784                                            if (_log.isWarnEnabled()) {
1785                                                    _log.warn("Team " + roleName + " does not exist");
1786                                            }
1787    
1788                                            continue;
1789                                    }
1790                            }
1791    
1792                            try {
1793                                    if (team != null) {
1794                                            role = RoleLocalServiceUtil.getTeamRole(
1795                                                    _companyId, team.getTeamId());
1796                                    }
1797                                    else {
1798                                            role = RoleLocalServiceUtil.getRole(_companyId, roleName);
1799                                    }
1800                            }
1801                            catch (NoSuchRoleException nsre) {
1802                                    if (_log.isWarnEnabled()) {
1803                                            _log.warn("Role " + roleName + " does not exist");
1804                                    }
1805    
1806                                    continue;
1807                            }
1808    
1809                            if (isPrivateLayout() &&
1810                                    resourceName.equals(Layout.class.getName()) &&
1811                                    roleName.equals(RoleConstants.GUEST)) {
1812    
1813                                    continue;
1814                            }
1815    
1816                            String[] actionIds = StringUtil.split(permission.getValue());
1817    
1818                            roleIdsToActionIds.put(role.getRoleId(), actionIds);
1819                    }
1820    
1821                    if (roleIdsToActionIds.isEmpty()) {
1822                            return;
1823                    }
1824    
1825                    if (ResourceBlockLocalServiceUtil.isSupported(resourceName)) {
1826                            ResourceBlockLocalServiceUtil.setIndividualScopePermissions(
1827                                    _companyId, _groupId, resourceName, newResourcePK,
1828                                    roleIdsToActionIds);
1829                    }
1830                    else {
1831                            ResourcePermissionLocalServiceUtil.setResourcePermissions(
1832                                    _companyId, resourceName, ResourceConstants.SCOPE_INDIVIDUAL,
1833                                    String.valueOf(newResourcePK), roleIdsToActionIds);
1834                    }
1835            }
1836    
1837            @Override
1838            public void importPortalPermissions()
1839                    throws PortalException, SystemException {
1840    
1841                    importPermissions(
1842                            PortletKeys.PORTAL, getSourceCompanyId(), getCompanyId());
1843            }
1844    
1845            @Override
1846            public void importPortletPermissions(String resourceName)
1847                    throws PortalException, SystemException {
1848    
1849                    importPermissions(resourceName, getSourceGroupId(), getScopeGroupId());
1850            }
1851    
1852            @Override
1853            public void importRatingsEntries(
1854                            Class<?> clazz, long classPK, long newClassPK)
1855                    throws PortalException, SystemException {
1856    
1857                    List<RatingsEntry> ratingsEntries = _ratingsEntriesMap.get(
1858                            getPrimaryKeyString(clazz, classPK));
1859    
1860                    if ((ratingsEntries == null) || ratingsEntries.isEmpty()) {
1861                            return;
1862                    }
1863    
1864                    ServiceContext serviceContext = new ServiceContext();
1865    
1866                    for (RatingsEntry ratingsEntry : ratingsEntries) {
1867                            long userId = getUserId(ratingsEntry.getUserUuid());
1868    
1869                            serviceContext.setCreateDate(ratingsEntry.getCreateDate());
1870                            serviceContext.setModifiedDate(ratingsEntry.getModifiedDate());
1871    
1872                            RatingsEntryLocalServiceUtil.updateEntry(
1873                                    userId, clazz.getName(), newClassPK, ratingsEntry.getScore(),
1874                                    serviceContext);
1875                    }
1876            }
1877    
1878            @Override
1879            public boolean isCompanyStagedGroupedModel(
1880                    StagedGroupedModel stagedGroupedModel) {
1881    
1882                    if ((stagedGroupedModel.getGroupId() == getCompanyGroupId()) &&
1883                            (getGroupId() != getCompanyGroupId())) {
1884    
1885                            return true;
1886                    }
1887    
1888                    return false;
1889            }
1890    
1891            @Override
1892            public boolean isDataStrategyMirror() {
1893                    if (_dataStrategy.equals(PortletDataHandlerKeys.DATA_STRATEGY_MIRROR) ||
1894                            _dataStrategy.equals(
1895                                    PortletDataHandlerKeys.DATA_STRATEGY_MIRROR_OVERWRITE)) {
1896    
1897                            return true;
1898                    }
1899                    else {
1900                            return false;
1901                    }
1902            }
1903    
1904            @Override
1905            public boolean isDataStrategyMirrorWithOverwriting() {
1906                    if (_dataStrategy.equals(
1907                                    PortletDataHandlerKeys.DATA_STRATEGY_MIRROR_OVERWRITE)) {
1908    
1909                            return true;
1910                    }
1911                    else {
1912                            return false;
1913                    }
1914            }
1915    
1916            @Override
1917            public boolean isInitialPublication() {
1918                    Group group = null;
1919    
1920                    try {
1921                            group = GroupLocalServiceUtil.getGroup(getGroupId());
1922                    }
1923                    catch (Exception e) {
1924                    }
1925    
1926                    if (ExportImportThreadLocal.isStagingInProcess() && (group != null) &&
1927                            group.hasStagingGroup()) {
1928    
1929                            return true;
1930                    }
1931    
1932                    return false;
1933            }
1934    
1935            @Override
1936            public boolean isMissingReference(Element referenceElement) {
1937                    Attribute missingAttribute = referenceElement.attribute("missing");
1938    
1939                    if ((missingAttribute != null) &&
1940                            !GetterUtil.getBoolean(
1941                                    referenceElement.attributeValue("missing"))) {
1942    
1943                            return false;
1944                    }
1945    
1946                    if (_missingReferences.isEmpty()) {
1947                            List<Element> missingReferenceElements =
1948                                    _missingReferencesElement.elements();
1949    
1950                            for (Element missingReferenceElement : missingReferenceElements) {
1951                                    String missingReferenceClassName =
1952                                            missingReferenceElement.attributeValue("class-name");
1953                                    String missingReferenceClassPK =
1954                                            missingReferenceElement.attributeValue("class-pk");
1955    
1956                                    String missingReferenceKey = getReferenceKey(
1957                                            missingReferenceClassName, missingReferenceClassPK);
1958    
1959                                    _missingReferences.add(missingReferenceKey);
1960                            }
1961                    }
1962    
1963                    String className = referenceElement.attributeValue("class-name");
1964                    String classPK = referenceElement.attributeValue("class-pk");
1965    
1966                    String referenceKey = getReferenceKey(className, classPK);
1967    
1968                    return _missingReferences.contains(referenceKey);
1969            }
1970    
1971            @Override
1972            public boolean isModelCounted(String className, long classPK) {
1973                    String modelCountedPrimaryKey = className.concat(
1974                            StringPool.POUND).concat(String.valueOf(classPK));
1975    
1976                    return addPrimaryKey(String.class, modelCountedPrimaryKey);
1977            }
1978    
1979            @Override
1980            public boolean isPathExportedInScope(String path) {
1981                    return addScopedPrimaryKey(String.class, path);
1982            }
1983    
1984            /**
1985             * @deprecated As of 7.0.0
1986             */
1987            @Deprecated
1988            @Override
1989            public boolean isPathNotExportedInScope(String path) {
1990                    return !isPathExportedInScope(path);
1991            }
1992    
1993            @Override
1994            public boolean isPathNotProcessed(String path) {
1995                    return !isPathProcessed(path);
1996            }
1997    
1998            @Override
1999            public boolean isPathProcessed(String path) {
2000                    addScopedPrimaryKey(String.class, path);
2001    
2002                    return addPrimaryKey(String.class, path);
2003            }
2004    
2005            @Override
2006            public boolean isPerformDirectBinaryImport() {
2007                    return MapUtil.getBoolean(
2008                            _parameterMap, PortletDataHandlerKeys.PERFORM_DIRECT_BINARY_IMPORT);
2009            }
2010    
2011            @Override
2012            public boolean isPrivateLayout() {
2013                    return _privateLayout;
2014            }
2015    
2016            @Override
2017            public boolean isStagedModelCounted(StagedModel stagedModel) {
2018                    StagedModelType stagedModelType = stagedModel.getStagedModelType();
2019    
2020                    return isModelCounted(
2021                            stagedModelType.getClassName(),
2022                            (Long)stagedModel.getPrimaryKeyObj());
2023            }
2024    
2025            /**
2026             * @see #addDateRangeCriteria(DynamicQuery, String)
2027             */
2028            @Override
2029            public boolean isWithinDateRange(Date modifiedDate) {
2030                    if (!hasDateRange()) {
2031                            return true;
2032                    }
2033                    else if ((_startDate.compareTo(modifiedDate) <= 0) &&
2034                                     _endDate.after(modifiedDate)) {
2035    
2036                            return true;
2037                    }
2038                    else {
2039                            return false;
2040                    }
2041            }
2042    
2043            @Override
2044            public void putNotUniquePerLayout(String dataKey) {
2045                    _notUniquePerLayout.add(dataKey);
2046            }
2047    
2048            @Override
2049            public void setClassLoader(ClassLoader classLoader) {
2050                    _xStream.setClassLoader(classLoader);
2051            }
2052    
2053            @Override
2054            public void setCompanyGroupId(long companyGroupId) {
2055                    _companyGroupId = companyGroupId;
2056            }
2057    
2058            @Override
2059            public void setCompanyId(long companyId) {
2060                    _companyId = companyId;
2061            }
2062    
2063            @Override
2064            public void setDataStrategy(String dataStrategy) {
2065                    _dataStrategy = dataStrategy;
2066            }
2067    
2068            @Override
2069            public void setDeletionKeysMap(Map<String, List<String>> deletionKeysMap) {
2070                    _deletionKeysMap = deletionKeysMap;
2071            }
2072    
2073            @Override
2074            public void setEndDate(Date endDate) {
2075                    _endDate = endDate;
2076            }
2077    
2078            @Override
2079            public void setExportDataRootElement(Element exportDataRootElement) {
2080                    _exportDataRootElement = exportDataRootElement;
2081            }
2082    
2083            @Override
2084            public void setGroupId(long groupId) {
2085                    _groupId = groupId;
2086            }
2087    
2088            @Override
2089            public void setImportDataRootElement(Element importDataRootElement) {
2090                    _importDataRootElement = importDataRootElement;
2091            }
2092    
2093            @Override
2094            public void setManifestSummary(ManifestSummary manifestSummary) {
2095                    _manifestSummary = manifestSummary;
2096            }
2097    
2098            @Override
2099            public void setMissingReferencesElement(Element missingReferencesElement) {
2100                    _missingReferencesElement = missingReferencesElement;
2101            }
2102    
2103            @Override
2104            public void setNewLayouts(List<Layout> newLayouts) {
2105                    _newLayouts = newLayouts;
2106            }
2107    
2108            @Override
2109            public void setNewPrimaryKeysMaps(
2110                    Map<String, Map<?, ?>> newPrimaryKeysMaps) {
2111    
2112                    _newPrimaryKeysMaps = newPrimaryKeysMaps;
2113            }
2114    
2115            @Override
2116            public void setOldPlid(long oldPlid) {
2117                    _oldPlid = oldPlid;
2118            }
2119    
2120            @Override
2121            public void setParameterMap(Map<String, String[]> parameterMap) {
2122                    _parameterMap = parameterMap;
2123            }
2124    
2125            @Override
2126            public void setPlid(long plid) {
2127                    _plid = plid;
2128            }
2129    
2130            @Override
2131            public void setPortetDataContextListener(
2132                    PortletDataContextListener portletDataContextListener) {
2133    
2134                    _portletDataContextListener = portletDataContextListener;
2135            }
2136    
2137            @Override
2138            public void setPrivateLayout(boolean privateLayout) {
2139                    _privateLayout = privateLayout;
2140            }
2141    
2142            @Override
2143            public void setRootPortletId(String rootPortletId) {
2144                    _rootPortletId = rootPortletId;
2145            }
2146    
2147            @Override
2148            public void setScopeGroupId(long scopeGroupId) {
2149                    _scopeGroupId = scopeGroupId;
2150            }
2151    
2152            @Override
2153            public void setScopeLayoutUuid(String scopeLayoutUuid) {
2154                    _scopeLayoutUuid = scopeLayoutUuid;
2155            }
2156    
2157            @Override
2158            public void setScopeType(String scopeType) {
2159                    _scopeType = scopeType;
2160            }
2161    
2162            @Override
2163            public void setSourceCompanyGroupId(long sourceCompanyGroupId) {
2164                    _sourceCompanyGroupId = sourceCompanyGroupId;
2165            }
2166    
2167            @Override
2168            public void setSourceCompanyId(long sourceCompanyId) {
2169                    _sourceCompanyId = sourceCompanyId;
2170            }
2171    
2172            @Override
2173            public void setSourceGroupId(long sourceGroupId) {
2174                    _sourceGroupId = sourceGroupId;
2175            }
2176    
2177            @Override
2178            public void setSourceUserPersonalSiteGroupId(
2179                    long sourceUserPersonalSiteGroupId) {
2180    
2181                    _sourceUserPersonalSiteGroupId = sourceUserPersonalSiteGroupId;
2182            }
2183    
2184            @Override
2185            public void setStartDate(Date startDate) {
2186                    _startDate = startDate;
2187            }
2188    
2189            @Override
2190            public void setUserIdStrategy(UserIdStrategy userIdStrategy) {
2191                    _userIdStrategy = userIdStrategy;
2192            }
2193    
2194            @Override
2195            public void setUserPersonalSiteGroupId(long userPersonalSiteGroupId) {
2196                    _userPersonalSiteGroupId = userPersonalSiteGroupId;
2197            }
2198    
2199            @Override
2200            public void setZipReader(ZipReader zipReader) {
2201                    _zipReader = zipReader;
2202            }
2203    
2204            @Override
2205            public void setZipWriter(ZipWriter zipWriter) {
2206                    _zipWriter = zipWriter;
2207            }
2208    
2209            @Override
2210            public String toXML(Object object) {
2211                    return _xStream.toXML(object);
2212            }
2213    
2214            protected void addExpando(
2215                            Element element, String path, ClassedModel classedModel,
2216                            Class<?> clazz)
2217                    throws PortalException, SystemException {
2218    
2219                    String className = clazz.getName();
2220    
2221                    if (!_expandoColumnsMap.containsKey(className)) {
2222                            List<ExpandoColumn> expandoColumns =
2223                                    ExpandoColumnLocalServiceUtil.getDefaultTableColumns(
2224                                            _companyId, className);
2225    
2226                            for (ExpandoColumn expandoColumn : expandoColumns) {
2227                                    addPermissions(
2228                                            ExpandoColumn.class, expandoColumn.getColumnId());
2229                            }
2230    
2231                            _expandoColumnsMap.put(className, expandoColumns);
2232                    }
2233    
2234                    ExpandoBridge expandoBridge = classedModel.getExpandoBridge();
2235    
2236                    Map<String, Serializable> expandoBridgeAttributes =
2237                            expandoBridge.getAttributes();
2238    
2239                    if (!expandoBridgeAttributes.isEmpty()) {
2240                            String expandoPath = ExportImportPathUtil.getExpandoPath(path);
2241    
2242                            element.addAttribute("expando-path", expandoPath);
2243    
2244                            addZipEntry(expandoPath, expandoBridgeAttributes);
2245                    }
2246            }
2247    
2248            protected ServiceContext createServiceContext(
2249                    Element element, String path, ClassedModel classedModel,
2250                    Class<?> clazz) {
2251    
2252                    long classPK = getClassPK(classedModel);
2253    
2254                    ServiceContext serviceContext = new ServiceContext();
2255    
2256                    // Theme display
2257    
2258                    serviceContext.setCompanyId(getCompanyId());
2259                    serviceContext.setScopeGroupId(getScopeGroupId());
2260    
2261                    // Dates
2262    
2263                    if (classedModel instanceof AuditedModel) {
2264                            AuditedModel auditedModel = (AuditedModel)classedModel;
2265    
2266                            serviceContext.setUserId(getUserId(auditedModel));
2267                            serviceContext.setCreateDate(auditedModel.getCreateDate());
2268                            serviceContext.setModifiedDate(auditedModel.getModifiedDate());
2269                    }
2270    
2271                    // Permissions
2272    
2273                    if (!MapUtil.getBoolean(
2274                                    _parameterMap, PortletDataHandlerKeys.PERMISSIONS)) {
2275    
2276                            serviceContext.setAddGroupPermissions(true);
2277                            serviceContext.setAddGuestPermissions(true);
2278                    }
2279    
2280                    // Asset
2281    
2282                    if (isResourceMain(classedModel)) {
2283                            long[] assetCategoryIds = getAssetCategoryIds(clazz, classPK);
2284    
2285                            serviceContext.setAssetCategoryIds(assetCategoryIds);
2286    
2287                            String[] assetTagNames = getAssetTagNames(clazz, classPK);
2288    
2289                            serviceContext.setAssetTagNames(assetTagNames);
2290    
2291                            if (ExportImportThreadLocal.isStagingInProcess()) {
2292                                    serviceContext.setAssetLinkEntryIds(new long[0]);
2293                            }
2294                    }
2295    
2296                    // Expando
2297    
2298                    String expandoPath = null;
2299    
2300                    if (element != null) {
2301                            expandoPath = element.attributeValue("expando-path");
2302                    }
2303                    else {
2304                            expandoPath = ExportImportPathUtil.getExpandoPath(path);
2305                    }
2306    
2307                    if (Validator.isNotNull(expandoPath)) {
2308                            try {
2309                                    Map<String, Serializable> expandoBridgeAttributes =
2310                                            (Map<String, Serializable>)getZipEntryAsObject(expandoPath);
2311    
2312                                    if (expandoBridgeAttributes != null) {
2313                                            serviceContext.setExpandoBridgeAttributes(
2314                                                    expandoBridgeAttributes);
2315                                    }
2316                            }
2317                            catch (Exception e) {
2318                                    if (_log.isDebugEnabled()) {
2319                                            _log.debug(e, e);
2320                                    }
2321                            }
2322                    }
2323    
2324                    return serviceContext;
2325            }
2326    
2327            protected Element doAddReferenceElement(
2328                    ClassedModel referrerClassedModel, Element element,
2329                    ClassedModel classedModel, String className, String binPath,
2330                    String referenceType, boolean missing) {
2331    
2332                    Element referenceElement = null;
2333    
2334                    if (missing) {
2335                            Element referencesElement = _missingReferencesElement;
2336    
2337                            referenceElement = referencesElement.addElement(
2338                                    "missing-reference");
2339                    }
2340                    else {
2341                            Element referencesElement = element.element("references");
2342    
2343                            if (referencesElement == null) {
2344                                    referencesElement = element.addElement("references");
2345                            }
2346    
2347                            referenceElement = referencesElement.addElement("reference");
2348                    }
2349    
2350                    referenceElement.addAttribute("class-name", className);
2351    
2352                    referenceElement.addAttribute(
2353                            "class-pk", String.valueOf(classedModel.getPrimaryKeyObj()));
2354    
2355                    if (missing) {
2356                            if (classedModel instanceof StagedModel) {
2357                                    referenceElement.addAttribute(
2358                                            "display-name",
2359                                            StagedModelDataHandlerUtil.getDisplayName(
2360                                                    (StagedModel)classedModel));
2361                            }
2362                            else {
2363                                    referenceElement.addAttribute(
2364                                            "display-name",
2365                                            String.valueOf(classedModel.getPrimaryKeyObj()));
2366                            }
2367                    }
2368    
2369                    if (classedModel instanceof StagedGroupedModel) {
2370                            StagedGroupedModel stagedGroupedModel =
2371                                    (StagedGroupedModel)classedModel;
2372    
2373                            referenceElement.addAttribute(
2374                                    "group-id", String.valueOf(stagedGroupedModel.getGroupId()));
2375                    }
2376    
2377                    if (Validator.isNotNull(binPath)) {
2378                            referenceElement.addAttribute("path", binPath);
2379                    }
2380    
2381                    referenceElement.addAttribute("type", referenceType);
2382    
2383                    if (missing) {
2384                            referenceElement.addAttribute(
2385                                    "referrer-class-name",
2386                                    ExportImportClassedModelUtil.getClassName(
2387                                            referrerClassedModel));
2388    
2389                            if (referrerClassedModel instanceof PortletModel) {
2390                                    Portlet portlet = (Portlet)referrerClassedModel;
2391    
2392                                    referenceElement.addAttribute(
2393                                            "referrer-display-name", portlet.getRootPortletId());
2394                            }
2395                            else if (referrerClassedModel instanceof StagedModel) {
2396                                    StagedModel referrerStagedModel =
2397                                            (StagedModel)referrerClassedModel;
2398    
2399                                    referenceElement.addAttribute(
2400                                            "referrer-display-name",
2401                                            StagedModelDataHandlerUtil.getDisplayName(
2402                                                    referrerStagedModel));
2403                            }
2404                    }
2405    
2406                    if (classedModel instanceof StagedModel) {
2407                            StagedModel stagedModel = (StagedModel)classedModel;
2408    
2409                            referenceElement.addAttribute("uuid", stagedModel.getUuid());
2410                            referenceElement.addAttribute(
2411                                    "company-id", String.valueOf(stagedModel.getCompanyId()));
2412    
2413                            Map<String, String> referenceAttributes =
2414                                    StagedModelDataHandlerUtil.getReferenceAttributes(
2415                                            this, stagedModel);
2416    
2417                            for (Map.Entry<String, String> referenceAttribute :
2418                                            referenceAttributes.entrySet()) {
2419    
2420                                    referenceElement.addAttribute(
2421                                            referenceAttribute.getKey(), referenceAttribute.getValue());
2422                            }
2423                    }
2424    
2425                    return referenceElement;
2426            }
2427    
2428            protected Map<Long, Set<String>> getActionIds(
2429                            long companyId, long[] roleIds, String className, long primKey,
2430                            List<String> actionIds)
2431                    throws PortalException, SystemException {
2432    
2433                    if (ResourceBlockLocalServiceUtil.isSupported(className)) {
2434                            return ResourceBlockPermissionLocalServiceUtil.
2435                                    getAvailableResourceBlockPermissionActionIds(
2436                                            roleIds, className, primKey, actionIds);
2437                    }
2438                    else {
2439                            return ResourcePermissionLocalServiceUtil.
2440                                    getAvailableResourcePermissionActionIds(
2441                                            companyId, className, ResourceConstants.SCOPE_INDIVIDUAL,
2442                                            String.valueOf(primKey), roleIds, actionIds);
2443                    }
2444            }
2445    
2446            protected long getClassPK(ClassedModel classedModel) {
2447                    if (classedModel instanceof ResourcedModel) {
2448                            ResourcedModel resourcedModel = (ResourcedModel)classedModel;
2449    
2450                            return resourcedModel.getResourcePrimKey();
2451                    }
2452                    else {
2453                            return (Long)classedModel.getPrimaryKeyObj();
2454                    }
2455            }
2456    
2457            protected Element getDataElement(
2458                    Element parentElement, String attribute, String value) {
2459    
2460                    if (parentElement == null) {
2461                            return null;
2462                    }
2463    
2464                    StringBundler sb = new StringBundler(6);
2465    
2466                    sb.append("staged-model");
2467                    sb.append("[@");
2468                    sb.append(attribute);
2469                    sb.append(StringPool.EQUAL);
2470                    sb.append(HtmlUtil.escapeXPathAttribute(value));
2471                    sb.append(StringPool.CLOSE_BRACKET);
2472    
2473                    XPath xPath = SAXReaderUtil.createXPath(sb.toString());
2474    
2475                    return (Element)xPath.selectSingleNode(parentElement);
2476            }
2477    
2478            protected String getExpandoPath(String path) {
2479                    return ExportImportPathUtil.getExpandoPath(path);
2480            }
2481    
2482            protected Element getExportDataGroupElement(String name) {
2483                    if (_exportDataRootElement == null) {
2484                            throw new IllegalStateException(
2485                                    "Root data element not initialized");
2486                    }
2487    
2488                    Element groupElement = _exportDataRootElement.element(name);
2489    
2490                    if (groupElement == null) {
2491                            groupElement = _exportDataRootElement.addElement(name);
2492                    }
2493    
2494                    return groupElement;
2495            }
2496    
2497            protected Element getImportDataGroupElement(String name) {
2498                    if (_importDataRootElement == null) {
2499                            throw new IllegalStateException(
2500                                    "Root data element not initialized");
2501                    }
2502    
2503                    if (Validator.isNull(name)) {
2504                            return SAXReaderUtil.createElement("EMPTY-ELEMENT");
2505                    }
2506    
2507                    Element groupElement = _importDataRootElement.element(name);
2508    
2509                    if (groupElement == null) {
2510                            return SAXReaderUtil.createElement("EMPTY-ELEMENT");
2511                    }
2512    
2513                    return groupElement;
2514            }
2515    
2516            protected Element getMissingReferenceElement(ClassedModel classedModel) {
2517                    StringBundler sb = new StringBundler(5);
2518    
2519                    sb.append("missing-reference[@class-name='");
2520                    sb.append(ExportImportClassedModelUtil.getClassName(classedModel));
2521                    sb.append("' and @class-pk='");
2522                    sb.append(String.valueOf(classedModel.getPrimaryKeyObj()));
2523                    sb.append("']");
2524    
2525                    XPath xPath = SAXReaderUtil.createXPath(sb.toString());
2526    
2527                    Node node = xPath.selectSingleNode(_missingReferencesElement);
2528    
2529                    return (Element)node;
2530            }
2531    
2532            protected String getPrimaryKeyString(Class<?> clazz, long classPK) {
2533                    return getPrimaryKeyString(clazz.getName(), String.valueOf(classPK));
2534            }
2535    
2536            protected String getPrimaryKeyString(Class<?> clazz, String primaryKey) {
2537                    return getPrimaryKeyString(clazz.getName(), primaryKey);
2538            }
2539    
2540            protected String getPrimaryKeyString(String className, long classPK) {
2541                    return getPrimaryKeyString(className, String.valueOf(classPK));
2542            }
2543    
2544            protected String getPrimaryKeyString(String className, String primaryKey) {
2545                    return className.concat(StringPool.POUND).concat(primaryKey);
2546            }
2547    
2548            protected List<Element> getReferenceDataElements(
2549                    List<Element> referenceElements, Class<?> clazz) {
2550    
2551                    List<Element> referenceDataElements = new ArrayList<Element>();
2552    
2553                    for (Element referenceElement : referenceElements) {
2554                            Element referenceDataElement = null;
2555    
2556                            String path = referenceElement.attributeValue("path");
2557    
2558                            if (Validator.isNotNull(path)) {
2559                                    referenceDataElement = getImportDataElement(
2560                                            clazz.getSimpleName(), "path", path);
2561                            }
2562                            else {
2563                                    String groupId = referenceElement.attributeValue("group-id");
2564                                    String uuid = referenceElement.attributeValue("uuid");
2565    
2566                                    StringBuilder sb = new StringBuilder(5);
2567    
2568                                    sb.append("staged-model[@uuid=");
2569                                    sb.append(HtmlUtil.escapeXPathAttribute(uuid));
2570    
2571                                    if (groupId != null) {
2572                                            sb.append(" and @group-id=");
2573                                            sb.append(HtmlUtil.escapeXPathAttribute(groupId));
2574                                    }
2575    
2576                                    sb.append(StringPool.CLOSE_BRACKET);
2577    
2578                                    XPath xPath = SAXReaderUtil.createXPath(sb.toString());
2579    
2580                                    Element groupElement = getImportDataGroupElement(
2581                                            clazz.getSimpleName());
2582    
2583                                    referenceDataElement = (Element)xPath.selectSingleNode(
2584                                            groupElement);
2585                            }
2586    
2587                            if (referenceDataElement == null) {
2588                                    continue;
2589                            }
2590    
2591                            referenceDataElements.add(referenceDataElement);
2592                    }
2593    
2594                    return referenceDataElements;
2595            }
2596    
2597            protected List<Element> getReferenceElements(
2598                    Element parentElement, Class<?> clazz, long groupId, String uuid,
2599                    long classPK, String referenceType) {
2600    
2601                    if (parentElement == null) {
2602                            return Collections.emptyList();
2603                    }
2604    
2605                    Element referencesElement = parentElement.element("references");
2606    
2607                    if (referencesElement == null) {
2608                            return Collections.emptyList();
2609                    }
2610    
2611                    StringBundler sb = new StringBundler(13);
2612    
2613                    sb.append("reference[@class-name=");
2614                    sb.append(HtmlUtil.escapeXPathAttribute(clazz.getName()));
2615    
2616                    if (groupId > 0) {
2617                            sb.append(" and @group-id='");
2618                            sb.append(groupId);
2619                            sb.append(StringPool.APOSTROPHE);
2620                    }
2621    
2622                    if (Validator.isNotNull(uuid)) {
2623                            sb.append(" and @uuid=");
2624                            sb.append(HtmlUtil.escapeXPathAttribute(uuid));
2625                    }
2626    
2627                    if (classPK > 0) {
2628                            sb.append(" and @class-pk='");
2629                            sb.append(classPK);
2630                            sb.append(StringPool.APOSTROPHE);
2631                    }
2632    
2633                    if (referenceType != null) {
2634                            sb.append(" and @type=");
2635                            sb.append(HtmlUtil.escapeXPathAttribute(referenceType));
2636                    }
2637    
2638                    sb.append(StringPool.CLOSE_BRACKET);
2639    
2640                    XPath xPath = SAXReaderUtil.createXPath(sb.toString());
2641    
2642                    List<Node> nodes = xPath.selectNodes(referencesElement);
2643    
2644                    return ListUtil.fromArray(nodes.toArray(new Element[nodes.size()]));
2645            }
2646    
2647            protected List<Element> getReferenceElements(
2648                    StagedModel parentStagedModel, Class<?> clazz, long classPK,
2649                    String referenceType) {
2650    
2651                    Element stagedModelElement = getImportDataStagedModelElement(
2652                            parentStagedModel);
2653    
2654                    return getReferenceElements(
2655                            stagedModelElement, clazz, 0, null, classPK, referenceType);
2656            }
2657    
2658            protected String getReferenceKey(ClassedModel classedModel) {
2659                    return getReferenceKey(
2660                            ExportImportClassedModelUtil.getClassName(classedModel),
2661                            String.valueOf(classedModel.getPrimaryKeyObj()));
2662            }
2663    
2664            protected String getReferenceKey(String className, String classPK) {
2665                    return className.concat(StringPool.POUND).concat(classPK);
2666            }
2667    
2668            protected long getUserId(AuditedModel auditedModel) {
2669                    try {
2670                            String userUuid = auditedModel.getUserUuid();
2671    
2672                            return getUserId(userUuid);
2673                    }
2674                    catch (SystemException se) {
2675                            if (_log.isErrorEnabled()) {
2676                                    _log.error(se, se);
2677                            }
2678                    }
2679    
2680                    return 0;
2681            }
2682    
2683            protected void initXStream() {
2684                    _xStream = new XStream();
2685    
2686                    // Aliases
2687    
2688                    _xStream.alias("BlogsEntry", BlogsEntryImpl.class);
2689                    _xStream.alias("BookmarksFolder", BookmarksFolderImpl.class);
2690                    _xStream.alias("BookmarksEntry", BookmarksEntryImpl.class);
2691                    _xStream.alias("DLFolder", DLFolderImpl.class);
2692                    _xStream.alias("DLFileEntry", DLFileEntryImpl.class);
2693                    _xStream.alias("DLFileShortcut", DLFileShortcutImpl.class);
2694                    _xStream.alias("JournalArticle", JournalArticleImpl.class);
2695                    _xStream.alias("JournalFeed", JournalFeedImpl.class);
2696                    _xStream.alias("Lock", LockImpl.class);
2697                    _xStream.alias("MBBan", MBBanImpl.class);
2698                    _xStream.alias("MBCategory", MBCategoryImpl.class);
2699                    _xStream.alias("MBMessage", MBMessageImpl.class);
2700                    _xStream.alias("MBThreadFlag", MBThreadFlagImpl.class);
2701                    _xStream.alias("PollsQuestion", PollsQuestionImpl.class);
2702                    _xStream.alias("PollsChoice", PollsChoiceImpl.class);
2703                    _xStream.alias("PollsVote", PollsVoteImpl.class);
2704                    _xStream.alias("RatingsEntry", RatingsEntryImpl.class);
2705                    _xStream.alias("WikiNode", WikiNodeImpl.class);
2706                    _xStream.alias("WikiPage", WikiPageImpl.class);
2707    
2708                    // Omit fields
2709    
2710                    _xStream.omitField(HashMap.class, "cache_bitmask");
2711    
2712                    // Register converters
2713    
2714                    _xStream.registerConverter(
2715                            new FolderConverter(), XStream.PRIORITY_VERY_HIGH);
2716                    _xStream.registerConverter(
2717                            new FileEntryConverter(), XStream.PRIORITY_VERY_HIGH);
2718                    _xStream.registerConverter(
2719                            new FileVersionConverter(), XStream.PRIORITY_VERY_HIGH);
2720    
2721                    if (!PropsValues.STAGING_XSTREAM_SECURITY_ENABLED) {
2722                            return;
2723                    }
2724    
2725                    // Permissions
2726    
2727                    // Wipe all of them
2728    
2729                    _xStream.addPermission(NoTypePermission.NONE);
2730    
2731                    // Add permissions
2732    
2733                    _xStream.addPermission(PrimitiveTypePermission.PRIMITIVES);
2734    
2735                    List<String> allowedTypes = new ArrayList<String>();
2736    
2737                    allowedTypes.addAll(
2738                            ListUtil.toList(_XSTREAM_DEFAULT_ALLOWED_CLASS_NAMES));
2739                    allowedTypes.addAll(
2740                            ListUtil.toList(PropsValues.STAGING_XSTREAM_CLASS_WHITELIST));
2741    
2742                    _xStream.allowTypes(allowedTypes.toArray(new String[0]));
2743    
2744                    _xStream.allowTypeHierarchy(AssetLink.class);
2745                    _xStream.allowTypeHierarchy(AssetTag.class);
2746                    _xStream.allowTypeHierarchy(List.class);
2747                    _xStream.allowTypeHierarchy(Lock.class);
2748                    _xStream.allowTypeHierarchy(Map.class);
2749                    _xStream.allowTypeHierarchy(OrgLabor.class);
2750                    _xStream.allowTypeHierarchy(RatingsEntry.class);
2751                    _xStream.allowTypeHierarchy(StagedModel.class);
2752    
2753                    _xStream.allowTypesByWildcard(
2754                            new String[] {
2755                                    "com.liferay.portal.model.*", "com.liferay.portal.model.impl.*",
2756                                    "com.thoughtworks.xstream.mapper.DynamicProxyMapper*"
2757                            }
2758                    );
2759            }
2760    
2761            protected boolean isResourceMain(ClassedModel classedModel) {
2762                    if (classedModel instanceof ResourcedModel) {
2763                            ResourcedModel resourcedModel = (ResourcedModel)classedModel;
2764    
2765                            return resourcedModel.isResourceMain();
2766                    }
2767    
2768                    return true;
2769            }
2770    
2771            protected void updateAssetCategoriesPrimaryKeyString(
2772                    Class<?> clazz, ClassedModel classedModel) {
2773    
2774                    long classPK = getClassPK(classedModel);
2775    
2776                    String primaryKeyString = getPrimaryKeyString(clazz, classPK);
2777    
2778                    long primaryKey = (Long)classedModel.getPrimaryKeyObj();
2779    
2780                    String updatedPrimaryKeyString = getPrimaryKeyString(
2781                            primaryKeyString, primaryKey);
2782    
2783                    String[] uuids = _assetCategoryUuidsMap.remove(primaryKeyString);
2784    
2785                    _assetCategoryUuidsMap.put(updatedPrimaryKeyString, uuids);
2786            }
2787    
2788            private static final String[] _XSTREAM_DEFAULT_ALLOWED_CLASS_NAMES =
2789                    new String[] {
2790                            BigDecimal.class.getName(), boolean[].class.getName(),
2791                            byte[].class.getName(), Date.class.getName(),
2792                            double[].class.getName(), Field.class.getName(),
2793                            Fields.class.getName(), float[].class.getName(),
2794                            InputStream.class.getName(), int[].class.getName(),
2795                            Locale.class.getName(), long[].class.getName(),
2796                            Number.class.getName(), Number[].class.getName(),
2797                            String.class.getName(), String[].class.getName(),
2798                            short[].class.getName(), Time.class.getName(),
2799                            Timestamp.class.getName()
2800                    };
2801    
2802            private static Log _log = LogFactoryUtil.getLog(
2803                    PortletDataContextImpl.class);
2804    
2805            private Map<String, long[]> _assetCategoryIdsMap =
2806                    new HashMap<String, long[]>();
2807            private Map<String, String[]> _assetCategoryUuidsMap =
2808                    new HashMap<String, String[]>();
2809            private Map<String, List<AssetLink>> _assetLinksMap =
2810                    new HashMap<String, List<AssetLink>>();
2811            private Map<String, String[]> _assetTagNamesMap =
2812                    new HashMap<String, String[]>();
2813            private Map<String, List<MBMessage>> _commentsMap =
2814                    new HashMap<String, List<MBMessage>>();
2815            private long _companyGroupId;
2816            private long _companyId;
2817            private String _dataStrategy;
2818            private Map<String, List<String>> _deletionKeysMap;
2819            private Set<StagedModelType> _deletionSystemEventModelTypes =
2820                    new HashSet<StagedModelType>();
2821            private Date _endDate;
2822            private Map<String, List<ExpandoColumn>> _expandoColumnsMap =
2823                    new HashMap<String, List<ExpandoColumn>>();
2824            private transient Element _exportDataRootElement;
2825            private long _groupId;
2826            private transient Element _importDataRootElement;
2827            private transient Map<String, Lock> _locksMap = new HashMap<String, Lock>();
2828            private transient ManifestSummary _manifestSummary = new ManifestSummary();
2829            private transient Set<String> _missingReferences = new HashSet<String>();
2830            private transient Element _missingReferencesElement;
2831            private transient List<Layout> _newLayouts;
2832            private Map<String, Map<?, ?>> _newPrimaryKeysMaps =
2833                    new HashMap<String, Map<?, ?>>();
2834            private Set<String> _notUniquePerLayout = new HashSet<String>();
2835            private long _oldPlid;
2836            private Map<String, String[]> _parameterMap;
2837            private Map<String, List<KeyValuePair>> _permissionsMap =
2838                    new HashMap<String, List<KeyValuePair>>();
2839            private long _plid;
2840            private transient PortletDataContextListener _portletDataContextListener;
2841            private String _rootPortletId;
2842            private Set<String> _primaryKeys = new HashSet<String>();
2843            private boolean _privateLayout;
2844            private transient Map<String, List<RatingsEntry>> _ratingsEntriesMap =
2845                    new HashMap<String, List<RatingsEntry>>();
2846            private Set<String> _references = new HashSet<String>();
2847            private Set<String> _scopedPrimaryKeys = new HashSet<String>();
2848            private long _scopeGroupId;
2849            private String _scopeLayoutUuid;
2850            private String _scopeType;
2851            private long _sourceCompanyGroupId;
2852            private long _sourceCompanyId;
2853            private long _sourceGroupId;
2854            private long _sourceUserPersonalSiteGroupId;
2855            private Date _startDate;
2856            private transient UserIdStrategy _userIdStrategy;
2857            private long _userPersonalSiteGroupId;
2858            private transient XStream _xStream;
2859            private transient ZipReader _zipReader;
2860            private transient ZipWriter _zipWriter;
2861    
2862    }