Use URL params for sections
parent
2c49a4fbc1
commit
496d0ac462
|
|
@ -35,6 +35,7 @@ import org.librecms.contentsection.ContentItem;
|
|||
import org.librecms.contenttypes.MultiPartArticle;
|
||||
import org.librecms.contenttypes.MultiPartArticleSection;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
|
|
@ -45,6 +46,8 @@ import java.util.ArrayList;
|
|||
@Named("CmsPagesMultiPartArticleModel")
|
||||
public class MultiPartArticleModel implements ProcessesContentItem {
|
||||
|
||||
private static final String MPA_SECTION_QUERY_PARAM = "mpa_section";
|
||||
|
||||
@Inject
|
||||
private ContentItemModel contentItemModel;
|
||||
|
||||
|
|
@ -154,7 +157,7 @@ public class MultiPartArticleModel implements ProcessesContentItem {
|
|||
.orElse(Collections.emptyList());
|
||||
|
||||
sectionLinks = buildSectionLinks();
|
||||
|
||||
|
||||
final int currentSection = readCurrentSection();
|
||||
if (mpa.getSections().size() < currentSection) {
|
||||
throw new WebApplicationException(
|
||||
|
|
@ -197,12 +200,15 @@ public class MultiPartArticleModel implements ProcessesContentItem {
|
|||
}
|
||||
|
||||
private int readCurrentSection() {
|
||||
if (pageUrlModel.getPath().matches(".*/@sections/[0-9]*$")) {
|
||||
final String[] tokens = pageUrlModel.getPath().split("/");
|
||||
return Integer.valueOf(tokens[tokens.length - 1]) - 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return Optional
|
||||
.ofNullable(
|
||||
pageUrlModel.getQueryParameters().get(
|
||||
MPA_SECTION_QUERY_PARAM
|
||||
)
|
||||
)
|
||||
.filter(value -> value.matches("\\d*"))
|
||||
.map(value -> Integer.parseInt(value))
|
||||
.orElse(0);
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
|
|
@ -227,42 +233,35 @@ public class MultiPartArticleModel implements ProcessesContentItem {
|
|||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
private List<String> buildSectionLinks() {
|
||||
final String pathWithoutSections;
|
||||
if (pageUrlModel.getPath().matches(".*/@sections/[0-9]*$")) {
|
||||
final String path = pageUrlModel.getPath();
|
||||
pathWithoutSections = path.substring(
|
||||
0,
|
||||
path.lastIndexOf("/@sections") + 1
|
||||
);
|
||||
} else {
|
||||
pathWithoutSections = pageUrlModel.getPath();
|
||||
}
|
||||
|
||||
final int size = sectionTitles.size();
|
||||
final List<String> sectionLinksList = new ArrayList<>();
|
||||
for (int i = 0; i < sectionTitles.size(); i++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
sectionLinksList.add(
|
||||
String.format(
|
||||
"%s/@sections/%d?%s",
|
||||
pathWithoutSections,
|
||||
i,
|
||||
"?%s&%s=%d",
|
||||
pageUrlModel
|
||||
.getQueryParameters()
|
||||
.entrySet()
|
||||
.stream()
|
||||
.filter(
|
||||
entry
|
||||
-> !MPA_SECTION_QUERY_PARAM
|
||||
.equals(
|
||||
entry.getKey()
|
||||
)
|
||||
)
|
||||
.map(
|
||||
entry -> String.format(
|
||||
"%s=%s",
|
||||
entry.getKey(),
|
||||
entry.getValue()
|
||||
"%s=%s", entry.getKey(), entry.getValue()
|
||||
)
|
||||
)
|
||||
.collect(
|
||||
Collectors.joining("&")
|
||||
)
|
||||
.collect(Collectors.joining("&")),
|
||||
MPA_SECTION_QUERY_PARAM,
|
||||
i
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return sectionLinksList;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue