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