| 36 |
naveen |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.metamodel.util;
|
|
|
5 |
|
|
|
6 |
import in.shop2020.metamodel.core.Bullet;
|
| 37 |
naveen |
7 |
import in.shop2020.metamodel.core.CompositeDataObject;
|
| 38 |
naveen |
8 |
import in.shop2020.metamodel.core.Entity;
|
| 37 |
naveen |
9 |
import in.shop2020.metamodel.core.EnumDataObject;
|
| 38 |
naveen |
10 |
import in.shop2020.metamodel.core.Feature;
|
|
|
11 |
import in.shop2020.metamodel.core.FreeformContent;
|
| 37 |
naveen |
12 |
import in.shop2020.metamodel.core.PrimitiveDataObject;
|
|
|
13 |
import in.shop2020.metamodel.definitions.BulletDefinition;
|
|
|
14 |
import in.shop2020.metamodel.definitions.Catalog;
|
|
|
15 |
import in.shop2020.metamodel.definitions.CompositeDefinition;
|
|
|
16 |
import in.shop2020.metamodel.definitions.CompositePartDefinition;
|
|
|
17 |
import in.shop2020.metamodel.definitions.DatatypeDefinition;
|
|
|
18 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
|
|
19 |
import in.shop2020.metamodel.definitions.EditorialImportance;
|
|
|
20 |
import in.shop2020.metamodel.definitions.EntityContainer;
|
|
|
21 |
import in.shop2020.metamodel.definitions.EnumDefinition;
|
|
|
22 |
import in.shop2020.metamodel.definitions.FeatureDefinition;
|
|
|
23 |
import in.shop2020.metamodel.definitions.SlideDefinition;
|
|
|
24 |
import in.shop2020.metamodel.definitions.Unit;
|
|
|
25 |
import in.shop2020.util.Utils;
|
| 36 |
naveen |
26 |
|
|
|
27 |
import java.util.ArrayList;
|
|
|
28 |
import java.util.HashMap;
|
|
|
29 |
import java.util.List;
|
|
|
30 |
import java.util.Map;
|
|
|
31 |
|
| 37 |
naveen |
32 |
import org.apache.commons.lang.ArrayUtils;
|
| 36 |
naveen |
33 |
import org.apache.commons.lang.StringUtils;
|
|
|
34 |
import org.apache.poi.hslf.HSLFSlideShow;
|
|
|
35 |
import org.apache.poi.hslf.extractor.PowerPointExtractor;
|
|
|
36 |
import org.apache.poi.hslf.model.Slide;
|
|
|
37 |
import org.apache.poi.hslf.model.TextRun;
|
|
|
38 |
import org.apache.poi.hslf.usermodel.RichTextRun;
|
|
|
39 |
import org.apache.poi.hslf.usermodel.SlideShow;
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* @author naveen
|
|
|
43 |
*
|
|
|
44 |
*/
|
|
|
45 |
public class HSLF {
|
| 37 |
naveen |
46 |
public static final String CONTENT_SRC_PPT_PATH =
|
|
|
47 |
"/home/naveen/workspace/eclipse/content/ppt/";
|
|
|
48 |
public static final String CONTENT_SRC_HTML_PATH =
|
|
|
49 |
"/home/naveen/workspace/eclipse/content/html/";
|
|
|
50 |
public static final String CONTENT_SRC_XML_PATH =
|
|
|
51 |
"/home/naveen/workspace/eclipse/content/xml/";
|
|
|
52 |
|
| 38 |
naveen |
53 |
public static final int BLUE = -16776961;
|
|
|
54 |
public static final int PURPLE = -6749953;
|
|
|
55 |
public static final int GREEN = -16711936;
|
|
|
56 |
public static final int ORANGE = -26368;
|
|
|
57 |
|
|
|
58 |
|
| 37 |
naveen |
59 |
//** LOCAL
|
|
|
60 |
public static final String CONTENT_DB_PATH =
|
|
|
61 |
"/home/naveen/workspace/eclipse/db/entities/";
|
|
|
62 |
|
|
|
63 |
/** WEB
|
|
|
64 |
public static final String CONTENT_DB_PATH =
|
|
|
65 |
"/var/lib/tomcat6/webapps/shop2020/db/entities/";
|
|
|
66 |
*/
|
|
|
67 |
|
| 36 |
naveen |
68 |
private List<String> slideNames = new ArrayList<String>();
|
|
|
69 |
private Map<String, List<String>> slideNameChildrenSlideNames =
|
|
|
70 |
new HashMap<String, List<String>>();
|
|
|
71 |
|
|
|
72 |
private Map<String, List<String>> slideNameFeatureNames =
|
|
|
73 |
new HashMap<String, List<String>>();
|
|
|
74 |
|
| 37 |
naveen |
75 |
private Map<String, Long> slideNameSlideDefID =
|
| 36 |
naveen |
76 |
new HashMap<String, Long>();
|
|
|
77 |
|
| 37 |
naveen |
78 |
private Map<String, Long> slideNameFeatureNameFeatureDefID =
|
| 36 |
naveen |
79 |
new HashMap<String, Long>();
|
|
|
80 |
|
| 37 |
naveen |
81 |
private Map<String, List<String>> slideNameFeatureNameBulletTexts =
|
|
|
82 |
new HashMap<String, List<String>>();
|
|
|
83 |
|
|
|
84 |
private Map<String, List<Bullet>> slideNameFeatureNameBullets =
|
| 36 |
naveen |
85 |
new HashMap<String, List<Bullet>>();
|
|
|
86 |
|
| 37 |
naveen |
87 |
private Map<String, List<String>> containerFCCs =
|
| 36 |
naveen |
88 |
new HashMap<String, List<String>>();
|
|
|
89 |
|
| 37 |
naveen |
90 |
private long categoryID;
|
|
|
91 |
private String srcFile;
|
|
|
92 |
private String dbFile;
|
|
|
93 |
|
| 38 |
naveen |
94 |
private String introductionTitle;
|
|
|
95 |
private String introductionText;
|
|
|
96 |
|
| 36 |
naveen |
97 |
/**
|
|
|
98 |
* @param args
|
|
|
99 |
*/
|
|
|
100 |
public static void main(String[] args) throws Exception {
|
| 40 |
naveen |
101 |
String[] commands = new String[] {"validate", "import", "show"};
|
| 36 |
naveen |
102 |
|
| 37 |
naveen |
103 |
String usage = "Usage: HSLF ["+ StringUtils.join(commands, "|") +
|
|
|
104 |
"] [{Entity ID}|{Category ID} {PPT file name}]\n";
|
|
|
105 |
|
|
|
106 |
if(args.length < 2) {
|
|
|
107 |
System.out.println(usage);
|
|
|
108 |
System.exit(-1);
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
String inputCommand = args[0];
|
|
|
112 |
|
|
|
113 |
if(!ArrayUtils.contains(commands, inputCommand)) {
|
|
|
114 |
System.out.println(usage);
|
|
|
115 |
System.exit(-1);
|
|
|
116 |
}
|
| 40 |
naveen |
117 |
|
|
|
118 |
if (inputCommand.equals("validate")) {
|
|
|
119 |
String inputCategoryID = args[1];
|
|
|
120 |
if(args.length < 3) {
|
|
|
121 |
System.out.println(usage);
|
|
|
122 |
System.exit(-1);
|
|
|
123 |
}
|
| 37 |
naveen |
124 |
|
| 40 |
naveen |
125 |
String inputFilename = args[2];
|
|
|
126 |
long categoryID = new Long(inputCategoryID).longValue();
|
|
|
127 |
HSLF hslf = new HSLF(categoryID, inputFilename);
|
|
|
128 |
hslf.validateEntity();
|
| 37 |
naveen |
129 |
System.exit(0);
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
if (inputCommand.equals("import")) {
|
|
|
133 |
String inputCategoryID = args[1];
|
|
|
134 |
if(args.length < 3) {
|
|
|
135 |
System.out.println(usage);
|
|
|
136 |
System.exit(-1);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
String inputFilename = args[2];
|
|
|
140 |
long categoryID = new Long(inputCategoryID).longValue();
|
|
|
141 |
HSLF hslf = new HSLF(categoryID, inputFilename);
|
|
|
142 |
hslf.importEntity();
|
|
|
143 |
System.exit(0);
|
|
|
144 |
}
|
| 40 |
naveen |
145 |
|
|
|
146 |
if (inputCommand.equals("show")) {
|
|
|
147 |
String entityID = args[1];
|
|
|
148 |
HSLF hslf = new HSLF();
|
|
|
149 |
hslf.showEntity(new Long(entityID).longValue());
|
|
|
150 |
System.exit(0);
|
|
|
151 |
}
|
| 37 |
naveen |
152 |
|
| 36 |
naveen |
153 |
}
|
|
|
154 |
|
| 37 |
naveen |
155 |
/**
|
|
|
156 |
*
|
|
|
157 |
*/
|
|
|
158 |
public HSLF() {
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
/**
|
|
|
162 |
*
|
|
|
163 |
* @param categoryID
|
|
|
164 |
* @param fileName
|
|
|
165 |
*/
|
|
|
166 |
public HSLF(long categoryID, String fileName) {
|
|
|
167 |
this.categoryID = categoryID;
|
|
|
168 |
|
|
|
169 |
this.srcFile = CONTENT_SRC_PPT_PATH + fileName + ".ppt";
|
|
|
170 |
this.dbFile = CONTENT_DB_PATH + "entities" + ".ser";
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
/**
|
|
|
174 |
*
|
|
|
175 |
* @throws Exception
|
|
|
176 |
*/
|
|
|
177 |
public void showEntity(long entityID) throws Exception {
|
|
|
178 |
EntityContainer entContainer =
|
|
|
179 |
Catalog.getInstance().getEntityContainer();
|
|
|
180 |
|
| 40 |
naveen |
181 |
Entity entity = entContainer.getEntity(entityID);
|
|
|
182 |
Utils.logger.info("Entity=" + entity);
|
|
|
183 |
|
|
|
184 |
/*
|
| 37 |
naveen |
185 |
ExpandedEntity expandedEntity =
|
|
|
186 |
entContainer.getExpandedEntity(entityID);
|
|
|
187 |
|
|
|
188 |
Utils.logger.info("expandedEntity=" + expandedEntity);
|
| 40 |
naveen |
189 |
*/
|
| 37 |
naveen |
190 |
}
|
|
|
191 |
|
| 40 |
naveen |
192 |
/**
|
|
|
193 |
*
|
|
|
194 |
* @throws Exception
|
|
|
195 |
*/
|
|
|
196 |
public void validateEntity() throws Exception {
|
| 37 |
naveen |
197 |
HSLFSlideShow hslfSS = new HSLFSlideShow(this.srcFile);
|
| 36 |
naveen |
198 |
SlideShow ss = new SlideShow(hslfSS);
|
|
|
199 |
Slide[] ssarr = ss.getSlides();
|
| 38 |
naveen |
200 |
|
|
|
201 |
// Introduction page
|
|
|
202 |
this.processIntroductionSlide(ssarr[0]);
|
|
|
203 |
|
|
|
204 |
// Rest of the content page
|
|
|
205 |
for(int i=1; i < ssarr.length; i++) {
|
| 36 |
naveen |
206 |
TextRun[] trs = ssarr[i].getTextRuns();
|
|
|
207 |
|
| 37 |
naveen |
208 |
String title = StringUtils.lowerCase(
|
|
|
209 |
StringUtils.strip(StringUtils.trim(ssarr[i].getTitle())));
|
| 36 |
naveen |
210 |
System.out.println(title);
|
|
|
211 |
|
|
|
212 |
this.slideNames.add(title);
|
|
|
213 |
|
| 40 |
naveen |
214 |
// Hack to get to TextRun where bullets are!
|
| 36 |
naveen |
215 |
TextRun contentTextRun = trs[1];
|
|
|
216 |
RichTextRun[] richTextRuns = contentTextRun.getRichTextRuns();
|
| 40 |
naveen |
217 |
if(richTextRuns.length == 1 && trs.length > 2) {
|
|
|
218 |
contentTextRun = trs[2];
|
|
|
219 |
richTextRuns = contentTextRun.getRichTextRuns();
|
|
|
220 |
}
|
|
|
221 |
|
| 36 |
naveen |
222 |
int startIndex = 0;
|
|
|
223 |
int indent = 1;
|
|
|
224 |
Map<String, Object[]> info = getContents(richTextRuns, startIndex,
|
|
|
225 |
indent);
|
|
|
226 |
|
|
|
227 |
System.out.println(info);
|
|
|
228 |
//System.exit(0);
|
|
|
229 |
|
|
|
230 |
drilldown(richTextRuns, info, indent, title);
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
System.out.println("this.slideNames=" + this.slideNames);
|
|
|
234 |
System.out.println("this.slideNameChildrenSlideNames=" +
|
|
|
235 |
this.slideNameChildrenSlideNames);
|
|
|
236 |
|
| 37 |
naveen |
237 |
System.out.println("this.slideNameFeatureNames=" +
|
|
|
238 |
this.slideNameFeatureNames);
|
|
|
239 |
|
|
|
240 |
System.out.println("this.slideNameFeatureNameBulletTexts=" +
|
|
|
241 |
this.slideNameFeatureNameBulletTexts);
|
|
|
242 |
|
|
|
243 |
System.out.println("this.containerFCCs=" + this.containerFCCs);
|
|
|
244 |
|
|
|
245 |
// Start validation and import
|
|
|
246 |
|
|
|
247 |
// Validate slides
|
|
|
248 |
this.processSlides();
|
|
|
249 |
|
|
|
250 |
// Collect Slide Definition IDs
|
|
|
251 |
this.collectSlideDefinitionIDs();
|
|
|
252 |
Utils.logger.info("this.slideNameSlideDefID=" +
|
|
|
253 |
this.slideNameSlideDefID);
|
|
|
254 |
|
|
|
255 |
// Validate features
|
|
|
256 |
for(String slideName : this.slideNames) {
|
|
|
257 |
this.processFeatures(slideName);
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
// Collect Feature Definition IDs
|
|
|
261 |
this.collectFeatureDefinitionIDs();
|
|
|
262 |
Utils.logger.info("this.slideNameFeatureNameFeatureDefID=" +
|
|
|
263 |
this.slideNameFeatureNameFeatureDefID);
|
|
|
264 |
|
|
|
265 |
DefinitionsContainer defs =
|
|
|
266 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
267 |
|
|
|
268 |
// Validate bullets
|
|
|
269 |
for(String slideName : this.slideNames) {
|
|
|
270 |
|
| 40 |
naveen |
271 |
Long slideDefID = this.slideNameSlideDefID.get(slideName);
|
|
|
272 |
SlideDefinition slideDef =
|
|
|
273 |
defs.getSlideDefinition(slideDefID.longValue());
|
|
|
274 |
|
| 37 |
naveen |
275 |
List<String> featureLabels =
|
|
|
276 |
this.slideNameFeatureNames.get(slideName);
|
|
|
277 |
|
|
|
278 |
// Feature-less slide
|
|
|
279 |
if(featureLabels == null) {
|
|
|
280 |
continue;
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
for(String featureLabel : featureLabels) {
|
|
|
284 |
String key = slideName + "_" + featureLabel;
|
|
|
285 |
List<String> bulletTexts =
|
|
|
286 |
this.slideNameFeatureNameBulletTexts.get(key);
|
|
|
287 |
|
|
|
288 |
// Bullet-less feature
|
|
|
289 |
if(bulletTexts == null) {
|
|
|
290 |
continue;
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
Long featureDefID =
|
|
|
294 |
this.slideNameFeatureNameFeatureDefID.get(key);
|
|
|
295 |
|
|
|
296 |
FeatureDefinition featureDef =
|
|
|
297 |
defs.getFeatureDefinition(featureDefID.longValue());
|
|
|
298 |
|
| 40 |
naveen |
299 |
String crumb = slideDef.getLabel() + " > " +
|
|
|
300 |
featureDef.getLabel();
|
|
|
301 |
|
| 38 |
naveen |
302 |
String prefix = slideName + "_" + featureLabel;
|
| 37 |
naveen |
303 |
for(String bulletText : bulletTexts) {
|
|
|
304 |
Bullet bullet =
|
| 38 |
naveen |
305 |
this.processBulletText(bulletText, featureDef, crumb,
|
|
|
306 |
prefix);
|
| 37 |
naveen |
307 |
|
| 40 |
naveen |
308 |
// Can't be imported has errors, skip
|
| 37 |
naveen |
309 |
if(bullet == null) {
|
|
|
310 |
continue;
|
|
|
311 |
}
|
|
|
312 |
|
|
|
313 |
List<Bullet> bullets =
|
|
|
314 |
this.slideNameFeatureNameBullets.get(key);
|
|
|
315 |
|
|
|
316 |
if(bullets == null) {
|
|
|
317 |
bullets = new ArrayList<Bullet>();
|
|
|
318 |
this.slideNameFeatureNameBullets.put(key, bullets);
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
bullets.add(bullet);
|
|
|
322 |
}
|
|
|
323 |
}
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
Utils.logger.info("this.slideNameFeatureNameBullets=" +
|
|
|
327 |
this.slideNameFeatureNameBullets);
|
| 40 |
naveen |
328 |
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
/**
|
|
|
332 |
*
|
|
|
333 |
* @throws Exception
|
|
|
334 |
*/
|
|
|
335 |
public void importEntity() throws Exception {
|
|
|
336 |
|
|
|
337 |
// Parse and Validate
|
|
|
338 |
this.validateEntity();
|
|
|
339 |
|
| 38 |
naveen |
340 |
// Construct Content Model
|
|
|
341 |
Entity entity = this.contructEntityObject();
|
|
|
342 |
Utils.logger.info("entity="+entity);
|
|
|
343 |
|
|
|
344 |
EntityContainer entContainer =
|
|
|
345 |
Catalog.getInstance().getEntityContainer();
|
|
|
346 |
|
|
|
347 |
entContainer.addEntity(entity);
|
|
|
348 |
|
|
|
349 |
// RE-VISIT
|
|
|
350 |
// Store it back
|
|
|
351 |
DBUtils.store(entContainer.getEntities(), this.dbFile);
|
|
|
352 |
|
|
|
353 |
// Store the index separately
|
|
|
354 |
String entitiesbycategoryDBFile = HSLF.CONTENT_DB_PATH +
|
|
|
355 |
"entitiesbycategory" + ".ser";
|
|
|
356 |
|
|
|
357 |
DBUtils.store(entContainer.getEntitiesbyCategory(),
|
|
|
358 |
entitiesbycategoryDBFile);
|
|
|
359 |
|
| 36 |
naveen |
360 |
}
|
| 38 |
naveen |
361 |
/**
|
|
|
362 |
*
|
|
|
363 |
* @param hslfSlide
|
|
|
364 |
*/
|
|
|
365 |
private void processIntroductionSlide(Slide hslfSlide) {
|
|
|
366 |
TextRun[] trs = hslfSlide.getTextRuns();
|
|
|
367 |
StringBuffer sbTitle = new StringBuffer();
|
|
|
368 |
StringBuffer sbText = new StringBuffer();
|
|
|
369 |
|
|
|
370 |
for(int i=0;i<trs.length;i++) {
|
|
|
371 |
RichTextRun[] rtrs = trs[i].getRichTextRuns();
|
|
|
372 |
|
|
|
373 |
for(int j=0;j<rtrs.length;j++) {
|
|
|
374 |
int rgb = rtrs[j].getFontColor().getRGB();
|
|
|
375 |
if(rgb == HSLF.ORANGE) {
|
|
|
376 |
sbTitle.append(rtrs[j].getRawText());
|
|
|
377 |
}
|
|
|
378 |
else if(rgb == HSLF.PURPLE) {
|
|
|
379 |
sbText.append(rtrs[j].getRawText());
|
|
|
380 |
}
|
|
|
381 |
}
|
|
|
382 |
}
|
|
|
383 |
|
|
|
384 |
this.introductionTitle = sbTitle.toString();
|
|
|
385 |
this.introductionText = sbText.toString();
|
|
|
386 |
Utils.logger.info("this.introductionTitle=" + this.introductionTitle);
|
|
|
387 |
Utils.logger.info("this.introductionText=" + this.introductionText);
|
|
|
388 |
}
|
| 36 |
naveen |
389 |
|
| 37 |
naveen |
390 |
/**
|
|
|
391 |
*
|
| 38 |
naveen |
392 |
* @return Entity
|
|
|
393 |
* @throws Exception
|
|
|
394 |
*/
|
|
|
395 |
private Entity contructEntityObject() throws Exception {
|
|
|
396 |
SequenceGenerator sg = SequenceGenerator.getInstance();
|
|
|
397 |
long entityID = sg.getNextSequence(SequenceGenerator.ENTITY);
|
|
|
398 |
|
|
|
399 |
Entity entity = new Entity(entityID, this.categoryID);
|
|
|
400 |
String brandModel[] = StringUtils.split(this.introductionTitle, " ");
|
|
|
401 |
|
|
|
402 |
if(brandModel.length == 1) {
|
|
|
403 |
entity.setBrand(StringUtils.strip(brandModel[0]));
|
|
|
404 |
}
|
|
|
405 |
else if(brandModel.length == 2) {
|
|
|
406 |
entity.setBrand(StringUtils.strip(brandModel[0]));
|
|
|
407 |
entity.setModelName(StringUtils.strip(brandModel[1]));
|
|
|
408 |
}
|
|
|
409 |
else if(brandModel.length == 3) {
|
|
|
410 |
entity.setBrand(StringUtils.strip(brandModel[0]));
|
|
|
411 |
entity.setModelNumber(StringUtils.strip(brandModel[1]));
|
|
|
412 |
entity.setModelName(StringUtils.strip(brandModel[2]));
|
|
|
413 |
}
|
|
|
414 |
else if(brandModel.length == 4) {
|
|
|
415 |
entity.setBrand(StringUtils.strip(brandModel[0]) + " " +
|
|
|
416 |
StringUtils.strip(brandModel[1]));
|
|
|
417 |
|
|
|
418 |
entity.setModelNumber(StringUtils.strip(brandModel[2]));
|
|
|
419 |
entity.setModelName(StringUtils.strip(brandModel[3]));
|
|
|
420 |
}
|
|
|
421 |
|
|
|
422 |
// Add introduction slide
|
|
|
423 |
DefinitionsContainer defs =
|
|
|
424 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
425 |
|
|
|
426 |
List<SlideDefinition> introSlideDefs =
|
| 40 |
naveen |
427 |
defs.getSlideDefinitions(this.categoryID, "Introduction");
|
| 38 |
naveen |
428 |
|
|
|
429 |
// It will only be one
|
|
|
430 |
long introSlideDefID = introSlideDefs.get(0).getID();
|
|
|
431 |
Utils.logger.info("introSlideDefID=" + introSlideDefID);
|
|
|
432 |
|
|
|
433 |
in.shop2020.metamodel.core.Slide introSlide =
|
|
|
434 |
new in.shop2020.metamodel.core.Slide(introSlideDefID);
|
|
|
435 |
|
|
|
436 |
introSlide.setFreeformContent(
|
|
|
437 |
new FreeformContent(this.introductionText));
|
|
|
438 |
Utils.logger.info("introSlide=" + introSlide);
|
| 40 |
naveen |
439 |
|
|
|
440 |
entity.addSlide(introSlide);
|
| 38 |
naveen |
441 |
|
|
|
442 |
// Add rest of the slides
|
|
|
443 |
for(String slideName : this.slideNames) {
|
|
|
444 |
List<String> featureNames =
|
|
|
445 |
this.slideNameFeatureNames.get(slideName);
|
|
|
446 |
|
|
|
447 |
Long slideDefID = this.slideNameSlideDefID.get(slideName);
|
|
|
448 |
in.shop2020.metamodel.core.Slide slide =
|
|
|
449 |
new in.shop2020.metamodel.core.Slide(slideDefID.longValue());
|
|
|
450 |
|
|
|
451 |
// Only if there are features
|
|
|
452 |
if(featureNames == null) {
|
|
|
453 |
continue;
|
|
|
454 |
}
|
|
|
455 |
|
|
|
456 |
List<Feature> features = new ArrayList<Feature>();
|
|
|
457 |
|
|
|
458 |
for(String featureName : featureNames) {
|
|
|
459 |
String key = slideName + "_" + featureName;
|
|
|
460 |
Long featureDefID =
|
|
|
461 |
this.slideNameFeatureNameFeatureDefID.get(key);
|
|
|
462 |
|
|
|
463 |
List<Bullet> bullets =
|
|
|
464 |
this.slideNameFeatureNameBullets.get(key);
|
|
|
465 |
|
|
|
466 |
Feature feature = new Feature(featureDefID.longValue());
|
|
|
467 |
feature.setBullets(bullets);
|
|
|
468 |
|
|
|
469 |
// Free-form content
|
|
|
470 |
List<String> featureFFCs = this.containerFCCs.get(key);
|
|
|
471 |
FreeformContent featureFFC =
|
|
|
472 |
new FreeformContent(StringUtils.join(featureFFCs, "|"));
|
|
|
473 |
|
|
|
474 |
feature.setFreeformContent(featureFFC);
|
|
|
475 |
|
|
|
476 |
features.add(feature);
|
|
|
477 |
}
|
|
|
478 |
|
|
|
479 |
slide.setFeatures(features);
|
|
|
480 |
|
|
|
481 |
// Add free-form content is collect above
|
|
|
482 |
List<String> slideFFCs = this.containerFCCs.get(slideName);
|
|
|
483 |
Utils.logger.info("slideName=" + slideName +
|
|
|
484 |
" slideFFCs=" + slideFFCs);
|
|
|
485 |
|
|
|
486 |
FreeformContent slideFFC =
|
|
|
487 |
new FreeformContent(StringUtils.join(slideFFCs, "|"));
|
|
|
488 |
|
|
|
489 |
slide.setFreeformContent(slideFFC);
|
|
|
490 |
|
|
|
491 |
entity.addSlide(slide);
|
|
|
492 |
}
|
|
|
493 |
|
|
|
494 |
return entity;
|
|
|
495 |
}
|
|
|
496 |
|
|
|
497 |
/**
|
|
|
498 |
*
|
| 37 |
naveen |
499 |
* @throws Exception
|
|
|
500 |
*/
|
|
|
501 |
private void collectFeatureDefinitionIDs() throws Exception {
|
|
|
502 |
DefinitionsContainer defs =
|
|
|
503 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
504 |
|
|
|
505 |
for(String slideName : this.slideNames) {
|
|
|
506 |
Long slideDefID = this.slideNameSlideDefID.get(slideName);
|
|
|
507 |
Utils.logger.info("slideName=" + slideName);
|
|
|
508 |
|
|
|
509 |
List<String> featureLabels =
|
|
|
510 |
this.slideNameFeatureNames.get(slideName);
|
|
|
511 |
Utils.logger.info("featureLabels=" + featureLabels);
|
|
|
512 |
|
|
|
513 |
// Feature-less slide
|
|
|
514 |
if(featureLabels == null) {
|
|
|
515 |
continue;
|
|
|
516 |
}
|
|
|
517 |
|
|
|
518 |
for(String featureLabel : featureLabels) {
|
|
|
519 |
FeatureDefinition featureDef =
|
|
|
520 |
defs.getFeatureDefinition(slideDefID, featureLabel);
|
|
|
521 |
String key = slideName + "_" + featureLabel;
|
|
|
522 |
|
|
|
523 |
this.slideNameFeatureNameFeatureDefID.put(key,
|
|
|
524 |
new Long(featureDef.getID()));
|
|
|
525 |
}
|
|
|
526 |
}
|
|
|
527 |
}
|
|
|
528 |
|
|
|
529 |
/**
|
|
|
530 |
*
|
|
|
531 |
* @throws Exception
|
|
|
532 |
*/
|
|
|
533 |
private void collectSlideDefinitionIDs() throws Exception {
|
|
|
534 |
DefinitionsContainer defs =
|
|
|
535 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
536 |
|
|
|
537 |
for(String slideName : this.slideNames) {
|
|
|
538 |
List<SlideDefinition> slideDefs =
|
|
|
539 |
defs.getSlideDefinitions(this.categoryID, slideName);
|
|
|
540 |
|
|
|
541 |
if(slideDefs == null) {
|
|
|
542 |
continue;
|
|
|
543 |
}
|
|
|
544 |
|
|
|
545 |
if (slideDefs.isEmpty()) {
|
|
|
546 |
continue;
|
|
|
547 |
}
|
|
|
548 |
|
|
|
549 |
// RE-VISIT
|
|
|
550 |
// Pick the first
|
|
|
551 |
SlideDefinition slideDef = slideDefs.get(0);
|
|
|
552 |
//Utils.logger.info("slideDef=" + slideDef);
|
|
|
553 |
|
|
|
554 |
Long slideID = slideDef.getID();
|
|
|
555 |
this.slideNameSlideDefID.put(slideName, slideID);
|
|
|
556 |
}
|
|
|
557 |
}
|
|
|
558 |
|
|
|
559 |
/**
|
|
|
560 |
*
|
|
|
561 |
* @param allLines
|
|
|
562 |
* @param slideDef
|
|
|
563 |
* @param lineNumberRange
|
|
|
564 |
* @throws Exception
|
|
|
565 |
*/
|
|
|
566 |
private void processFeatures(String slideName)
|
|
|
567 |
throws Exception {
|
|
|
568 |
|
|
|
569 |
long slideDefID = this.slideNameSlideDefID.get(slideName).longValue();
|
|
|
570 |
Utils.logger.info("slideID=" + slideDefID);
|
|
|
571 |
|
|
|
572 |
List<String> candidateFeatures =
|
|
|
573 |
this.slideNameFeatureNames.get(slideName);
|
|
|
574 |
|
|
|
575 |
Utils.logger.info("slideName=" + slideName);
|
|
|
576 |
Utils.logger.info("candidateFeatures=" + candidateFeatures);
|
|
|
577 |
|
|
|
578 |
// Feature less slide
|
|
|
579 |
if(candidateFeatures == null) {
|
|
|
580 |
return;
|
|
|
581 |
}
|
|
|
582 |
|
|
|
583 |
// Get all feature definitions for the slide
|
|
|
584 |
DefinitionsContainer defs =
|
|
|
585 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
586 |
|
|
|
587 |
SlideDefinition slideDef = defs.getSlideDefinition(slideDefID);
|
|
|
588 |
Utils.logger.info("slideDef=" + slideDef);
|
|
|
589 |
|
|
|
590 |
List<FeatureDefinition> featureDefs =
|
|
|
591 |
defs.getFeatureDefinitions(slideDefID);
|
|
|
592 |
Utils.logger.info("featureDefs=" + featureDefs);
|
|
|
593 |
|
|
|
594 |
List<String> validFeatureLabels = new ArrayList<String>();
|
|
|
595 |
for(int i=0; i<featureDefs.size(); i++) {
|
|
|
596 |
validFeatureLabels.add(
|
|
|
597 |
StringUtils.lowerCase(featureDefs.get(i).getLabel()));
|
|
|
598 |
|
|
|
599 |
}
|
|
|
600 |
Utils.logger.info("validFeatureLabels=" + validFeatureLabels);
|
|
|
601 |
|
|
|
602 |
// Discard if feature is not one of the valids
|
|
|
603 |
List<String> processedFeatureLabels = new ArrayList<String>();
|
|
|
604 |
for(String featureLabel : candidateFeatures) {
|
|
|
605 |
|
|
|
606 |
if(validFeatureLabels.contains(featureLabel)) {
|
|
|
607 |
processedFeatureLabels.add(featureLabel);
|
|
|
608 |
}
|
|
|
609 |
else {
|
| 40 |
naveen |
610 |
Utils.logger.severe("Invalid feature \"" + slideDef.getLabel() +
|
|
|
611 |
" > " + featureLabel + "\"");
|
| 37 |
naveen |
612 |
}
|
|
|
613 |
|
|
|
614 |
}
|
|
|
615 |
Utils.logger.info("processedFeatureLabels=" + processedFeatureLabels);
|
|
|
616 |
|
|
|
617 |
// For all further processing
|
|
|
618 |
this.slideNameFeatureNames.put(slideName, processedFeatureLabels);
|
|
|
619 |
|
|
|
620 |
// Fetch all mandatory features
|
|
|
621 |
List<FeatureDefinition> mandatoryFeatureDefs =
|
|
|
622 |
defs.getFeatureDefinitions(slideDefID,
|
|
|
623 |
EditorialImportance.MANDATORY);
|
|
|
624 |
|
|
|
625 |
Utils.logger.info("mandatoryFeatureDefs=" + mandatoryFeatureDefs);
|
|
|
626 |
|
|
|
627 |
// Severe error if mandatory features are not included
|
|
|
628 |
for(FeatureDefinition featureDef : mandatoryFeatureDefs) {
|
|
|
629 |
if(!processedFeatureLabels.contains(StringUtils.lowerCase(
|
|
|
630 |
featureDef.getLabel()))) {
|
|
|
631 |
Utils.logger.severe("Mandatory feature \"" + slideDef.getLabel()
|
|
|
632 |
+ " > " + featureDef.getLabel() + "\" is missing");
|
|
|
633 |
}
|
|
|
634 |
}
|
|
|
635 |
|
|
|
636 |
// Fetch all recommended features
|
|
|
637 |
List<FeatureDefinition> recommendedFeatureDefs =
|
|
|
638 |
defs.getFeatureDefinitions(slideDef.getID(),
|
|
|
639 |
EditorialImportance.RECOMMENDED);
|
|
|
640 |
|
|
|
641 |
Utils.logger.info("recommendedFeatureDefs=" + recommendedFeatureDefs);
|
|
|
642 |
|
|
|
643 |
// Warn if recommended features are not included
|
|
|
644 |
for(FeatureDefinition featureDef : recommendedFeatureDefs) {
|
|
|
645 |
if(!processedFeatureLabels.contains(StringUtils.lowerCase(
|
|
|
646 |
featureDef.getLabel()))) {
|
|
|
647 |
Utils.logger.warning("Recommended feature \"" +
|
|
|
648 |
slideDef.getLabel() + " > " + featureDef.getLabel() +
|
|
|
649 |
"\" is missing");
|
|
|
650 |
}
|
|
|
651 |
}
|
|
|
652 |
}
|
|
|
653 |
|
|
|
654 |
/**
|
|
|
655 |
* Filter and validate parent slide names
|
|
|
656 |
*
|
|
|
657 |
* @throws Exception
|
|
|
658 |
*/
|
|
|
659 |
private void processSlides() throws Exception {
|
|
|
660 |
|
|
|
661 |
// 1 Retrieve meta-data
|
|
|
662 |
// 1.1 Retrieve all valid slide names in the content model
|
|
|
663 |
DefinitionsContainer defs =
|
|
|
664 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
665 |
|
|
|
666 |
List<SlideDefinition> slideDefs = defs.getSlideDefinitions(
|
|
|
667 |
this.categoryID);
|
|
|
668 |
|
|
|
669 |
List<String> validSlideNames = new ArrayList<String>();
|
|
|
670 |
for (SlideDefinition slideDef : slideDefs) {
|
|
|
671 |
|
|
|
672 |
// To avoid Introduction slide
|
|
|
673 |
if(!slideDef.getLabel().isEmpty()) {
|
|
|
674 |
validSlideNames.add(StringUtils.lowerCase(slideDef.getLabel()));
|
|
|
675 |
}
|
|
|
676 |
}
|
|
|
677 |
Utils.logger.info("validSlideNames=" + validSlideNames.toString());
|
|
|
678 |
|
|
|
679 |
// 2 Rules
|
|
|
680 |
// 2.1 Discard if slide is not one of the valids
|
|
|
681 |
List<String> processedSlideNames = new ArrayList<String>();
|
|
|
682 |
for(String slideName : this.slideNames) {
|
|
|
683 |
if(validSlideNames.contains(slideName)) {
|
|
|
684 |
processedSlideNames.add(slideName);
|
|
|
685 |
}
|
| 40 |
naveen |
686 |
else if(slideName.equals("resource urls") ||
|
|
|
687 |
slideName.equals("reference urls")) {
|
|
|
688 |
// ignore
|
|
|
689 |
continue;
|
|
|
690 |
}
|
| 37 |
naveen |
691 |
else {
|
|
|
692 |
Utils.logger.severe("Invalid slide \"" + slideName + "\"");
|
|
|
693 |
}
|
|
|
694 |
}
|
|
|
695 |
|
|
|
696 |
Utils.logger.info("processedSlideNames=" +
|
|
|
697 |
processedSlideNames.toString());
|
|
|
698 |
|
|
|
699 |
// For all further processing use processed slide names only
|
|
|
700 |
this.slideNames = processedSlideNames;
|
|
|
701 |
|
|
|
702 |
// 3 Retrieve "Mandatory" slide names for the category
|
|
|
703 |
List<SlideDefinition> mandatorySlideDefs =
|
|
|
704 |
defs.getSlides(this.categoryID, EditorialImportance.MANDATORY);
|
|
|
705 |
|
|
|
706 |
Utils.logger.info("mandatorySlideDefs=" +
|
|
|
707 |
mandatorySlideDefs.toString());
|
|
|
708 |
|
|
|
709 |
// 3.1 All mandatory slides exist - Severe
|
|
|
710 |
for(SlideDefinition mandatorySlideDef : mandatorySlideDefs) {
|
|
|
711 |
|
|
|
712 |
// Avoid introduction slide
|
|
|
713 |
if(mandatorySlideDef.getLabel().isEmpty()) {
|
|
|
714 |
continue;
|
|
|
715 |
}
|
|
|
716 |
|
| 40 |
naveen |
717 |
if(mandatorySlideDef.getLabel().equals("Introduction")) {
|
|
|
718 |
continue;
|
|
|
719 |
}
|
|
|
720 |
|
| 37 |
naveen |
721 |
if(!this.slideNames.contains(
|
|
|
722 |
StringUtils.lowerCase(mandatorySlideDef.getLabel()))) {
|
|
|
723 |
|
|
|
724 |
Utils.logger.severe("Mandatory slide \"" +
|
|
|
725 |
mandatorySlideDef.getLabel() + "\" is missing");
|
|
|
726 |
}
|
|
|
727 |
}
|
|
|
728 |
|
|
|
729 |
// 4 Retrieve "Recommended" slide names for the category
|
|
|
730 |
List<SlideDefinition> recommendedSlideDefs =
|
|
|
731 |
defs.getSlides(this.categoryID, EditorialImportance.RECOMMENDED);
|
|
|
732 |
|
|
|
733 |
Utils.logger.info("recommendedSlideDefs=" +
|
|
|
734 |
recommendedSlideDefs.toString());
|
|
|
735 |
|
|
|
736 |
// 4.1 All recommended slides exist - Warn
|
|
|
737 |
for(SlideDefinition recommendedSlideDef : recommendedSlideDefs) {
|
|
|
738 |
if(!this.slideNames.contains(
|
|
|
739 |
StringUtils.lowerCase(recommendedSlideDef.getLabel()))) {
|
|
|
740 |
|
|
|
741 |
Utils.logger.warning("Recommended slide \"" +
|
|
|
742 |
recommendedSlideDef.getLabel() + "\" is missing");
|
|
|
743 |
}
|
|
|
744 |
}
|
|
|
745 |
}
|
|
|
746 |
|
|
|
747 |
/**
|
|
|
748 |
*
|
|
|
749 |
* @param bulletText
|
|
|
750 |
* @return Bullet
|
|
|
751 |
* @throws Exception
|
|
|
752 |
*/
|
|
|
753 |
private Bullet processBulletText(String bulletText,
|
| 38 |
naveen |
754 |
FeatureDefinition featureDef, String crumb, String prefix)
|
|
|
755 |
throws Exception {
|
| 40 |
naveen |
756 |
Utils.logger.info("featureDef.getLabel=" + featureDef.getLabel());
|
|
|
757 |
Utils.logger.info("bulletText=" + bulletText);
|
|
|
758 |
|
| 37 |
naveen |
759 |
BulletDefinition bulletDef = featureDef.getBulletDefinition();
|
|
|
760 |
Utils.logger.info("bulletDefinition=" + bulletDef);
|
|
|
761 |
|
|
|
762 |
DefinitionsContainer defs =
|
|
|
763 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
764 |
|
|
|
765 |
// If unit is defined
|
|
|
766 |
Unit unitDef = null;
|
|
|
767 |
if(bulletDef.getUnitID() != 0L) {
|
|
|
768 |
long unitID = bulletDef.getUnitID();
|
|
|
769 |
unitDef = defs.getUnit(unitID);
|
|
|
770 |
Utils.logger.info("unitDef=" + unitDef);
|
|
|
771 |
}
|
|
|
772 |
|
|
|
773 |
long datatypeDefID = bulletDef.getDatatypeDefinitionID();
|
|
|
774 |
DatatypeDefinition datatypeDef =
|
|
|
775 |
defs.getDatatypeDefinition(datatypeDefID);
|
|
|
776 |
Utils.logger.info("datatypeDef=" + datatypeDef);
|
|
|
777 |
|
|
|
778 |
// If primitive
|
|
|
779 |
boolean isEnum = false;
|
|
|
780 |
boolean isComposite = false;
|
|
|
781 |
boolean isPrimitive = false;
|
|
|
782 |
if(datatypeDef instanceof EnumDefinition) {
|
|
|
783 |
isEnum = true;
|
|
|
784 |
}
|
|
|
785 |
else if(datatypeDef instanceof CompositeDefinition) {
|
|
|
786 |
isComposite = true;
|
|
|
787 |
}
|
|
|
788 |
else {
|
|
|
789 |
isPrimitive = true;
|
|
|
790 |
}
|
|
|
791 |
|
|
|
792 |
Utils.logger.info("isEnum=" + isEnum + " isComposite=" + isComposite +
|
|
|
793 |
" isPrimitive=" + isPrimitive);
|
|
|
794 |
|
|
|
795 |
// if no unit is defined for this bullet whole is treated as value
|
|
|
796 |
String bulletValue = bulletText;
|
|
|
797 |
Bullet bullet = null;
|
|
|
798 |
|
|
|
799 |
// If unit is defined
|
|
|
800 |
if(bulletDef.getUnitID() != 0L) {
|
|
|
801 |
|
|
|
802 |
// Validate unit
|
|
|
803 |
String[] parts = StringUtils.split(bulletText, " ");
|
|
|
804 |
if(parts.length < 2) {
|
| 40 |
naveen |
805 |
Utils.logger.severe("Unit is missing, \"" + crumb + "\" = " +
|
| 37 |
naveen |
806 |
bulletText);
|
|
|
807 |
|
|
|
808 |
return null;
|
|
|
809 |
}
|
|
|
810 |
|
|
|
811 |
else if(parts.length > 2) {
|
| 40 |
naveen |
812 |
Utils.logger.severe("Invalid value, \"" + crumb + "\" = " +
|
| 37 |
naveen |
813 |
bulletText);
|
|
|
814 |
|
|
|
815 |
return null;
|
|
|
816 |
}
|
|
|
817 |
|
|
|
818 |
bulletValue = parts[0];
|
|
|
819 |
String unitValue = parts[1];
|
|
|
820 |
Utils.logger.info("unitValue="+unitValue);
|
|
|
821 |
|
|
|
822 |
if(!(unitValue.equalsIgnoreCase(unitDef.getShortForm()) ||
|
|
|
823 |
unitValue.equalsIgnoreCase(unitDef.getFullForm()))) {
|
|
|
824 |
|
| 40 |
naveen |
825 |
Utils.logger.severe("Invalid unit, \"" + crumb + "\" = " +
|
| 37 |
naveen |
826 |
bulletText);
|
|
|
827 |
|
|
|
828 |
}
|
|
|
829 |
}
|
|
|
830 |
|
|
|
831 |
// Validate bullet value
|
|
|
832 |
Utils.logger.info("bulletValue=" + bulletValue);
|
|
|
833 |
if(isPrimitive) {
|
|
|
834 |
if(!this.validatePrimitive(bulletValue, datatypeDef, crumb)) {
|
|
|
835 |
return null;
|
|
|
836 |
}
|
|
|
837 |
|
|
|
838 |
bullet = new Bullet(new PrimitiveDataObject(bulletValue));
|
|
|
839 |
}
|
|
|
840 |
|
|
|
841 |
// Enum and fixed
|
|
|
842 |
else if(isEnum && !bulletDef.isLearned()) {
|
|
|
843 |
long enumValueID = defs.getEnumValueID(datatypeDef.getID(),
|
|
|
844 |
bulletValue);
|
|
|
845 |
Utils.logger.info("enumValueID=" + enumValueID);
|
|
|
846 |
|
|
|
847 |
// Treat it to be free-form
|
|
|
848 |
if(enumValueID == -1L) {
|
| 40 |
naveen |
849 |
Utils.logger.severe("Not one of the valid enum values, \"" +
|
|
|
850 |
crumb + "\" = " + bulletValue);
|
| 37 |
naveen |
851 |
|
|
|
852 |
return null;
|
|
|
853 |
}
|
|
|
854 |
|
|
|
855 |
EnumDataObject enumDataObject = new EnumDataObject(enumValueID);
|
|
|
856 |
bullet = new Bullet(enumDataObject);
|
|
|
857 |
}
|
|
|
858 |
|
|
|
859 |
// Composite
|
|
|
860 |
else if(isComposite) {
|
|
|
861 |
CompositeDefinition compositeDef =
|
|
|
862 |
(CompositeDefinition)datatypeDef;
|
|
|
863 |
|
|
|
864 |
String separator = compositeDef.getSeparator();
|
|
|
865 |
String[] compositeParts =
|
|
|
866 |
StringUtils.split(bulletValue, separator);
|
|
|
867 |
|
|
|
868 |
List<CompositePartDefinition> compositePartDefs =
|
|
|
869 |
compositeDef.getCompositePartDefinitions();
|
|
|
870 |
|
|
|
871 |
// Validate number of parts
|
|
|
872 |
if(compositeParts.length != compositePartDefs.size()) {
|
|
|
873 |
Utils.logger.severe("Invalid value, " + crumb + " = " +
|
|
|
874 |
bulletValue);
|
|
|
875 |
|
|
|
876 |
return null;
|
|
|
877 |
}
|
|
|
878 |
|
|
|
879 |
// Remove spurious whitespaces
|
|
|
880 |
boolean validPart = true;
|
|
|
881 |
for(int j=0;j<compositeParts.length;j++) {
|
|
|
882 |
compositeParts[j] = StringUtils.strip(compositeParts[j]);
|
|
|
883 |
Utils.logger.info("compositeParts["+ j + "]=" +
|
|
|
884 |
compositeParts[j]);
|
|
|
885 |
|
|
|
886 |
// Validate each part
|
|
|
887 |
// Each part can be enum or composite in itself
|
|
|
888 |
// We will stick to primitive for now
|
|
|
889 |
long partDatatypeDefID =
|
|
|
890 |
compositePartDefs.get(j).getDatatypeDefinitionID();
|
|
|
891 |
|
|
|
892 |
DatatypeDefinition partDatatypeDef =
|
|
|
893 |
defs.getDatatypeDefinition(partDatatypeDefID);
|
|
|
894 |
Utils.logger.info("partDatatypeDef=" + partDatatypeDef);
|
|
|
895 |
|
|
|
896 |
if(!this.validatePrimitive(compositeParts[j],
|
|
|
897 |
partDatatypeDef, crumb)) {
|
|
|
898 |
validPart = false;
|
|
|
899 |
break;
|
|
|
900 |
}
|
|
|
901 |
}
|
|
|
902 |
|
|
|
903 |
if(!validPart) {
|
|
|
904 |
return null;
|
|
|
905 |
}
|
|
|
906 |
|
|
|
907 |
CompositeDataObject compositeDataObject =
|
|
|
908 |
new CompositeDataObject();
|
|
|
909 |
|
|
|
910 |
for(int j=0;j<compositeParts.length;j++) {
|
|
|
911 |
compositeDataObject.addPrimitiveDataObject(
|
|
|
912 |
new PrimitiveDataObject(compositeParts[j]));
|
|
|
913 |
}
|
|
|
914 |
|
|
|
915 |
bullet = new Bullet(compositeDataObject);
|
|
|
916 |
}
|
|
|
917 |
|
| 38 |
naveen |
918 |
// Free-form content at bullet level
|
|
|
919 |
String key = prefix + "_" + bulletText;
|
|
|
920 |
List<String> bulletFFCs = this.containerFCCs.get(key);
|
|
|
921 |
bullet.setFreeformContent(new FreeformContent(StringUtils.join(
|
|
|
922 |
bulletFFCs, "|")));
|
|
|
923 |
|
| 37 |
naveen |
924 |
return bullet;
|
|
|
925 |
}
|
|
|
926 |
|
|
|
927 |
|
|
|
928 |
/**
|
|
|
929 |
*
|
|
|
930 |
* @param bulletValue
|
|
|
931 |
* @param datatypeDef
|
|
|
932 |
* @param crumb
|
|
|
933 |
*/
|
|
|
934 |
private boolean validatePrimitive(String bulletValue,
|
|
|
935 |
DatatypeDefinition datatypeDef, String crumb) {
|
|
|
936 |
String dt = datatypeDef.getName();
|
|
|
937 |
|
|
|
938 |
// integer
|
|
|
939 |
if(dt.equals("integer")) {
|
|
|
940 |
try {
|
|
|
941 |
Integer.parseInt(bulletValue);
|
|
|
942 |
}
|
|
|
943 |
catch(NumberFormatException nfe) {
|
| 40 |
naveen |
944 |
Utils.logger.severe("Invalid integer value, \"" + crumb +
|
|
|
945 |
"\" = " + bulletValue);
|
| 39 |
naveen |
946 |
return false;
|
| 37 |
naveen |
947 |
}
|
|
|
948 |
}
|
|
|
949 |
|
|
|
950 |
// decimal
|
| 39 |
naveen |
951 |
else if(dt.equals("decimal")) {
|
| 37 |
naveen |
952 |
try {
|
|
|
953 |
Float.parseFloat(bulletValue);
|
|
|
954 |
}
|
|
|
955 |
catch(NumberFormatException nfe) {
|
| 40 |
naveen |
956 |
Utils.logger.severe("Invalid decimal value, \"" + crumb +
|
|
|
957 |
"\" = " + bulletValue);
|
| 39 |
naveen |
958 |
return false;
|
| 37 |
naveen |
959 |
}
|
|
|
960 |
}
|
|
|
961 |
|
| 39 |
naveen |
962 |
// hours_mins e.g. 2 hours 40 mins
|
|
|
963 |
else if(dt.equals("hours_mins")) {
|
|
|
964 |
String[] parts = StringUtils.split(bulletValue, " ");
|
|
|
965 |
if(!(parts.length == 2 || parts.length == 4)) {
|
|
|
966 |
return false;
|
|
|
967 |
}
|
|
|
968 |
// parts[0]
|
|
|
969 |
try {
|
|
|
970 |
Integer.parseInt(StringUtils.strip(parts[0]));
|
|
|
971 |
}
|
|
|
972 |
catch (NumberFormatException nfe) {
|
| 40 |
naveen |
973 |
Utils.logger.severe("Invalid value, \"" + crumb +
|
|
|
974 |
"\" = " + bulletValue);
|
| 39 |
naveen |
975 |
return false;
|
|
|
976 |
}
|
|
|
977 |
|
|
|
978 |
// parts[1]
|
|
|
979 |
if(!parts[1].equalsIgnoreCase("hours")) {
|
| 40 |
naveen |
980 |
Utils.logger.severe("Invalid value, \"" + crumb +
|
|
|
981 |
"\" = " + bulletValue);
|
| 39 |
naveen |
982 |
return false;
|
|
|
983 |
}
|
|
|
984 |
|
|
|
985 |
if(parts.length == 4) {
|
|
|
986 |
// parts[2]
|
|
|
987 |
try {
|
|
|
988 |
Integer.parseInt(StringUtils.strip(parts[2]));
|
|
|
989 |
}
|
|
|
990 |
catch (NumberFormatException nfe) {
|
| 40 |
naveen |
991 |
Utils.logger.severe("Invalid value, \"" + crumb +
|
|
|
992 |
"\" = " + bulletValue);
|
| 39 |
naveen |
993 |
return false;
|
|
|
994 |
}
|
|
|
995 |
|
|
|
996 |
// parts[3]
|
|
|
997 |
if(!parts[1].equalsIgnoreCase("mins")) {
|
| 40 |
naveen |
998 |
Utils.logger.severe("Invalid value, \"" + crumb +
|
|
|
999 |
"\" = " + bulletValue);
|
| 39 |
naveen |
1000 |
return false;
|
|
|
1001 |
}
|
|
|
1002 |
}
|
|
|
1003 |
}
|
|
|
1004 |
|
|
|
1005 |
// days_hours e.g. 9 days 14 hours
|
|
|
1006 |
else if(dt.equals("days_hours")) {
|
|
|
1007 |
String[] parts = StringUtils.split(bulletValue, " ");
|
|
|
1008 |
if(!(parts.length == 2 || parts.length == 4)) {
|
|
|
1009 |
return false;
|
|
|
1010 |
}
|
|
|
1011 |
|
|
|
1012 |
// parts[0]
|
|
|
1013 |
try {
|
|
|
1014 |
Integer.parseInt(StringUtils.strip(parts[0]));
|
|
|
1015 |
}
|
|
|
1016 |
catch (NumberFormatException nfe) {
|
| 40 |
naveen |
1017 |
Utils.logger.severe("Invalid value, \"" + crumb +
|
|
|
1018 |
"\" = " + bulletValue);
|
| 39 |
naveen |
1019 |
return false;
|
|
|
1020 |
}
|
|
|
1021 |
|
|
|
1022 |
// parts[1]
|
|
|
1023 |
if(!parts[1].equalsIgnoreCase("days")) {
|
| 40 |
naveen |
1024 |
Utils.logger.severe("Invalid value, \"" + crumb +
|
|
|
1025 |
"\" = " + bulletValue);
|
| 39 |
naveen |
1026 |
return false;
|
|
|
1027 |
}
|
|
|
1028 |
|
|
|
1029 |
if(parts.length == 4) {
|
|
|
1030 |
// parts[2]
|
|
|
1031 |
try {
|
|
|
1032 |
Integer.parseInt(StringUtils.strip(parts[2]));
|
|
|
1033 |
}
|
|
|
1034 |
catch (NumberFormatException nfe) {
|
| 40 |
naveen |
1035 |
Utils.logger.severe("Invalid value, \"" + crumb +
|
|
|
1036 |
"\" = " + bulletValue);
|
| 39 |
naveen |
1037 |
return false;
|
|
|
1038 |
}
|
|
|
1039 |
|
|
|
1040 |
// parts[3]
|
|
|
1041 |
if(!parts[1].equalsIgnoreCase("hours")) {
|
| 40 |
naveen |
1042 |
Utils.logger.severe("Invalid value, \"" + crumb +
|
|
|
1043 |
"\" = " + bulletValue);
|
| 39 |
naveen |
1044 |
return false;
|
|
|
1045 |
}
|
|
|
1046 |
}
|
|
|
1047 |
}
|
|
|
1048 |
|
|
|
1049 |
return true;
|
| 37 |
naveen |
1050 |
}
|
|
|
1051 |
|
|
|
1052 |
/**
|
|
|
1053 |
*
|
|
|
1054 |
* @param richTextRuns
|
|
|
1055 |
* @param info
|
|
|
1056 |
* @param indent
|
|
|
1057 |
* @param prefix
|
|
|
1058 |
*/
|
| 36 |
naveen |
1059 |
@SuppressWarnings("unchecked")
|
|
|
1060 |
private void drilldown(RichTextRun[] richTextRuns,
|
| 37 |
naveen |
1061 |
Map<String, Object[]> info, int indent, String prefix) {
|
| 36 |
naveen |
1062 |
System.out.println("drilldown");
|
|
|
1063 |
//System.exit(0);
|
|
|
1064 |
|
|
|
1065 |
|
| 40 |
naveen |
1066 |
Object[] featuresInfo = info.get("features");
|
|
|
1067 |
if(featuresInfo != null) {
|
|
|
1068 |
List<String> featureLabels = (List<String>) featuresInfo[0];
|
|
|
1069 |
List<Integer> featureIndices = (List<Integer>) featuresInfo[1];
|
|
|
1070 |
System.out.println("featureLabels=" + featureLabels);
|
|
|
1071 |
System.out.println("featureIndices=" + featureIndices);
|
| 36 |
naveen |
1072 |
|
| 40 |
naveen |
1073 |
System.out.println("processing features");
|
|
|
1074 |
for(int i=0;i<featureLabels.size();i++) {
|
|
|
1075 |
String featureLabel = featureLabels.get(i);
|
|
|
1076 |
System.out.println("featureLabel="+featureLabel);
|
|
|
1077 |
|
|
|
1078 |
featureLabels.set(i, StringUtils.lowerCase(
|
|
|
1079 |
StringUtils.strip(StringUtils.trim(featureLabel))));
|
|
|
1080 |
|
|
|
1081 |
int contentStartIndex = featureIndices.get(i) + 1;
|
|
|
1082 |
int contentIndent = indent + 1;
|
|
|
1083 |
|
|
|
1084 |
Map<String, Object[]> info1 =
|
|
|
1085 |
getContents(richTextRuns, contentStartIndex, contentIndent);
|
|
|
1086 |
|
|
|
1087 |
String newprefix = StringUtils.lowerCase(prefix + "_" +
|
|
|
1088 |
featureLabel);
|
|
|
1089 |
|
|
|
1090 |
drilldown(richTextRuns, info1, contentIndent, newprefix);
|
|
|
1091 |
}
|
| 36 |
naveen |
1092 |
|
| 40 |
naveen |
1093 |
if(featureLabels.size() > 0) {
|
|
|
1094 |
this.slideNameFeatureNames.put(prefix, featureLabels);
|
|
|
1095 |
}
|
| 36 |
naveen |
1096 |
}
|
|
|
1097 |
//System.exit(0);
|
|
|
1098 |
|
| 40 |
naveen |
1099 |
|
|
|
1100 |
Object[] bulletsInfo = info.get("bullets");
|
|
|
1101 |
if(bulletsInfo != null) {
|
|
|
1102 |
List<String> bulletLabels = (List<String>) bulletsInfo[0];
|
|
|
1103 |
List<Integer> bulletIndices = (List<Integer>) bulletsInfo[1];
|
|
|
1104 |
System.out.println("bulletLabels=" + bulletLabels);
|
|
|
1105 |
System.out.println("bulletIndices=" + bulletIndices);
|
| 36 |
naveen |
1106 |
|
| 40 |
naveen |
1107 |
System.out.println("processing bullets");
|
|
|
1108 |
for(int i=0;i<bulletLabels.size();i++) {
|
|
|
1109 |
String bulletLabel = bulletLabels.get(i);
|
|
|
1110 |
System.out.println("bulletLabel="+bulletLabel);
|
|
|
1111 |
|
|
|
1112 |
int contentStartIndex = bulletIndices.get(i) + 1;
|
|
|
1113 |
int contentIndent = indent + 1;
|
|
|
1114 |
|
|
|
1115 |
Map<String, Object[]> info1 = getContents(richTextRuns,
|
|
|
1116 |
contentStartIndex, contentIndent);
|
|
|
1117 |
|
|
|
1118 |
drilldown(richTextRuns, info1, contentIndent, prefix);
|
|
|
1119 |
}
|
| 36 |
naveen |
1120 |
|
| 40 |
naveen |
1121 |
if(bulletLabels.size() > 0) {
|
|
|
1122 |
this.slideNameFeatureNameBulletTexts.put(prefix, bulletLabels);
|
|
|
1123 |
}
|
| 36 |
naveen |
1124 |
}
|
|
|
1125 |
//System.exit(0);
|
|
|
1126 |
|
| 40 |
naveen |
1127 |
|
|
|
1128 |
Object[] childrenSlidesInfo = info.get("childrenSlides");
|
|
|
1129 |
if(childrenSlidesInfo != null) {
|
|
|
1130 |
List<String> childrenSlideLabels =
|
|
|
1131 |
(List<String>) childrenSlidesInfo[0];
|
| 36 |
naveen |
1132 |
|
| 40 |
naveen |
1133 |
List<Integer> childrenSlideIndices =
|
|
|
1134 |
(List<Integer>) childrenSlidesInfo[1];
|
| 36 |
naveen |
1135 |
|
| 40 |
naveen |
1136 |
System.out.println("childrenSlideLabels=" +
|
|
|
1137 |
childrenSlideLabels);
|
| 36 |
naveen |
1138 |
|
| 40 |
naveen |
1139 |
System.out.println("childrenSlideIndices=" +
|
|
|
1140 |
childrenSlideIndices);
|
| 36 |
naveen |
1141 |
|
| 40 |
naveen |
1142 |
System.out.println("processing children slides");
|
|
|
1143 |
for(int i=0;i<childrenSlideLabels.size();i++) {
|
|
|
1144 |
String slideLabel = childrenSlideLabels.get(i);
|
|
|
1145 |
System.out.println("slideLabel="+slideLabel);
|
|
|
1146 |
|
|
|
1147 |
childrenSlideLabels.set(i, StringUtils.lowerCase(slideLabel));
|
|
|
1148 |
|
|
|
1149 |
int contentStartIndex = childrenSlideIndices.get(i) + 1;
|
|
|
1150 |
int contentIndent = indent + 1;
|
|
|
1151 |
|
|
|
1152 |
Map<String, Object[]> info1 = getContents(richTextRuns,
|
|
|
1153 |
contentStartIndex, contentIndent);
|
|
|
1154 |
|
|
|
1155 |
String newprefix = StringUtils.lowerCase(prefix + "_" +
|
|
|
1156 |
slideLabel);
|
|
|
1157 |
|
|
|
1158 |
drilldown(richTextRuns, info1, contentIndent, newprefix);
|
|
|
1159 |
}
|
| 37 |
naveen |
1160 |
|
| 40 |
naveen |
1161 |
if(childrenSlideLabels.size() > 0) {
|
|
|
1162 |
this.slideNameChildrenSlideNames.put(prefix,
|
|
|
1163 |
childrenSlideLabels);
|
|
|
1164 |
}
|
| 36 |
naveen |
1165 |
}
|
| 40 |
naveen |
1166 |
|
| 36 |
naveen |
1167 |
|
| 40 |
naveen |
1168 |
Object[] ffcInfo = info.get("ffc");
|
|
|
1169 |
if(ffcInfo != null) {
|
|
|
1170 |
List<String> ffcTexts = (List<String>) ffcInfo[0];
|
|
|
1171 |
List<Integer> ffcIndices = (List<Integer>) ffcInfo[1];
|
|
|
1172 |
System.out.println("ffcTexts=" + ffcTexts);
|
|
|
1173 |
System.out.println("ffcIndices=" + ffcIndices);
|
|
|
1174 |
|
|
|
1175 |
System.out.println("processing ffc");
|
|
|
1176 |
if(ffcTexts.size() > 0) {
|
|
|
1177 |
this.containerFCCs.put(prefix, ffcTexts);
|
|
|
1178 |
}
|
| 37 |
naveen |
1179 |
}
|
| 36 |
naveen |
1180 |
}
|
|
|
1181 |
|
| 37 |
naveen |
1182 |
/**
|
|
|
1183 |
*
|
|
|
1184 |
* @param richTextRuns
|
|
|
1185 |
* @param startIndex
|
|
|
1186 |
* @param indent
|
|
|
1187 |
* @return
|
|
|
1188 |
*/
|
| 36 |
naveen |
1189 |
private Map<String, Object[]> getContents(RichTextRun[] richTextRuns,
|
|
|
1190 |
int startIndex, int indent) {
|
|
|
1191 |
Map<String, Object[]> info = new HashMap<String, Object[]>();
|
|
|
1192 |
|
|
|
1193 |
Object[] childrenSlidesInfo = getChildrenSlides(richTextRuns,
|
|
|
1194 |
startIndex, indent);
|
|
|
1195 |
info.put("childrenSlides", childrenSlidesInfo);
|
|
|
1196 |
|
| 40 |
naveen |
1197 |
if(childrenSlidesInfo != null) {
|
|
|
1198 |
System.out.println("childrenSlidesInfo[0]=" +
|
|
|
1199 |
childrenSlidesInfo[0]);
|
|
|
1200 |
|
|
|
1201 |
System.out.println("childrenSlidesInfo[1]=" +
|
|
|
1202 |
childrenSlidesInfo[1]);
|
|
|
1203 |
}
|
|
|
1204 |
|
| 36 |
naveen |
1205 |
Object[] featuresInfo = getFeatures(richTextRuns,
|
|
|
1206 |
startIndex, indent);
|
|
|
1207 |
info.put("features", featuresInfo);
|
|
|
1208 |
|
| 40 |
naveen |
1209 |
if(featuresInfo != null) {
|
|
|
1210 |
System.out.println("featuresInfo[0]=" + featuresInfo[0]);
|
|
|
1211 |
System.out.println("featuresInfo[1]=" + featuresInfo[1]);
|
|
|
1212 |
}
|
| 36 |
naveen |
1213 |
|
|
|
1214 |
Object[] bulletsInfo = getBulletInfo(richTextRuns,
|
|
|
1215 |
startIndex, indent);
|
|
|
1216 |
info.put("bullets", bulletsInfo);
|
|
|
1217 |
|
| 40 |
naveen |
1218 |
if(bulletsInfo != null) {
|
|
|
1219 |
System.out.println("bulletsInfo[0]=" + bulletsInfo[0]);
|
|
|
1220 |
System.out.println("bulletsInfo[1]=" + bulletsInfo[1]);
|
|
|
1221 |
}
|
| 36 |
naveen |
1222 |
|
|
|
1223 |
Object[] ffcInfo = getFreeformContent(richTextRuns,
|
|
|
1224 |
startIndex, indent);
|
|
|
1225 |
info.put("ffc", ffcInfo);
|
|
|
1226 |
|
| 40 |
naveen |
1227 |
if(ffcInfo != null) {
|
|
|
1228 |
System.out.println("ffcInfo[0]=" + ffcInfo[0]);
|
|
|
1229 |
System.out.println("ffcInfo[1]=" + ffcInfo[1]);
|
|
|
1230 |
}
|
| 36 |
naveen |
1231 |
|
|
|
1232 |
return info;
|
|
|
1233 |
}
|
|
|
1234 |
|
| 37 |
naveen |
1235 |
/**
|
|
|
1236 |
*
|
|
|
1237 |
* @param richTextRuns
|
|
|
1238 |
* @param startIndex
|
|
|
1239 |
* @param indent
|
|
|
1240 |
* @return
|
|
|
1241 |
*/
|
| 36 |
naveen |
1242 |
private Object[] getBulletInfo(RichTextRun[] richTextRuns,
|
|
|
1243 |
int startIndex, int indent) {
|
|
|
1244 |
|
| 37 |
naveen |
1245 |
// -16776961 - Blue
|
| 36 |
naveen |
1246 |
Object[] bulletsInfo = this.getInfo(richTextRuns, startIndex, indent,
|
| 38 |
naveen |
1247 |
HSLF.BLUE, true);
|
| 36 |
naveen |
1248 |
|
|
|
1249 |
return bulletsInfo;
|
|
|
1250 |
}
|
|
|
1251 |
|
| 37 |
naveen |
1252 |
/**
|
|
|
1253 |
*
|
|
|
1254 |
* @param richTextRuns
|
|
|
1255 |
* @param startIndex
|
|
|
1256 |
* @param indent
|
|
|
1257 |
* @return
|
|
|
1258 |
*/
|
| 36 |
naveen |
1259 |
private Object[] getFreeformContent(RichTextRun[] richTextRuns,
|
|
|
1260 |
int startIndex, int indent) {
|
|
|
1261 |
|
| 37 |
naveen |
1262 |
// -6749953 - Purple
|
| 36 |
naveen |
1263 |
Object[] ffcInfo = this.getInfo(richTextRuns, startIndex,
|
| 40 |
naveen |
1264 |
indent, HSLF.PURPLE, true);
|
| 36 |
naveen |
1265 |
|
|
|
1266 |
|
|
|
1267 |
return ffcInfo;
|
|
|
1268 |
}
|
|
|
1269 |
|
| 37 |
naveen |
1270 |
/**
|
|
|
1271 |
*
|
|
|
1272 |
* @param richTextRuns
|
|
|
1273 |
* @param startIndex
|
|
|
1274 |
* @param indent
|
|
|
1275 |
* @return
|
|
|
1276 |
*/
|
| 36 |
naveen |
1277 |
private Object[] getFeatures(RichTextRun[] richTextRuns,
|
|
|
1278 |
int startIndex, int indent) {
|
|
|
1279 |
|
| 37 |
naveen |
1280 |
// -16711936 - Green
|
| 36 |
naveen |
1281 |
Object[] featuresInfo = this.getInfo(richTextRuns, startIndex,
|
| 40 |
naveen |
1282 |
indent, HSLF.GREEN, true);
|
| 36 |
naveen |
1283 |
|
|
|
1284 |
return featuresInfo;
|
|
|
1285 |
}
|
|
|
1286 |
|
| 37 |
naveen |
1287 |
/**
|
|
|
1288 |
*
|
|
|
1289 |
* @param richTextRuns
|
|
|
1290 |
* @param startIndex
|
|
|
1291 |
* @param indent
|
|
|
1292 |
* @return
|
|
|
1293 |
*/
|
| 36 |
naveen |
1294 |
private Object[] getChildrenSlides(RichTextRun[] richTextRuns,
|
|
|
1295 |
int startIndex, int indent) {
|
|
|
1296 |
|
| 37 |
naveen |
1297 |
// -26368 - Orange
|
| 36 |
naveen |
1298 |
Object[] childrenSlidesInfo = this.getInfo(richTextRuns, startIndex,
|
| 40 |
naveen |
1299 |
indent, HSLF.ORANGE, true);
|
| 36 |
naveen |
1300 |
|
|
|
1301 |
return childrenSlidesInfo;
|
|
|
1302 |
}
|
|
|
1303 |
|
| 37 |
naveen |
1304 |
/**
|
|
|
1305 |
*
|
|
|
1306 |
* @param rts
|
|
|
1307 |
* @param startIndex
|
|
|
1308 |
* @param indent
|
|
|
1309 |
* @param rgb
|
|
|
1310 |
* @param debug
|
|
|
1311 |
* @return
|
|
|
1312 |
*/
|
| 36 |
naveen |
1313 |
private Object[] getInfo(RichTextRun[] rts, int startIndex,
|
|
|
1314 |
int indent, int rgb, boolean debug) {
|
|
|
1315 |
List<String> labels = new ArrayList<String>();
|
|
|
1316 |
List<Integer> indices = new ArrayList<Integer>();
|
| 40 |
naveen |
1317 |
|
|
|
1318 |
if(startIndex >= rts.length) {
|
|
|
1319 |
return null;
|
|
|
1320 |
}
|
|
|
1321 |
|
| 36 |
naveen |
1322 |
int i = startIndex;
|
|
|
1323 |
while(true) {
|
|
|
1324 |
if(debug) {
|
|
|
1325 |
System.out.println("rts["+i+"].getRawText=" +
|
|
|
1326 |
rts[i].getRawText());
|
|
|
1327 |
|
|
|
1328 |
System.out.println("rts["+i+"].isBullet=" + rts[i].isBullet());
|
|
|
1329 |
System.out.println("rts["+i+"].getIndentLevel=" +
|
|
|
1330 |
rts[i].getIndentLevel());
|
|
|
1331 |
|
|
|
1332 |
System.out.println("rts["+i+"].getBulletColor().getRGB=" +
|
|
|
1333 |
rts[i].getBulletColor().getRGB());
|
|
|
1334 |
|
|
|
1335 |
|
|
|
1336 |
System.out.println("rts["+i+"].getFontColor().getRGB=" +
|
|
|
1337 |
rts[i].getFontColor().getRGB());
|
|
|
1338 |
|
|
|
1339 |
System.out.println("rgb=" + rgb);
|
|
|
1340 |
System.out.println("indent=" + indent);
|
| 37 |
naveen |
1341 |
|
|
|
1342 |
System.out.println("rts.length=" + rts.length);
|
| 36 |
naveen |
1343 |
}
|
| 40 |
naveen |
1344 |
// rts[i].isBullet() &&
|
|
|
1345 |
// rts[i].getBulletColor().getRGB() == rgb
|
|
|
1346 |
// rts[i].getFontColor().getRGB()
|
|
|
1347 |
if(rts[i].getIndentLevel() == indent &&
|
|
|
1348 |
(rts[i].getBulletColor().getRGB() == rgb ||
|
|
|
1349 |
rts[i].getFontColor().getRGB() == rgb)) {
|
|
|
1350 |
|
|
|
1351 |
System.out.println("Criteria of color, indent etc. is met");
|
| 36 |
naveen |
1352 |
i = this.getValidLabel(i, rts, labels, indices, debug);
|
|
|
1353 |
if(debug) System.out.println("new i="+ i);
|
|
|
1354 |
}
|
| 40 |
naveen |
1355 |
System.out.println("labels=" + labels);
|
|
|
1356 |
System.out.println("indices=" + indices);
|
| 36 |
naveen |
1357 |
|
| 40 |
naveen |
1358 |
System.out.println("(i >= (rts.length-1))" + (i >= (rts.length-1)));
|
|
|
1359 |
if(i >= (rts.length-1)) {
|
|
|
1360 |
break;
|
|
|
1361 |
}
|
| 36 |
naveen |
1362 |
|
| 40 |
naveen |
1363 |
// rts[i+1].isBullet() &&
|
|
|
1364 |
if(rts[i+1].getIndentLevel() < indent) {
|
|
|
1365 |
break;
|
|
|
1366 |
}
|
|
|
1367 |
|
| 36 |
naveen |
1368 |
i++;
|
|
|
1369 |
}
|
|
|
1370 |
return new Object[] {labels, indices};
|
|
|
1371 |
}
|
|
|
1372 |
|
| 37 |
naveen |
1373 |
/**
|
|
|
1374 |
*
|
|
|
1375 |
* @param index
|
|
|
1376 |
* @param rts
|
|
|
1377 |
* @param labels
|
|
|
1378 |
* @param indices
|
|
|
1379 |
* @param debug
|
|
|
1380 |
* @return
|
|
|
1381 |
*/
|
| 36 |
naveen |
1382 |
private int getValidLabel(int index, RichTextRun[] rts,
|
|
|
1383 |
List<String> labels, List<Integer> indices, boolean debug){
|
|
|
1384 |
StringBuffer sb = new StringBuffer();
|
|
|
1385 |
while(true) {
|
| 37 |
naveen |
1386 |
if(index > rts.length - 1) {
|
|
|
1387 |
break;
|
|
|
1388 |
}
|
|
|
1389 |
|
| 36 |
naveen |
1390 |
String text = rts[index].getRawText();
|
|
|
1391 |
if(text.equals("\r")) {
|
|
|
1392 |
break;
|
|
|
1393 |
}
|
|
|
1394 |
sb.append(text);
|
|
|
1395 |
index++;
|
|
|
1396 |
}
|
|
|
1397 |
if(debug)System.out.println("before label=]"+sb.toString()+"[");
|
|
|
1398 |
String label = StringUtils.strip(StringUtils.trim(sb.toString()));
|
|
|
1399 |
if(debug)System.out.println("after label=]"+label+"[");
|
|
|
1400 |
|
|
|
1401 |
//for(int i=0;i<label.length();i++) System.out.println(label.charAt(i));
|
|
|
1402 |
|
|
|
1403 |
if(!label.isEmpty()) {
|
|
|
1404 |
indices.add(new Integer(index));
|
| 37 |
naveen |
1405 |
|
|
|
1406 |
// Remove hardspace character \xa0
|
|
|
1407 |
char hardspace = (char)160;
|
|
|
1408 |
char softspace = (char)32;
|
|
|
1409 |
label = StringUtils.strip(StringUtils.replaceChars(label,
|
|
|
1410 |
hardspace, softspace));
|
|
|
1411 |
|
| 36 |
naveen |
1412 |
labels.add(label);
|
|
|
1413 |
}
|
|
|
1414 |
|
|
|
1415 |
return index;
|
|
|
1416 |
}
|
| 37 |
naveen |
1417 |
/**
|
|
|
1418 |
* TEST ONLY
|
|
|
1419 |
*
|
|
|
1420 |
* @param filename
|
|
|
1421 |
* @throws Exception
|
|
|
1422 |
*/
|
| 36 |
naveen |
1423 |
public static void showAllRichText(String filename) throws Exception {
|
|
|
1424 |
HSLFSlideShow hslfSS = new HSLFSlideShow(filename);
|
|
|
1425 |
SlideShow ss = new SlideShow(hslfSS);
|
|
|
1426 |
Slide[] ssarr = ss.getSlides();
|
|
|
1427 |
|
|
|
1428 |
for(int i=0; i < ssarr.length; i++) {
|
|
|
1429 |
TextRun[] trarr = ssarr[i].getTextRuns();
|
|
|
1430 |
//System.out.println("\nTitle=" + ssarr[i].getTitle());
|
|
|
1431 |
//System.out.println(ssarr[i].getTitle());
|
|
|
1432 |
|
|
|
1433 |
for(int j=0; j < trarr.length; j++) {
|
|
|
1434 |
System.out.println("\ntrarr[" + j + "].getRawText=" +
|
|
|
1435 |
trarr[j].getRawText());
|
|
|
1436 |
|
|
|
1437 |
RichTextRun[] rtrarr = trarr[j].getRichTextRuns();
|
|
|
1438 |
|
|
|
1439 |
StringBuffer indent2 = new StringBuffer();
|
|
|
1440 |
|
|
|
1441 |
for(int k=0; k < rtrarr.length; k++) {
|
|
|
1442 |
String rawText = rtrarr[k].getRawText();
|
|
|
1443 |
System.out.println("\nrtrarr[" + k + "].getRawText=" +
|
|
|
1444 |
rawText);
|
|
|
1445 |
System.out.println("rtrarr[" + k + "].isBullet=" +
|
|
|
1446 |
rtrarr[k].isBullet());
|
|
|
1447 |
|
|
|
1448 |
System.out.println("rtrarr[" + k + "].isUnderlined=" +
|
|
|
1449 |
rtrarr[k].isUnderlined());
|
|
|
1450 |
|
|
|
1451 |
//System.out.println("Ends with CR=" +
|
|
|
1452 |
// StringUtils.endsWith(rawText, "\r"));
|
|
|
1453 |
|
|
|
1454 |
//System.out.println("\nRawText=" + rawText);
|
|
|
1455 |
|
|
|
1456 |
/*
|
|
|
1457 |
if(StringUtils.strip(rawText).isEmpty()) {
|
|
|
1458 |
continue;
|
|
|
1459 |
}
|
|
|
1460 |
*/
|
|
|
1461 |
|
|
|
1462 |
int indent = rtrarr[k].getIndentLevel();
|
|
|
1463 |
System.out.println("indent=" + indent);
|
|
|
1464 |
if(indent == 2) {
|
|
|
1465 |
indent2.append(rawText);
|
|
|
1466 |
}
|
|
|
1467 |
|
|
|
1468 |
int rgb = rtrarr[k].getBulletColor().getRGB();
|
|
|
1469 |
System.out.println("rgb=" + rgb);
|
|
|
1470 |
|
|
|
1471 |
int fontrgb = rtrarr[k].getFontColor().getRGB();
|
|
|
1472 |
System.out.println("font rgb=" + fontrgb);
|
|
|
1473 |
|
|
|
1474 |
String fontname = rtrarr[k].getFontName();
|
|
|
1475 |
System.out.println("font rgb=" + fontname);
|
|
|
1476 |
|
|
|
1477 |
/*
|
|
|
1478 |
String indent = "";
|
|
|
1479 |
switch(rgb) {
|
|
|
1480 |
// Orange
|
|
|
1481 |
case -26368 :
|
|
|
1482 |
indent = "\t";
|
|
|
1483 |
break;
|
|
|
1484 |
// Purple
|
|
|
1485 |
case -6749953 :
|
|
|
1486 |
indent = "";
|
|
|
1487 |
break;
|
|
|
1488 |
// Green
|
|
|
1489 |
case -16711936 :
|
|
|
1490 |
indent = "\t";
|
|
|
1491 |
break;
|
|
|
1492 |
// Blue
|
|
|
1493 |
case -16776961 :
|
|
|
1494 |
indent = "\t\t";
|
|
|
1495 |
break;
|
|
|
1496 |
default:
|
|
|
1497 |
continue;
|
|
|
1498 |
}
|
|
|
1499 |
|
|
|
1500 |
//System.out.println(indent + rawText);
|
|
|
1501 |
*/
|
|
|
1502 |
}
|
|
|
1503 |
/*
|
|
|
1504 |
System.out.println("indent2="+ indent2.toString());
|
|
|
1505 |
|
|
|
1506 |
String[] sa = StringUtils.split(indent2.toString(), "\r");
|
|
|
1507 |
for(i=0;i<sa.length;i++) {
|
|
|
1508 |
System.out.println("sa["+i+"]=" + sa[i]);
|
|
|
1509 |
}
|
|
|
1510 |
*/
|
|
|
1511 |
}
|
|
|
1512 |
}
|
|
|
1513 |
}
|
|
|
1514 |
|
| 37 |
naveen |
1515 |
/**
|
|
|
1516 |
* TEST ONLY
|
|
|
1517 |
*
|
|
|
1518 |
* @param filename
|
|
|
1519 |
* @throws Exception
|
|
|
1520 |
*/
|
| 36 |
naveen |
1521 |
public static void showAllText(String filename) throws Exception {
|
|
|
1522 |
PowerPointExtractor ppe = new PowerPointExtractor(filename);
|
|
|
1523 |
System.out.println(ppe.getText());
|
|
|
1524 |
}
|
|
|
1525 |
}
|