001    /**
002     * Copyright (c) 2000-2010 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.upgrade.v4_3_4.util;
016    
017    import com.liferay.portal.kernel.upgrade.util.BaseUpgradeColumnImpl;
018    import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
019    import com.liferay.portal.kernel.util.LocaleUtil;
020    import com.liferay.portal.kernel.util.LocalizationUtil;
021    import com.liferay.portal.kernel.util.StringPool;
022    import com.liferay.portal.kernel.util.Validator;
023    
024    /**
025     * @author Alexander Chow
026     */
027    public class JournalArticleContentUpgradeColumnImpl
028            extends BaseUpgradeColumnImpl {
029    
030            public JournalArticleContentUpgradeColumnImpl(
031                    UpgradeColumn structureIdColumn) {
032    
033                    super("content");
034    
035                    _structureIdColumn = structureIdColumn;
036            }
037    
038            public Object getNewValue(Object oldValue) throws Exception {
039                    String oldContent = (String)oldValue;
040    
041                    String newContent = oldContent;
042    
043                    String structureId = (String)_structureIdColumn.getOldValue();
044    
045                    if (Validator.isNull(structureId)) {
046                            if (Validator.isNotNull(oldContent) &&
047                                    (oldContent.indexOf("<static-content") == -1)) {
048    
049                                    String defaultLanguageId = LocaleUtil.toLanguageId(
050                                            LocaleUtil.getDefault());
051    
052                                    newContent = LocalizationUtil.updateLocalization(
053                                            StringPool.BLANK, "static-content", oldContent,
054                                            defaultLanguageId, defaultLanguageId, true);
055                            }
056                    }
057    
058                    return newContent;
059            }
060    
061            private UpgradeColumn _structureIdColumn;
062    
063    }