diff --git a/scm-core/src/main/java/sonia/scm/repository/PreProcessorUtil.java b/scm-core/src/main/java/sonia/scm/repository/PreProcessorUtil.java index d747f56b22..0c87c3980f 100644 --- a/scm-core/src/main/java/sonia/scm/repository/PreProcessorUtil.java +++ b/scm-core/src/main/java/sonia/scm/repository/PreProcessorUtil.java @@ -30,6 +30,7 @@ */ + package sonia.scm.repository; //~--- non-JDK imports -------------------------------------------------------- @@ -76,18 +77,16 @@ public class PreProcessorUtil * @param blameLinePreProcessorFactorySet */ @Inject - public PreProcessorUtil( - Set changesetPreProcessorSet, - Set changesetPreProcessorFactorySet, - Set fileObjectPreProcessorSet, - Set fileObjectPreProcessorFactorySet, - Set blameLinePreProcessorSet, - Set blameLinePreProcessorFactorySet) + public PreProcessorUtil(Set changesetPreProcessorSet, + Set changesetPreProcessorFactorySet, + Set fileObjectPreProcessorSet, + Set fileObjectPreProcessorFactorySet, + Set blameLinePreProcessorSet, + Set blameLinePreProcessorFactorySet) { this.changesetPreProcessorSet = Collections2.transform(changesetPreProcessorSet, - new Function() + new Function() { @Override public ChangesetPreProcessorWrapper apply(ChangesetPreProcessor input) @@ -97,20 +96,19 @@ public class PreProcessorUtil }); this.changesetPreProcessorFactorySet = Collections2.transform(changesetPreProcessorFactorySet, - new Function() + new Function() { @Override public ChangesetPreProcessorFactoryWrapper apply( - ChangesetPreProcessorFactory input) + ChangesetPreProcessorFactory input) { return new ChangesetPreProcessorFactoryWrapper(input); } }); this.fileObjectPreProcessorSet = Collections2.transform(fileObjectPreProcessorSet, - new Function() + new Function() { @Override public FileObjectPreProcessorWrapper apply(FileObjectPreProcessor input) @@ -120,12 +118,12 @@ public class PreProcessorUtil }); this.fileObjectPreProcessorFactorySet = Collections2.transform(fileObjectPreProcessorFactorySet, - new Function() + new Function() { @Override public FileObjectPreProcessorFactoryWrapper apply( - FileObjectPreProcessorFactory input) + FileObjectPreProcessorFactory input) { return new FileObjectPreProcessorFactoryWrapper(input); } @@ -148,14 +146,14 @@ public class PreProcessorUtil if (logger.isTraceEnabled()) { logger.trace("prepare blame line {} of repository {} for return", - blameLine.getLineNumber(), repository.getName()); + blameLine.getLineNumber(), repository.getName()); } EscapeUtil.escape(blameLine); PreProcessorHandler handler = new PreProcessorHandler(blameLinePreProcessorFactorySet, - blameLinePreProcessorSet, repository); + blameLinePreProcessorSet, repository); handler.callPreProcessors(blameLine); handler.callPreProcessorFactories(blameLine); @@ -169,18 +167,37 @@ public class PreProcessorUtil * @param blameResult */ public void prepareForReturn(Repository repository, BlameResult blameResult) + { + prepareForReturn(repository, blameResult, true); + } + + /** + * Method description + * + * + * @param repository + * @param blameResult + * @param escape + * + * @since 1.35 + */ + public void prepareForReturn(Repository repository, BlameResult blameResult, + boolean escape) { if (logger.isTraceEnabled()) { logger.trace("prepare blame result of repository {} for return", - repository.getName()); + repository.getName()); } - EscapeUtil.escape(blameResult); + if (escape) + { + EscapeUtil.escape(blameResult); + } PreProcessorHandler handler = new PreProcessorHandler(blameLinePreProcessorFactorySet, - blameLinePreProcessorSet, repository); + blameLinePreProcessorSet, repository); handler.callPreProcessors(blameResult.getBlameLines()); handler.callPreProcessorFactories(blameResult.getBlameLines()); @@ -194,18 +211,37 @@ public class PreProcessorUtil * @param changeset */ public void prepareForReturn(Repository repository, Changeset changeset) + { + prepareForReturn(repository, changeset, true); + } + + /** + * Method description + * + * + * @param repository + * @param changeset + * @param escape + * + * @since 1.35 + */ + public void prepareForReturn(Repository repository, Changeset changeset, + boolean escape) { if (logger.isTraceEnabled()) { logger.trace("prepare changeset {} of repository {} for return", - changeset.getId(), repository.getName()); + changeset.getId(), repository.getName()); } - EscapeUtil.escape(changeset); + if (escape) + { + EscapeUtil.escape(changeset); + } PreProcessorHandler handler = new PreProcessorHandler(changesetPreProcessorFactorySet, - changesetPreProcessorSet, repository); + changesetPreProcessorSet, repository); handler.callPreProcessors(changeset); handler.callPreProcessorFactories(changeset); @@ -219,18 +255,69 @@ public class PreProcessorUtil * @param result */ public void prepareForReturn(Repository repository, BrowserResult result) + { + prepareForReturn(repository, result, true); + } + + /** + * Method description + * + * + * @param repository + * @param result + * @param escape + * + * @since 1.35 + */ + public void prepareForReturn(Repository repository, BrowserResult result, + boolean escape) { if (logger.isTraceEnabled()) { logger.trace("prepare browser result of repository {} for return", - repository.getName()); + repository.getName()); } - EscapeUtil.escape(result); + if (escape) + { + EscapeUtil.escape(result); + } PreProcessorHandler handler = new PreProcessorHandler(fileObjectPreProcessorFactorySet, - fileObjectPreProcessorSet, repository); + fileObjectPreProcessorSet, repository); + + handler.callPreProcessors(result); + handler.callPreProcessorFactories(result); + } + + /** + * Method description + * + * + * @param repository + * @param result + * @param escape + * + * @since 1.35 + */ + public void prepareForReturn(Repository repository, + ChangesetPagingResult result, boolean escape) + { + if (logger.isTraceEnabled()) + { + logger.trace("prepare changesets of repository {} for return", + repository.getName()); + } + + if (escape) + { + EscapeUtil.escape(result); + } + + PreProcessorHandler handler = + new PreProcessorHandler(changesetPreProcessorFactorySet, + changesetPreProcessorSet, repository); handler.callPreProcessors(result); handler.callPreProcessorFactories(result); @@ -244,22 +331,9 @@ public class PreProcessorUtil * @param result */ public void prepareForReturn(Repository repository, - ChangesetPagingResult result) + ChangesetPagingResult result) { - if (logger.isTraceEnabled()) - { - logger.trace("prepare changesets of repository {} for return", - repository.getName()); - } - - EscapeUtil.escape(result); - - PreProcessorHandler handler = - new PreProcessorHandler(changesetPreProcessorFactorySet, - changesetPreProcessorSet, repository); - - handler.callPreProcessors(result); - handler.callPreProcessorFactories(result); + prepareForReturn(repository, result, true); } //~--- inner classes -------------------------------------------------------- @@ -272,7 +346,7 @@ public class PreProcessorUtil * @author Enter your name here... */ private static class ChangesetPreProcessorFactoryWrapper - implements PreProcessorFactory + implements PreProcessorFactory { /** @@ -282,7 +356,7 @@ public class PreProcessorUtil * @param preProcessorFactory */ public ChangesetPreProcessorFactoryWrapper( - ChangesetPreProcessorFactory preProcessorFactory) + ChangesetPreProcessorFactory preProcessorFactory) { this.preProcessorFactory = preProcessorFactory; } @@ -327,7 +401,7 @@ public class PreProcessorUtil * @author Enter your name here... */ private static class ChangesetPreProcessorWrapper - implements PreProcessor + implements PreProcessor { /** @@ -370,7 +444,7 @@ public class PreProcessorUtil * @author Enter your name here... */ private static class FileObjectPreProcessorFactoryWrapper - implements PreProcessorFactory + implements PreProcessorFactory { /** @@ -380,7 +454,7 @@ public class PreProcessorUtil * @param preProcessorFactory */ public FileObjectPreProcessorFactoryWrapper( - FileObjectPreProcessorFactory preProcessorFactory) + FileObjectPreProcessorFactory preProcessorFactory) { this.preProcessorFactory = preProcessorFactory; } @@ -426,7 +500,7 @@ public class PreProcessorUtil * @author Enter your name here... */ private static class FileObjectPreProcessorWrapper - implements PreProcessor + implements PreProcessor { /** @@ -482,9 +556,9 @@ public class PreProcessorUtil * @param repository */ public PreProcessorHandler( - Collection> preProcessorFactorySet, - Collection> preProcessorSet, - Repository repository) + Collection> preProcessorFactorySet, + Collection> preProcessorSet, + Repository repository) { this.preProcessorFactorySet = preProcessorFactorySet; this.preProcessorSet = preProcessorSet; diff --git a/scm-core/src/main/java/sonia/scm/repository/api/BlameCommandBuilder.java b/scm-core/src/main/java/sonia/scm/repository/api/BlameCommandBuilder.java index d473e592e5..f57ca6ab39 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/BlameCommandBuilder.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/BlameCommandBuilder.java @@ -190,7 +190,7 @@ public final class BlameCommandBuilder if (!disablePreProcessors && (result != null)) { - preProcessorUtil.prepareForReturn(repository, result); + preProcessorUtil.prepareForReturn(repository, result, !disableEscaping); } return result; @@ -214,6 +214,24 @@ public final class BlameCommandBuilder return this; } + + /** + * Disable html escaping for the returned blame lines. By default all + * blame lines are html escaped. + * + * + * @param disableEscaping true to disable the html escaping + * + * @return {@code this} + * + * @since 1.35 + */ + public BlameCommandBuilder setDisableEscaping(boolean disableEscaping) + { + this.disableEscaping = disableEscaping; + + return this; + } /** * Disable the execution of pre processors. @@ -349,6 +367,9 @@ public final class BlameCommandBuilder /** the cache */ private Cache cache; + /** disable escaping */ + private boolean disableEscaping = false; + /** disable change */ private boolean disableCache = false; diff --git a/scm-core/src/main/java/sonia/scm/repository/api/BrowseCommandBuilder.java b/scm-core/src/main/java/sonia/scm/repository/api/BrowseCommandBuilder.java index 3a951cc490..ea4c1450ae 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/BrowseCommandBuilder.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/BrowseCommandBuilder.java @@ -186,7 +186,7 @@ public final class BrowseCommandBuilder if (!disablePreProcessors && (result != null)) { - preProcessorUtil.prepareForReturn(repository, result); + preProcessorUtil.prepareForReturn(repository, result, !disableEscaping); List fileObjects = result.getFiles(); @@ -218,6 +218,24 @@ public final class BrowseCommandBuilder return this; } + + /** + * Disable html escaping for the returned file objects. By default all + * file objects are html escaped. + * + * + * @param disableEscaping true to disable the html escaping + * + * @return {@code this} + * + * @since 1.35 + */ + public BrowseCommandBuilder setDisableEscaping(boolean disableEscaping) + { + this.disableEscaping = disableEscaping; + + return this; + } /** * Disabling the last commit means that every call to @@ -422,6 +440,9 @@ public final class BrowseCommandBuilder /** cache */ private Cache cache; + /** disable escaping */ + private boolean disableEscaping = false; + /** disables the cache */ private boolean disableCache = false; diff --git a/scm-core/src/main/java/sonia/scm/repository/api/HookChangesetBuilder.java b/scm-core/src/main/java/sonia/scm/repository/api/HookChangesetBuilder.java index 2a6c9ac533..c06e227d5f 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/HookChangesetBuilder.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/HookChangesetBuilder.java @@ -95,9 +95,9 @@ public final class HookChangesetBuilder /** * Returns a immutable {@link List} of added {@link Changeset}'s. - * Note: Use this method only if you need a {@link List}, if - * you just want to iterate over the {@link Changeset}'s use - * {@link #getChangesets()} instead. The {@link #getChangesets()} needs less + * Note: Use this method only if you need a {@link List}, if + * you just want to iterate over the {@link Changeset}'s use + * {@link #getChangesets()} instead. The {@link #getChangesets()} needs less * memory and should be much more faster then this method. * * @return immutable {@link List} of added {@link Changeset}'s @@ -108,7 +108,7 @@ public final class HookChangesetBuilder } /** - * Returns an {@link Iterable} which is able to return all {@link Changeset}s + * Returns an {@link Iterable} which is able to return all {@link Changeset}s * which are added to the repository. * * @return {@link Iterable} for added {@link Changeset}s @@ -132,7 +132,8 @@ public final class HookChangesetBuilder try { copy = DeepCopy.copy(c); - preProcessorUtil.prepareForReturn(repository, copy); + preProcessorUtil.prepareForReturn(repository, copy, + !disableEscaping); } catch (IOException ex) { @@ -155,6 +156,24 @@ public final class HookChangesetBuilder //~--- set methods ---------------------------------------------------------- + /** + * Disable html escaping for the returned changesets. By default all + * changesets are html escaped. + * + * + * @param disableEscaping true to disable the html escaping + * + * @return {@code this} + * + * @since 1.35 + */ + public HookChangesetBuilder setDisableEscaping(boolean disableEscaping) + { + this.disableEscaping = disableEscaping; + + return this; + } + /** * Disable the execution of pre processors. * @@ -173,6 +192,9 @@ public final class HookChangesetBuilder //~--- fields --------------------------------------------------------------- + /** disable escaping */ + private boolean disableEscaping = false; + /** disable pre processors marker */ private boolean disablePreProcessors = false; diff --git a/scm-core/src/main/java/sonia/scm/repository/api/LogCommandBuilder.java b/scm-core/src/main/java/sonia/scm/repository/api/LogCommandBuilder.java index c09ab7edcd..2977979ad2 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/LogCommandBuilder.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/LogCommandBuilder.java @@ -273,7 +273,7 @@ public final class LogCommandBuilder if (!disablePreProcessors && (cpr != null)) { - preProcessorUtil.prepareForReturn(repository, cpr); + preProcessorUtil.prepareForReturn(repository, cpr, !disableEscaping); } return cpr; @@ -315,6 +315,24 @@ public final class LogCommandBuilder return this; } + /** + * Disable html escaping for the returned changesets. By default all + * changesets are html escaped. + * + * + * @param disableEscaping true to disable the html escaping + * + * @return {@code this} + * + * @since 1.35 + */ + public LogCommandBuilder setDisableEscaping(boolean disableEscaping) + { + this.disableEscaping = disableEscaping; + + return this; + } + /** * Disable the execution of pre processors. * @@ -525,6 +543,9 @@ public final class LogCommandBuilder /** cache for changesets */ private Cache cache; + /** disable escaping */ + private boolean disableEscaping = false; + /** disable cache */ private boolean disableCache = false; diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitRepositoryViewer.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitRepositoryViewer.java index dff2a31a83..49b98f1047 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitRepositoryViewer.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitRepositoryViewer.java @@ -301,12 +301,15 @@ public class GitRepositoryViewer try { - ChangesetPagingResult cpr = service.getLogCommand().setBranch( - name).setPagingLimit( - CHANGESET_PER_BRANCH).getChangesets(); - Iterable changesets = Iterables.transform(cpr, - new Function() + //J- + ChangesetPagingResult cpr = service.getLogCommand() + .setDisableEscaping(true) + .setBranch(name) + .setPagingLimit(CHANGESET_PER_BRANCH) + .getChangesets(); + + Iterable changesets = + Iterables.transform(cpr, new Function() { @Override @@ -315,6 +318,7 @@ public class GitRepositoryViewer return new ChangesetModel(changeset); } }); + //J+ model = new BranchModel(name, changesets); }