001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.lar;
016    
017    import com.liferay.portal.kernel.backgroundtask.BackgroundTaskThreadLocal;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.kernel.util.ArrayUtil;
021    import com.liferay.portal.kernel.util.GetterUtil;
022    import com.liferay.portal.kernel.util.StringPool;
023    import com.liferay.portal.kernel.util.Time;
024    import com.liferay.portal.kernel.util.Validator;
025    import com.liferay.portal.kernel.xml.Document;
026    import com.liferay.portal.kernel.xml.DocumentException;
027    import com.liferay.portal.kernel.xml.Element;
028    import com.liferay.portal.kernel.xml.SAXReaderUtil;
029    import com.liferay.portal.model.Portlet;
030    import com.liferay.portal.service.PortletLocalServiceUtil;
031    import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
032    import com.liferay.portal.util.PortletKeys;
033    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate;
034    import com.liferay.portlet.portletdisplaytemplate.util.PortletDisplayTemplate;
035    import com.liferay.portlet.portletdisplaytemplate.util.PortletDisplayTemplateUtil;
036    
037    import java.io.IOException;
038    
039    import java.util.ArrayList;
040    import java.util.List;
041    
042    import javax.portlet.PortletPreferences;
043    
044    /**
045     * @author Brian Wing Shun Chan
046     */
047    public abstract class BasePortletDataHandler implements PortletDataHandler {
048    
049            @Override
050            public PortletPreferences deleteData(
051                            PortletDataContext portletDataContext, String portletId,
052                            PortletPreferences portletPreferences)
053                    throws PortletDataException {
054    
055                    long startTime = 0;
056    
057                    if (_log.isInfoEnabled()) {
058                            _log.info("Deleting portlet " + portletId);
059    
060                            startTime = System.currentTimeMillis();
061                    }
062    
063                    try {
064                            return doDeleteData(
065                                    portletDataContext, portletId, portletPreferences);
066                    }
067                    catch (Exception e) {
068                            throw new PortletDataException(e);
069                    }
070                    finally {
071                            if (_log.isInfoEnabled()) {
072                                    long duration = System.currentTimeMillis() - startTime;
073    
074                                    _log.info("Deleted portlet in " + Time.getDuration(duration));
075                            }
076                    }
077            }
078    
079            @Override
080            public String exportData(
081                            PortletDataContext portletDataContext, String portletId,
082                            PortletPreferences portletPreferences)
083                    throws PortletDataException {
084    
085                    long startTime = 0;
086    
087                    if (_log.isInfoEnabled()) {
088                            _log.info("Exporting portlet " + portletId);
089    
090                            startTime = System.currentTimeMillis();
091                    }
092    
093                    try {
094                            portletDataContext.addDeletionSystemEventStagedModelTypes(
095                                    getDeletionSystemEventStagedModelTypes());
096    
097                            for (PortletDataHandlerControl portletDataHandlerControl :
098                                            getExportControls()) {
099    
100                                    addUncheckedModelAdditionCount(
101                                            portletDataContext, portletDataHandlerControl);
102                            }
103    
104                            if (BackgroundTaskThreadLocal.hasBackgroundTask()) {
105                                    PortletDataContext clonePortletDataContext =
106                                            PortletDataContextFactoryUtil.clonePortletDataContext(
107                                                    portletDataContext);
108    
109                                    prepareManifestSummary(
110                                            clonePortletDataContext, portletPreferences);
111    
112                                    PortletDataHandlerStatusMessageSenderUtil.sendStatusMessage(
113                                            "portlet", portletId,
114                                            clonePortletDataContext.getManifestSummary());
115                            }
116    
117                            return doExportData(
118                                    portletDataContext, portletId, portletPreferences);
119                    }
120                    catch (Exception e) {
121                            throw new PortletDataException(e);
122                    }
123                    finally {
124                            if (_log.isInfoEnabled()) {
125                                    long duration = System.currentTimeMillis() - startTime;
126    
127                                    _log.info("Exported portlet in " + Time.getDuration(duration));
128                            }
129                    }
130            }
131    
132            @Override
133            public DataLevel getDataLevel() {
134                    return _dataLevel;
135            }
136    
137            @Override
138            public String[] getDataPortletPreferences() {
139                    return _dataPortletPreferences;
140            }
141    
142            @Override
143            public StagedModelType[] getDeletionSystemEventStagedModelTypes() {
144                    return _deletionSystemEventStagedModelTypes;
145            }
146    
147            @Override
148            public PortletDataHandlerControl[] getExportConfigurationControls(
149                            long companyId, long groupId, Portlet portlet,
150                            boolean privateLayout)
151                    throws Exception {
152    
153                    return getExportConfigurationControls(
154                            companyId, groupId, portlet, -1, privateLayout);
155            }
156    
157            @Override
158            public PortletDataHandlerControl[] getExportConfigurationControls(
159                            long companyId, long groupId, Portlet portlet, long plid,
160                            boolean privateLayout)
161                    throws Exception {
162    
163                    List<PortletDataHandlerBoolean> configurationControls =
164                            new ArrayList<PortletDataHandlerBoolean>();
165    
166                    // Setup
167    
168                    if ((PortletPreferencesLocalServiceUtil.getPortletPreferencesCount(
169                                    companyId, groupId, PortletKeys.PREFS_OWNER_ID_DEFAULT,
170                                    PortletKeys.PREFS_OWNER_TYPE_LAYOUT, plid, portlet,
171                                    privateLayout, false) > 0) ||
172                            (PortletPreferencesLocalServiceUtil.getPortletPreferencesCount(
173                                    groupId, PortletKeys.PREFS_OWNER_TYPE_GROUP,
174                                    portlet.getRootPortletId(), false) > 0) ||
175                            (PortletPreferencesLocalServiceUtil.getPortletPreferencesCount(
176                                    companyId, PortletKeys.PREFS_OWNER_TYPE_COMPANY,
177                                    portlet.getRootPortletId(), false) > 0)) {
178    
179                                    configurationControls.add(
180                                            new PortletDataHandlerBoolean(
181                                                    null, PortletDataHandlerKeys.PORTLET_SETUP, "setup",
182                                                    true, false, null, null, null));
183                    }
184    
185                    // Archived setups
186    
187                    if (PortletPreferencesLocalServiceUtil.getPortletPreferencesCount(
188                                    -1, PortletKeys.PREFS_OWNER_TYPE_ARCHIVED,
189                                    portlet.getRootPortletId(), false) > 0) {
190    
191                            configurationControls.add(
192                                    new PortletDataHandlerBoolean(
193                                            null, PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS,
194                                            "archived-setups", true, false, null, null, null)
195                            );
196                    }
197    
198                    // User preferences
199    
200                    if ((PortletPreferencesLocalServiceUtil.getPortletPreferencesCount(
201                                    companyId, groupId, -1, PortletKeys.PREFS_OWNER_TYPE_USER, plid,
202                                    portlet, privateLayout, false) > 0) ||
203                            (PortletPreferencesLocalServiceUtil.getPortletPreferencesCount(
204                                    companyId, groupId, groupId, PortletKeys.PREFS_OWNER_TYPE_USER,
205                                    PortletKeys.PREFS_PLID_SHARED, portlet, privateLayout, false)
206                                    > 0)) {
207    
208                            configurationControls.add(
209                                    new PortletDataHandlerBoolean(
210                                            null, PortletDataHandlerKeys.PORTLET_USER_PREFERENCES,
211                                            "user-preferences", true, false, null, null, null));
212                    }
213    
214                    return configurationControls.toArray(
215                            new PortletDataHandlerBoolean[configurationControls.size()]);
216            }
217    
218            @Override
219            public PortletDataHandlerControl[] getExportControls() {
220                    return _exportControls;
221            }
222    
223            @Override
224            public PortletDataHandlerControl[] getExportMetadataControls() {
225                    return _exportMetadataControls;
226            }
227    
228            @Override
229            public long getExportModelCount(ManifestSummary manifestSummary) {
230                    return getExportModelCount(manifestSummary, getExportControls());
231            }
232    
233            @Override
234            public PortletDataHandlerControl[] getImportConfigurationControls(
235                    Portlet portlet, ManifestSummary manifestSummary) {
236    
237                    String[] configurationPortletOptions =
238                            manifestSummary.getConfigurationPortletOptions(
239                                    portlet.getRootPortletId());
240    
241                    return getImportConfigurationControls(configurationPortletOptions);
242            }
243    
244            @Override
245            public PortletDataHandlerControl[] getImportConfigurationControls(
246                    String[] configurationPortletOptions) {
247    
248                    List<PortletDataHandlerBoolean> configurationControls =
249                            new ArrayList<PortletDataHandlerBoolean>();
250    
251                    // Setup
252    
253                    if (ArrayUtil.contains(configurationPortletOptions, "setup")) {
254                            configurationControls.add(
255                                    new PortletDataHandlerBoolean(
256                                            null, PortletDataHandlerKeys.PORTLET_SETUP, "setup", true,
257                                            false, null, null, null));
258                    }
259    
260                    // Archived setups
261    
262                    if (ArrayUtil.contains(
263                                    configurationPortletOptions, "archived-setups")) {
264    
265                            configurationControls.add(
266                                    new PortletDataHandlerBoolean(
267                                            null, PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS,
268                                            "archived-setups", true, false, null, null, null));
269                    }
270    
271                    // User preferences
272    
273                    if (ArrayUtil.contains(
274                                    configurationPortletOptions, "user-preferences")) {
275    
276                            configurationControls.add(
277                                    new PortletDataHandlerBoolean(
278                                            null, PortletDataHandlerKeys.PORTLET_USER_PREFERENCES,
279                                            "user-preferences", true, false, null, null, null));
280                    }
281    
282                    return configurationControls.toArray(
283                            new PortletDataHandlerBoolean[configurationControls.size()]);
284            }
285    
286            @Override
287            public PortletDataHandlerControl[] getImportControls() {
288                    return _importControls;
289            }
290    
291            @Override
292            public PortletDataHandlerControl[] getImportMetadataControls() {
293                    return _importMetadataControls;
294            }
295    
296            @Override
297            public String getPortletId() {
298                    return _portletId;
299            }
300    
301            @Override
302            public PortletPreferences importData(
303                            PortletDataContext portletDataContext, String portletId,
304                            PortletPreferences portletPreferences, String data)
305                    throws PortletDataException {
306    
307                    long startTime = 0;
308    
309                    if (_log.isInfoEnabled()) {
310                            _log.info("Importing portlet " + portletId);
311    
312                            startTime = System.currentTimeMillis();
313                    }
314    
315                    long sourceGroupId = portletDataContext.getSourceGroupId();
316    
317                    try {
318                            if (Validator.isXml(data)) {
319                                    addImportDataRootElement(portletDataContext, data);
320                            }
321    
322                            portletDataContext.addDeletionSystemEventStagedModelTypes(
323                                    getDeletionSystemEventStagedModelTypes());
324    
325                            return doImportData(
326                                    portletDataContext, portletId, portletPreferences, data);
327                    }
328                    catch (Exception e) {
329                            throw new PortletDataException(e);
330                    }
331                    finally {
332                            portletDataContext.setSourceGroupId(sourceGroupId);
333    
334                            if (_log.isInfoEnabled()) {
335                                    long duration = System.currentTimeMillis() - startTime;
336    
337                                    _log.info("Imported portlet in " + Time.getDuration(duration));
338                            }
339                    }
340            }
341    
342            @Override
343            public boolean isDataLocalized() {
344                    return _dataLocalized;
345            }
346    
347            @Override
348            public boolean isDataPortalLevel() {
349                    return _dataLevel.equals(DataLevel.PORTAL);
350            }
351    
352            @Override
353            public boolean isDataPortletInstanceLevel() {
354                    return _dataLevel.equals(DataLevel.PORTLET_INSTANCE);
355            }
356    
357            @Override
358            public boolean isDataSiteLevel() {
359                    return _dataLevel.equals(DataLevel.SITE);
360            }
361    
362            @Override
363            public boolean isDisplayPortlet() {
364                    if (isDataPortletInstanceLevel() &&
365                            !ArrayUtil.isEmpty(getDataPortletPreferences())) {
366    
367                            return true;
368                    }
369    
370                    return false;
371            }
372    
373            @Override
374            public boolean isPublishToLiveByDefault() {
375                    return _publishToLiveByDefault;
376            }
377    
378            @Override
379            public boolean isSupportsDataStrategyCopyAsNew() {
380                    return _supportsDataStrategyCopyAsNew;
381            }
382    
383            @Override
384            public void prepareManifestSummary(PortletDataContext portletDataContext)
385                    throws PortletDataException {
386    
387                    prepareManifestSummary(portletDataContext, null);
388            }
389    
390            @Override
391            public void prepareManifestSummary(
392                            PortletDataContext portletDataContext,
393                            PortletPreferences portletPreferences)
394                    throws PortletDataException {
395    
396                    try {
397                            doPrepareManifestSummary(portletDataContext, portletPreferences);
398                    }
399                    catch (Exception e) {
400                            throw new PortletDataException(e);
401                    }
402            }
403    
404            @Override
405            public PortletPreferences processExportPortletPreferences(
406                            PortletDataContext portletDataContext, String portletId,
407                            PortletPreferences portletPreferences)
408                    throws PortletDataException {
409    
410                    String displayStyle = getDisplayTemplate(
411                            portletDataContext, portletId, portletPreferences);
412    
413                    if (Validator.isNotNull(displayStyle) &&
414                            displayStyle.startsWith(
415                                    PortletDisplayTemplate.DISPLAY_STYLE_PREFIX)) {
416    
417                            long displayStyleGroupId = getDisplayTemplateGroupId(
418                                    portletDataContext, portletId, portletPreferences);
419    
420                            long previousScopeGroupId = portletDataContext.getScopeGroupId();
421    
422                            if (displayStyleGroupId != portletDataContext.getScopeGroupId()) {
423                                    portletDataContext.setScopeGroupId(displayStyleGroupId);
424                            }
425    
426                            DDMTemplate ddmTemplate =
427                                    PortletDisplayTemplateUtil.fetchDDMTemplate(
428                                            portletDataContext.getGroupId(), displayStyle);
429    
430                            if (ddmTemplate != null) {
431                                    StagedModelDataHandlerUtil.exportReferenceStagedModel(
432                                            portletDataContext, portletId, ddmTemplate);
433                            }
434    
435                            portletDataContext.setScopeGroupId(previousScopeGroupId);
436                    }
437    
438                    try {
439                            return doProcessExportPortletPreferences(
440                                    portletDataContext, portletId, portletPreferences);
441                    }
442                    catch (Exception e) {
443                            throw new PortletDataException(e);
444                    }
445            }
446    
447            @Override
448            public PortletPreferences processImportPortletPreferences(
449                            PortletDataContext portletDataContext, String portletId,
450                            PortletPreferences portletPreferences)
451                    throws PortletDataException {
452    
453                    try {
454                            String displayStyle = getDisplayTemplate(
455                                    portletDataContext, portletId, portletPreferences);
456    
457                            if (Validator.isNotNull(displayStyle) &&
458                                    displayStyle.startsWith(
459                                            PortletDisplayTemplate.DISPLAY_STYLE_PREFIX)) {
460    
461                                    DDMTemplate ddmTemplate = null;
462    
463                                    long displayStyleGroupId = getDisplayTemplateGroupId(
464                                            portletDataContext, portletId, portletPreferences);
465    
466                                    if (displayStyleGroupId ==
467                                                    portletDataContext.getCompanyGroupId()) {
468    
469                                            ddmTemplate = PortletDisplayTemplateUtil.fetchDDMTemplate(
470                                                    portletDataContext.getCompanyGroupId(), displayStyle);
471                                    }
472                                    else if (displayStyleGroupId ==
473                                                            portletDataContext.getSourceGroupId()) {
474    
475                                            ddmTemplate = PortletDisplayTemplateUtil.fetchDDMTemplate(
476                                                    portletDataContext.getScopeGroupId(), displayStyle);
477                                    }
478                                    else {
479                                            ddmTemplate = PortletDisplayTemplateUtil.fetchDDMTemplate(
480                                                    displayStyleGroupId, displayStyle);
481                                    }
482    
483                                    long importedDisplayStyleGroupId =
484                                            portletDataContext.getScopeGroupId();
485    
486                                    if (ddmTemplate == null) {
487                                            String ddmTemplateUuid =
488                                                    PortletDisplayTemplateUtil.getDDMTemplateUuid(
489                                                            displayStyle);
490    
491                                            Element ddmTemplateElement =
492                                                    portletDataContext.getImportDataElement(
493                                                            DDMTemplate.class.getSimpleName(), "uuid",
494                                                            ddmTemplateUuid);
495    
496                                            String ddmTemplatePath = ddmTemplateElement.attributeValue(
497                                                    "path");
498    
499                                            ddmTemplate =
500                                                    (DDMTemplate)portletDataContext.getZipEntryAsObject(
501                                                            ddmTemplatePath);
502    
503                                            if (ddmTemplate != null) {
504                                                    StagedModelDataHandlerUtil.importStagedModel(
505                                                            portletDataContext, ddmTemplate);
506                                            }
507                                    }
508                                    else {
509                                            importedDisplayStyleGroupId = ddmTemplate.getGroupId();
510                                    }
511    
512                                    portletPreferences.setValue(
513                                            "displayStyleGroupId",
514                                            String.valueOf(importedDisplayStyleGroupId));
515                            }
516                            else {
517                                    portletPreferences.setValue(
518                                            "displayStyleGroupId", StringPool.BLANK);
519                            }
520    
521                            return doProcessImportPortletPreferences(
522                                    portletDataContext, portletId, portletPreferences);
523                    }
524                    catch (Exception e) {
525                            throw new PortletDataException(e);
526                    }
527            }
528    
529            @Override
530            public void setPortletId(String portletId) {
531                    _portletId = portletId;
532            }
533    
534            protected Element addExportDataRootElement(
535                    PortletDataContext portletDataContext) {
536    
537                    Document document = SAXReaderUtil.createDocument();
538    
539                    Class<?> clazz = getClass();
540    
541                    Element rootElement = document.addElement(clazz.getSimpleName());
542    
543                    portletDataContext.setExportDataRootElement(rootElement);
544    
545                    return rootElement;
546            }
547    
548            protected Element addImportDataRootElement(
549                            PortletDataContext portletDataContext, String data)
550                    throws DocumentException {
551    
552                    Document document = SAXReaderUtil.read(data);
553    
554                    Element rootElement = document.getRootElement();
555    
556                    portletDataContext.setImportDataRootElement(rootElement);
557    
558                    long groupId = GetterUtil.getLong(
559                            rootElement.attributeValue("group-id"));
560    
561                    if (groupId != 0) {
562                            portletDataContext.setSourceGroupId(groupId);
563                    }
564    
565                    return rootElement;
566            }
567    
568            protected void addUncheckedModelAdditionCount(
569                    PortletDataContext portletDataContext,
570                    PortletDataHandlerControl portletDataHandlerControl) {
571    
572                    if (!(portletDataHandlerControl instanceof PortletDataHandlerBoolean)) {
573                            return;
574                    }
575    
576                    PortletDataHandlerBoolean portletDataHandlerBoolean =
577                            (PortletDataHandlerBoolean)portletDataHandlerControl;
578    
579                    PortletDataHandlerControl[] childPortletDataHandlerControls =
580                            portletDataHandlerBoolean.getChildren();
581    
582                    if (childPortletDataHandlerControls != null) {
583                            for (PortletDataHandlerControl childPortletDataHandlerControl :
584                                            childPortletDataHandlerControls) {
585    
586                                    addUncheckedModelAdditionCount(
587                                            portletDataContext, childPortletDataHandlerControl);
588                            }
589                    }
590    
591                    if (Validator.isNull(portletDataHandlerControl.getClassName())) {
592                            return;
593                    }
594    
595                    boolean checkedControl = GetterUtil.getBoolean(
596                            portletDataContext.getBooleanParameter(
597                                    portletDataHandlerControl.getNamespace(),
598                                    portletDataHandlerControl.getControlName(), false));
599    
600                    if (!checkedControl) {
601                            ManifestSummary manifestSummary =
602                                    portletDataContext.getManifestSummary();
603    
604                            String manifestSummaryKey = ManifestSummary.getManifestSummaryKey(
605                                    portletDataHandlerControl.getClassName(),
606                                    portletDataHandlerBoolean.getReferrerClassName());
607    
608                            manifestSummary.addModelAdditionCount(manifestSummaryKey, 0);
609                    }
610            }
611    
612            protected PortletPreferences doDeleteData(
613                            PortletDataContext portletDataContext, String portletId,
614                            PortletPreferences portletPreferences)
615                    throws Exception {
616    
617                    return portletPreferences;
618            }
619    
620            protected String doExportData(
621                            PortletDataContext portletDataContext, String portletId,
622                            PortletPreferences portletPreferences)
623                    throws Exception {
624    
625                    return null;
626            }
627    
628            protected PortletPreferences doImportData(
629                            PortletDataContext portletDataContext, String portletId,
630                            PortletPreferences portletPreferences, String data)
631                    throws Exception {
632    
633                    return null;
634            }
635    
636            protected void doPrepareManifestSummary(
637                            PortletDataContext portletDataContext,
638                            PortletPreferences portletPreferences)
639                    throws Exception {
640            }
641    
642            protected PortletPreferences doProcessExportPortletPreferences(
643                            PortletDataContext portletDataContext, String portletId,
644                            PortletPreferences portletPreferences)
645                    throws Exception {
646    
647                    return portletPreferences;
648            }
649    
650            protected PortletPreferences doProcessImportPortletPreferences(
651                            PortletDataContext portletDataContext, String portletId,
652                            PortletPreferences portletPreferences)
653                    throws Exception {
654    
655                    return portletPreferences;
656            }
657    
658            protected String getDisplayTemplate(
659                    PortletDataContext portletDataContext, String portletId,
660                    PortletPreferences portletPreferences) {
661    
662                    try {
663                            Portlet portlet = PortletLocalServiceUtil.getPortletById(
664                                    portletDataContext.getCompanyId(), portletId);
665    
666                            if (Validator.isNotNull(portlet.getTemplateHandlerClass())) {
667                                    return portletPreferences.getValue("displayStyle", null);
668                            }
669                    }
670                    catch (Exception e) {
671                    }
672    
673                    return null;
674            }
675    
676            protected long getDisplayTemplateGroupId(
677                    PortletDataContext portletDataContext, String portletId,
678                    PortletPreferences portletPreferences) {
679    
680                    try {
681                            Portlet portlet = PortletLocalServiceUtil.getPortletById(
682                                    portletDataContext.getCompanyId(), portletId);
683    
684                            if (Validator.isNotNull(portlet.getTemplateHandlerClass())) {
685                                    return GetterUtil.getLong(
686                                            portletPreferences.getValue("displayStyleGroupId", null));
687                            }
688                    }
689                    catch (Exception e) {
690                    }
691    
692                    return 0;
693            }
694    
695            protected String getExportDataRootElementString(Element rootElement) {
696                    if (rootElement == null) {
697                            return StringPool.BLANK;
698                    }
699    
700                    try {
701                            Document document = rootElement.getDocument();
702    
703                            return document.formattedString();
704                    }
705                    catch (IOException ioe) {
706                            return StringPool.BLANK;
707                    }
708            }
709    
710            protected long getExportModelCount(
711                    ManifestSummary manifestSummary,
712                    PortletDataHandlerControl[] portletDataHandlerControls) {
713    
714                    long totalModelCount = -1;
715    
716                    for (PortletDataHandlerControl portletDataHandlerControl :
717                                    portletDataHandlerControls) {
718    
719                            long modelCount = manifestSummary.getModelAdditionCount(
720                                    portletDataHandlerControl.getClassName(),
721                                    portletDataHandlerControl.getReferrerClassName());
722    
723                            if (portletDataHandlerControl
724                                            instanceof PortletDataHandlerBoolean) {
725    
726                                    PortletDataHandlerBoolean portletDataHandlerBoolean =
727                                            (PortletDataHandlerBoolean)portletDataHandlerControl;
728    
729                                    PortletDataHandlerControl[] childPortletDataHandlerControls =
730                                            portletDataHandlerBoolean.getChildren();
731    
732                                    if (childPortletDataHandlerControls != null) {
733                                            long childModelCount = getExportModelCount(
734                                                    manifestSummary, childPortletDataHandlerControls);
735    
736                                            if (childModelCount != -1) {
737                                                    if (modelCount == -1) {
738                                                            modelCount = childModelCount;
739                                                    }
740                                                    else {
741                                                            modelCount += childModelCount;
742                                                    }
743                                            }
744                                    }
745                            }
746    
747                            if (modelCount == -1) {
748                                    continue;
749                            }
750    
751                            if (totalModelCount == -1) {
752                                    totalModelCount = modelCount;
753                            }
754                            else {
755                                    totalModelCount += modelCount;
756                            }
757                    }
758    
759                    return totalModelCount;
760            }
761    
762            /**
763             * @deprecated As of 6.2.0
764             */
765            protected void setAlwaysExportable(boolean alwaysExportable) {
766            }
767    
768            /**
769             * @deprecated As of 6.2.0
770             */
771            protected void setAlwaysStaged(boolean alwaysStaged) {
772            }
773    
774            protected void setDataLevel(DataLevel dataLevel) {
775                    _dataLevel = dataLevel;
776            }
777    
778            protected void setDataLocalized(boolean dataLocalized) {
779                    _dataLocalized = dataLocalized;
780            }
781    
782            protected void setDataPortletPreferences(String... dataPortletPreferences) {
783                    _dataPortletPreferences = dataPortletPreferences;
784            }
785    
786            protected void setDeletionSystemEventStagedModelTypes(
787                    StagedModelType... deletionSystemEventStagedModelTypes) {
788    
789                    _deletionSystemEventStagedModelTypes =
790                            deletionSystemEventStagedModelTypes;
791            }
792    
793            protected void setExportControls(
794                    PortletDataHandlerControl... exportControls) {
795    
796                    _exportControls = exportControls;
797    
798                    setImportControls(exportControls);
799            }
800    
801            protected void setExportMetadataControls(
802                    PortletDataHandlerControl... exportMetadataControls) {
803    
804                    _exportMetadataControls = exportMetadataControls;
805    
806                    setImportMetadataControls(exportMetadataControls);
807            }
808    
809            protected void setImportControls(
810                    PortletDataHandlerControl... importControls) {
811    
812                    _importControls = importControls;
813            }
814    
815            protected void setImportMetadataControls(
816                    PortletDataHandlerControl... importMetadataControls) {
817    
818                    _importMetadataControls = importMetadataControls;
819            }
820    
821            protected void setPublishToLiveByDefault(boolean publishToLiveByDefault) {
822                    _publishToLiveByDefault = publishToLiveByDefault;
823            }
824    
825            protected void setSupportsDataStrategyCopyAsNew(
826                    boolean supportsDataStrategyCopyAsNew) {
827    
828                    _supportsDataStrategyCopyAsNew = supportsDataStrategyCopyAsNew;
829            }
830    
831            private static Log _log = LogFactoryUtil.getLog(
832                    BasePortletDataHandler.class);
833    
834            private DataLevel _dataLevel = DataLevel.SITE;
835            private boolean _dataLocalized;
836            private String[] _dataPortletPreferences = StringPool.EMPTY_ARRAY;
837            private StagedModelType[] _deletionSystemEventStagedModelTypes =
838                    new StagedModelType[0];
839            private PortletDataHandlerControl[] _exportControls =
840                    new PortletDataHandlerControl[0];
841            private PortletDataHandlerControl[] _exportMetadataControls =
842                    new PortletDataHandlerControl[0];
843            private PortletDataHandlerControl[] _importControls =
844                    new PortletDataHandlerControl[0];
845            private PortletDataHandlerControl[] _importMetadataControls =
846                    new PortletDataHandlerControl[0];
847            private String _portletId;
848            private boolean _publishToLiveByDefault;
849            private boolean _supportsDataStrategyCopyAsNew = true;
850    
851    }