Project

General

Profile

Download (1.73 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.api.service;
10

    
11
import java.util.Map;
12

    
13
import org.apache.commons.lang.StringUtils;
14

    
15
import eu.etaxonomy.cdm.model.common.Language;
16
import eu.etaxonomy.cdm.model.common.LanguageString;
17
import eu.etaxonomy.cdm.model.description.TextData;
18

    
19
/**
20
 * @author m.venin
21
 * @since 2010-12-02
22
 */
23
public class DeltaTextDataProcessor implements INaturalLanguageTextDataProcessor {
24

    
25
	@Override
26
	public void process(TextData textData, TextData previousTextData) {
27
		boolean doItBetter = false;
28

    
29
		Map<Language,LanguageString> previousMultiLanguageText = previousTextData.getMultilanguageText();
30
		Map<Language,LanguageString> multiLanguageText = textData.getMultilanguageText();
31

    
32
		for (Language language : multiLanguageText.keySet()){
33
			LanguageString langString = multiLanguageText.get(language);
34
			String text = langString.getText();
35

    
36
			LanguageString tmpMultilangText = previousMultiLanguageText.get(language);
37
			if( tmpMultilangText != null){
38
				text = StringUtils.remove(text, tmpMultilangText.getText());
39
			}
40

    
41
			if (doItBetter) { //TODO remove the text between brackets
42
				StringBuilder strbuilder = new StringBuilder();
43
				do	{
44
					strbuilder.append(StringUtils.substringBefore(text, "<"));
45
				}
46
				while (!(text=StringUtils.substringAfter(text, ">")).equals(""));
47
				StringUtils.substringBeforeLast(strbuilder.toString()," ");
48
			}
49
			else{
50
				text=StringUtils.replaceChars(text,"<>","");
51
			}
52

    
53
			textData.removeText(language);
54
			textData.putText(language, text);
55
		}
56
	}
57
}
(10-10/95)