Project

General

Profile

Download (2.52 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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.model.common;
10

    
11
/**
12
 * Utility class to handle {@link IntextReference}s
13
 *
14
 * @author a.mueller
15
 * @date 10.03.2017
16
 *
17
 */
18
public final class IntextReferenceHelper {
19

    
20
    public static IntextReference addIntextReference(IIntextReferenceTarget target, IIntextReferencable referencedEntity, String start, String inner, String end){
21
        IntextReference intextReference = IntextReference.NewInstance(target, referencedEntity, 0, 0);
22
      // intextReference.setInnerText(inner);
23
        referencedEntity.setText(start + intextReference.toInlineString(inner) + end);
24
        referencedEntity.getIntextReferences().add(intextReference);
25
        return intextReference;
26
    }
27
    public static IntextReference addIntextReference(IIntextReferenceTarget target, IIntextReferencable referencedEntity, int start, int end){
28
        String text = referencedEntity.getText();
29
        if (start < 0 || end < 0 || start > end || end > text.length()){
30
            throw new IndexOutOfBoundsException("Start and end must be within bounds");
31
        }
32
        IntextReference intextReference = IntextReference.NewInstance(target, referencedEntity, 0, 0);
33
//        intextReference.setInnerText(text.substring(start,end));
34
        referencedEntity.setText(text.substring(0, start) + intextReference.toInlineString(text.substring(start,end))
35
            + text.substring(end));
36
        referencedEntity.getIntextReferences().add(intextReference);
37
        return intextReference;
38
    }
39
    public static IntextReference addIntextReference(IIntextReferenceTarget target, IntextReference intextRef, int start, int end){
40
        String text = intextRef.getReferencedEntity().getText();
41
        if (start < 0 || end < 0 || start > end || end > text.length()){
42
            throw new IndexOutOfBoundsException("Start and end must be within bounds");
43
        }
44
        intextRef.setTarget(target);
45
//        intextRef.setInnerText(text.substring(start,end));
46
        intextRef.getReferencedEntity().setText(text.substring(0, start) + intextRef.toInlineString(text.substring(start,end))
47
            + text.substring(end));
48
        intextRef.setStartPos(start);
49
        intextRef.setEndPos(end);
50
//        intextRef.getReferencedEntity().getIntextReferences().add(intextReference);
51
        return intextRef;
52

    
53
    }
54
}
(41-41/77)