blob: feab82bfd178c2955b66177b08fd6b165f163cd7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/*******************************************************************************
* Copyright (c) 2014 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.define.report.api;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
* @author Angel Avila
*/
@XmlRootElement
public class DataRightResult {
private static final String NEW_PAGE_TEMPLATE =
"<w:p><w:pPr><w:spacing w:after=\"0\"/><w:sectPr>%s</w:sectPr></w:pPr></w:p>";
private static final String SAME_PAGE_TEMPLATE = "<w:sectPr>%s</w:sectPr>";
@XmlTransient
private List<DataRightAnchor> dataRightAnchors;
@XmlTransient
private List<DataRight> dataRights;
private Map<DataRightId, DataRight> dataRightIdToDataRight;
private Map<String, DataRightAnchor> guidToAnchor;
@XmlElement
public Collection<DataRightAnchor> getDataRightAnchors() {
if (dataRightAnchors == null) {
dataRightAnchors = new ArrayList<DataRightAnchor>();
}
return dataRightAnchors;
}
public void setDataRightAnchors(List<DataRightAnchor> dataRightAnchors) {
this.dataRightAnchors = dataRightAnchors;
}
@XmlElement
public Collection<DataRight> getDataRights() {
if (dataRights == null) {
dataRights = new ArrayList<DataRight>();
}
return dataRights;
}
public void setDataRights(List<DataRight> dataRights) {
this.dataRights = dataRights;
}
public String getContent(String guid, PageOrientation orientation) {
checkInitialized();
String toReturn;
DataRightAnchor anchor = guidToAnchor.get(guid);
DataRightId key = anchor.getDataRightId();
boolean needsPageBreak = anchor.isNeedsPageBreak();
boolean isNextDifferent = anchor.isNextDifferent();
DataRight dataRight = dataRightIdToDataRight.get(key);
String partialFooter = dataRight.getContent();
if (orientation.isLandscape()) {
toReturn = partialFooter;
} else if (isNextDifferent || needsPageBreak) {
if (needsPageBreak) {
toReturn = String.format(NEW_PAGE_TEMPLATE, partialFooter);
} else {
toReturn = String.format(SAME_PAGE_TEMPLATE, partialFooter);
}
} else {
toReturn = "";
}
return toReturn;
}
public void reset() {
dataRightIdToDataRight = null;
guidToAnchor = null;
}
private void checkInitialized() {
if (dataRightIdToDataRight == null || guidToAnchor == null) {
dataRightIdToDataRight = new HashMap<DataRightId, DataRight>();
guidToAnchor = new HashMap<String, DataRightAnchor>();
for (DataRightAnchor anchor : dataRightAnchors) {
guidToAnchor.put(anchor.getId(), anchor);
}
for (DataRight dataRight : dataRights) {
dataRightIdToDataRight.put(dataRight.getId(), dataRight);
}
}
}
}
|