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