diff options
author | David W. Miller | 2014-07-22 20:33:27 +0000 |
---|---|---|
committer | Roberto E. Escobar | 2014-08-28 23:59:46 +0000 |
commit | f0cd4f5572b8a5ecf4ac366319dbfedea341b6c5 (patch) | |
tree | daacd3311652a111ffb327d0c894f6b2637e855c /plugins | |
parent | 0ecd86975f79ccfd60b97eb49b7fab8baf9682d6 (diff) | |
download | org.eclipse.osee-f0cd4f5572b8a5ecf4ac366319dbfedea341b6c5.tar.gz org.eclipse.osee-f0cd4f5572b8a5ecf4ac366319dbfedea341b6c5.tar.xz org.eclipse.osee-f0cd4f5572b8a5ecf4ac366319dbfedea341b6c5.zip |
refinement[ats_ATS10815]: Improve PageCreator readKeyValues method
Change-Id: I6759dd2792d2e47cf0d0e48d0b33bbcf78a6fc05
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/org.eclipse.osee.template.engine/src/org/eclipse/osee/template/engine/PageCreator.java | 99 |
1 files changed, 53 insertions, 46 deletions
diff --git a/plugins/org.eclipse.osee.template.engine/src/org/eclipse/osee/template/engine/PageCreator.java b/plugins/org.eclipse.osee.template.engine/src/org/eclipse/osee/template/engine/PageCreator.java index 18cf5b15245..e9c06177a2d 100644 --- a/plugins/org.eclipse.osee.template.engine/src/org/eclipse/osee/template/engine/PageCreator.java +++ b/plugins/org.eclipse.osee.template.engine/src/org/eclipse/osee/template/engine/PageCreator.java @@ -90,61 +90,37 @@ public final class PageCreator { Scanner scanner = new Scanner(keyValueStream, "UTF-8"); scanner.useDelimiter(xmlProcessingInstructionStartOrEnd); try { - String id = ""; - StringBuilder substitution = null; + String id = null; + StringBuilder substitution = new StringBuilder(NumOfCharsInTypicalSmallPage); + boolean isProcessingInstruction = false; + while (scanner.hasNext()) { + isProcessingInstruction = scanner.findInLine(xmlProcessingInstructionStart) != null; String token = scanner.next(); if (emptyOrWhitespaceOnly.matcher(token).matches()) { continue; } - if (token.startsWith("include")) { - if (!Strings.isValid(id)) { - id = getProcessingInstructionId(token); - } - if (substitution == null) { - substitution = new StringBuilder(NumOfCharsInTypicalSmallPage); - } - appendInclude(substitution, token); - if (scanner.hasNext()) { - substitution.append(trimToken(scanner.next())); - } - + handleInclude(substitution, token); + substitution = new StringBuilder(NumOfCharsInTypicalSmallPage); } else if (token.startsWith("rule ")) { - String ruleName = getRuleNamefromToken(token); - if (!Strings.isValid(ruleName)) { - throw new OseeArgumentException("no rule name specified in token %s", token); - } - AppendableRule<?> rule = substitutions.get(ruleName); - if (rule == null) { - throw new OseeArgumentException("no rule was found for token %s", token); - } - if (substitution == null) { - substitution = new StringBuilder(NumOfCharsInTypicalSmallPage); - } - Map<String, String> attributes = new HashMap<String, String>(); - // parse the arguments - parseArgumentList(token, attributes); - try { - rule.applyTo(substitution, attributes); - if (!Strings.isValid(id)) { - id = token; + handleRule(substitution, token); + substitution = new StringBuilder(NumOfCharsInTypicalSmallPage); + } else { // handle key + if (isProcessingInstruction) { + // next instruction found, complete previous one + if (id != null) { + addKeyValuePair(id, substitution); + substitution = new StringBuilder(NumOfCharsInTypicalSmallPage); } - } catch (IOException ex) { - throw new OseeCoreException(ex); - } - if (scanner.hasNext()) { - substitution.append(trimToken(scanner.next())); - } - } else { - id = token; - if (scanner.hasNext()) { - substitution = new StringBuilder(trimToken(scanner.next())); + id = token; } else { - substitution = new StringBuilder(); + substitution.append(trimToken(token)); } } - + } + // finish last token + if (id != null) { addKeyValuePair(id, substitution); } } catch (IOException ex) { @@ -154,6 +130,29 @@ public final class PageCreator { } } + private void handleRule(StringBuilder substitution, String token) { + String ruleName = getRuleNamefromToken(token); + if (!Strings.isValid(ruleName)) { + throw new OseeArgumentException("no rule name specified in token %s", token); + } + AppendableRule<?> rule = substitutions.get(ruleName); + if (rule == null) { + throw new OseeArgumentException("no rule was found for token %s", token); + } + + Map<String, String> attributes = new HashMap<String, String>(); + // parse the arguments + parseArgumentList(token, attributes); + try { + rule.applyTo(substitution, attributes); + + } catch (IOException ex) { + throw new OseeCoreException(ex); + } + String id = attributes.get("id"); + addKeyValuePair(id, substitution); + } + public String realizePage(ResourceToken templateResource) { return realizePage(templateResource, true); } @@ -195,7 +194,7 @@ public final class PageCreator { if (pathMatcher.find()) { return Long.parseLong(pathMatcher.group(1), 16); } - throw new OseeArgumentException("include path from token[%s] is in of the expected format", token); + throw new OseeArgumentException("include path from token[%s] is not of the expected format", token); } private String getProcessingInstructionId(String token) { @@ -203,7 +202,7 @@ public final class PageCreator { if (idMatcher.find()) { return idMatcher.group(1); } - throw new OseeArgumentException("include id from token [%s] is in of the expected format", token); + return null; } private void processToken(Appendable page, String token, boolean isProcessingInstruction) throws IOException { @@ -270,6 +269,14 @@ public final class PageCreator { return toReturn; } + private void handleInclude(StringBuilder substitution, String token) throws IOException { + appendInclude(substitution, token); + String id = getProcessingInstructionId(token); + if (id != null) { + addKeyValuePair(id, substitution); + } + } + private void appendInclude(Appendable page, String tokenStr) throws IOException { Long universalId = toUniversalId(tokenStr); boolean parseInclude = parseInclude(tokenStr); |