[
https://issues.apache.org/jira/browse/SLING-5917?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Oliver Lietz reassigned SLING-5917:
-----------------------------------
Assignee: Oliver Lietz
> parseRawText flag in getRepoInitText() is ambiguous
> ---------------------------------------------------
>
> Key: SLING-5917
> URL: https://issues.apache.org/jira/browse/SLING-5917
> Project: Sling
> Issue Type: Bug
> Components: JCR
> Affects Versions: Repoinit JCR 1.0.0
> Reporter: Oliver Lietz
> Assignee: Oliver Lietz
>
> *current:*
> {noformat}
> private String getRepoInitText() {
> final boolean parseRawText = modelSectionName.trim().length() > 0;
> if(parseRawText) {
> log.info("Reading repoinit statements from {}", textURL);
> } else {
> log.info("Extracting repoinit statements from section {} of
> provisioning model {}", modelSectionName, textURL);
> }
> String result = getRawRepoInitText();
> log.debug("Raw text from {}: \n{}", textURL, result);
> log.info("Got {} characters from {}", result.length(), textURL);
> if(parseRawText) {
> final StringReader r = new StringReader(result);
> try {
> final Model m = ModelReader.read(r, textURL);
> final StringBuilder b = new StringBuilder();
> for(Feature f : m.getFeatures()) {
> for(Section s :
> f.getAdditionalSections(modelSectionName)) {
> b.append("# ").append(modelSectionName).append(" from
> ").append(f.getName()).append("\n");
> b.append("# ").append(s.getComment()).append("\n");
> b.append(s.getContents()).append("\n");
> }
> }
> result = b.toString();
> } catch (IOException e) {
> result = "";
> log.warn("Error parsing provisioning model from " + textURL,
> e);
> }
> }
> return result;
> }
> {noformat}
> *improved:*
> {noformat}
> private String getRepoInitText() {
> final String rawText = getRawRepoInitText();
> log.debug("Raw text from {}: \n{}", textURL, rawText);
> log.info("Got {} characters from {}", rawText.length(), textURL);
> final boolean parseRawText = modelSectionName.trim().length() == 0;
> if (parseRawText) {
> log.info("Parsing raw repoinit statements from {}", textURL);
> return rawText;
> } else {
> log.info("Extracting repoinit statements from section '{}' of
> provisioning model {}", modelSectionName, textURL);
> final StringReader reader = new StringReader(rawText);
> try {
> final Model model = ModelReader.read(reader, textURL);
> final StringBuilder sb = new StringBuilder();
> for (Feature feature : model.getFeatures()) {
> for (Section section :
> feature.getAdditionalSections(modelSectionName)) {
> sb.append("# ").append(modelSectionName).append("
> from ").append(feature.getName()).append("\n");
> sb.append("#
> ").append(section.getComment()).append("\n");
> sb.append(section.getContents()).append("\n");
> }
> }
> return sb.toString();
> } catch (IOException e) {
> log.warn("Error parsing provisioning model from " + textURL,
> e);
> return "";
> }
> }
> }
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)