You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Bertrand Delacretaz (JIRA)" <ji...@apache.org> on 2016/08/22 16:17:21 UTC
[jira] [Closed] (SLING-5917) parseRawText flag in getRepoInitText()
is ambiguous
[ https://issues.apache.org/jira/browse/SLING-5917?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Bertrand Delacretaz closed SLING-5917.
--------------------------------------
Closing this ticket and removing the fix version, as we won't released this code in the end, replaced by the more flexible SLING-5969 mechanism.
> parseRawText flag in getRepoInitText() is ambiguous
> ---------------------------------------------------
>
> Key: SLING-5917
> URL: https://issues.apache.org/jira/browse/SLING-5917
> Project: Sling
> Issue Type: Bug
> Components: Repoinit
> 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)