Skip to content

Commit

Permalink
Merge pull request #327 from ist-dresden/bugfix/caconfigfixes
Browse files Browse the repository at this point in the history
Some fixes for CA configuration display and some fixes on SourceModel for node names like cq:tags and attribute names with a colon that are not namespaced.
  • Loading branch information
stoerr authored Jun 27, 2024
2 parents 31890fd + ffcb822 commit 6c1bb06
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ public List<String> getGlobalConfigPaths() {

public List<ContextResource> getContextPaths() {
List<ContextResource> contextResources = IteratorUtils.toList(contextPathStrategyMultiplexer.findContextResources(getResource()));
contextResources = contextResources.stream()
.filter(contextResource ->
getResolver().getResource(contextResource.getConfigRef()) != null)
.filter(contextResource ->
getResolver().getResource(contextResource.getConfigRef() + "/sling:configs") != null)
.collect(Collectors.toList());
return contextResources;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ public class SourceModel extends ConsoleSlingBean {
protected transient Boolean[] hasOrderableChildren;
protected transient Comparator<Property> propertyComparator;

/** Some things look like namespaces but aren't actual namespaces. This saves them. */
protected transient List<String> nonExistingNamespaces = new ArrayList<>();

public SourceModel(NodesConfiguration config, BeanContext context, Resource resource) {
this.config = config;
initialize(context, resource);
Expand Down Expand Up @@ -213,7 +216,7 @@ public String getExportPath(@NotNull final String path) {
}

/**
* @param path a resource path in the resource repository tree; maybe a mounted resource path
* @param aPath a resource path in the resource repository tree; maybe a mounted resource path
* @return 'true' if the path is equal to the export root path
*/
public boolean isRootPath(@NotNull final String aPath) {
Expand Down Expand Up @@ -343,6 +346,7 @@ protected void determineNamespaces(List<String> keys, boolean inFullCoverage) {
addNameNamespace(keys, resource.getName());
boolean subnodeInFullCoverage = inFullCoverage || isFullCoverageNode();
for (Resource subnode : getSubnodeList()) {
addNameNamespace(keys, subnode.getName());
SourceModel subnodeModel = new SourceModel(config, context, subnode);
if (subnodeModel.getRenderingType(subnodeModel.getResource(), subnodeInFullCoverage) == RenderingType.EMBEDDED) {
subnodeModel.determineNamespaces(keys, subnodeInFullCoverage);
Expand Down Expand Up @@ -906,13 +910,23 @@ protected void writeNamespaceAttributes(Writer writer, List<String> namespaces)
}
} catch (NamespaceException nsex) {
LOG.debug(nsex.toString());
nonExistingNamespaces.add(ns);
}
}
}
}

public String escapeXmlName(String propertyName) {
return ISO9075.encode(propertyName);
String encoded = ISO9075.encode(propertyName);
// If the attribute has a colon which does not start a namespace, we still need to encode that.
if (encoded.contains(":")) {
int pos = encoded.indexOf(':');
String prefix = encoded.substring(0, pos);
if (nonExistingNamespaces.contains(prefix)) {
encoded = encoded.replaceAll(":", "_x003A_");
}
}
return encoded;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<p>
To edit the configuration go to the mentioned configuration locations.
For creating new configurations - the following nodes are currently connected via sling:configRef:
For creating new configurations - the following nodes are currently connected:
</p>
<ul>
<c:forEach var="contextResource" items="${model.contextPaths}">
Expand All @@ -29,7 +29,7 @@
data-path="${contextResource.configRef}/sling:configs">${contextResource.configRef}/sling:configs</a>
referenced by
<a class="target-link"
data-path="${contextResource.resource.path}/sling:configs">${contextResource.resource.path}/sling:configs</a>
data-path="${contextResource.resource.path}">${contextResource.resource.path}</a>
(ranking ${contextResource.serviceRanking})
</li>
</c:forEach>
Expand Down Expand Up @@ -119,7 +119,7 @@

<c:forEach var="collection"
items="${model.collectionConfigurations}">
<c:if test="${not empty collection.collectionConfigData.resourcePath}">
<c:if test="${not empty collection.collectionConfigData.resourcePath and not empty collection.collectionConfigData.items}">
<%--@elvariable id="collection" type="com.composum.sling.nodes.components.CAConfigModel.CollectionConfigInfo"--%>
<div class="panel panel-default">
<div class="panel-heading">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void listArchive() throws Exception {
String zipContents = getZipContentOverview(out, true, true);
System.out.println(zipContents);
assertThat(zipContents, is(".content.xml : 292 | 504953282\n" +
"assetsfolder/.content.xml : 200 | 2815730915\n" +
"assetsfolder/.content.xml : 249 | 213389511\n" +
"assetsfolder/_nt_resourcewithoutfile : 83358 | 2844564088\n" +
"assetsfolder/_nt_resourcewithoutfile.dir/.content.xml : 221 | 1068843391\n" +
"assetsfolder/plain.jpg : 76910 | 2714537933\n" +
Expand Down

0 comments on commit 6c1bb06

Please sign in to comment.