/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache license, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.internna.iwebmvc.parsers;
import java.util.List;
import org.internna.iwebmvc.dao.DAO;
import org.internna.iwebmvc.model.I18nText;
import org.internna.iwebmvc.model.LocalizedValue;
/**
* Parses @{@link I18nText} entities.
*
* @author Jose Noheda
* @since 2.0
*/
public class I18nTextParser extends AbstractEntityParser<I18nText> {
public I18nTextParser(DAO dao) {
super(I18nText.class, dao);
}
@Override
public I18nText parse(I18nText txt) {
if ((txt != null) && (txt.getId() != null)) {
I18nText loaded = getDao().find(I18nText.class, txt.getId());
if (loaded != null) {
List<LocalizedValue> oldData = loaded.getData();
List<LocalizedValue> newData = txt.getData();
for (int index = 0; index < oldData.size(); index++) {
LocalizedValue localized = oldData.get(index);
localized.setTranslation(newData.get(index).getTranslation());
}
return loaded;
}
}
return txt;
}
}