This is an automated email from the ASF dual-hosted git repository. dklco pushed a commit to branch SLING-7900 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git
commit 5d2c55ae3c54ccceb1538c8ac6d155d6ee1e5f2c Author: JE Bailey <jason.bai...@sas.com> AuthorDate: Fri Sep 7 13:25:13 2018 -0400 initial changes --- .../cms/core/models/components/Breadcrumbs.java | 93 ++++++++++++++++++++++ ui/pom.xml | 12 +++ .../cms/contentbreadcrumb/contentbreadcrumb.jsp | 40 ++++------ ui/src/main/resources/jcr_root/web-fragment.xml | 5 ++ 4 files changed, 126 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/org/apache/sling/cms/core/models/components/Breadcrumbs.java b/core/src/main/java/org/apache/sling/cms/core/models/components/Breadcrumbs.java new file mode 100644 index 0000000..4c7da58 --- /dev/null +++ b/core/src/main/java/org/apache/sling/cms/core/models/components/Breadcrumbs.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sling.cms.core.models.components; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.DefaultInjectionStrategy; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.injectorspecific.Self; + +@Model(adaptables = SlingHttpServletRequest.class,defaultInjectionStrategy=DefaultInjectionStrategy.OPTIONAL) +public class Breadcrumbs { + + @Inject + int depth; + + @Inject + @Named("jcr:title") + String title; + + @Inject + String prefix; + + @Inject + Resource resource; + + @Self + SlingHttpServletRequest servletRequest; + + Resource suffixResource; + + List<PathData> pathData = new ArrayList<>(); + + @PostConstruct + public void postConstruct() { + suffixResource = servletRequest.getRequestPathInfo().getSuffixResource(); + pathData.add(new PathData(prefix+resource.getPath(),title)); + } + + public String getTitle() { + return null; + } + + public List<PathData> getPathData() { + return pathData; + } + + public String getString() { + return "flounder"; + } + + public static class PathData{ + + private String href; + private String title; + + public PathData(String href, String title) { + this.href = href; + this.title = title; + } + public String getHref() { + return href; //prefix + resource path + } + //${parent.valueMap['jcr:title'] != null ? parent.valueMap['jcr:title'] : parent.valueMap['jcr:content/jcr:title']}" default="${parent.name}" + public String getTitle() { + return title; + } + + } + +} diff --git a/ui/pom.xml b/ui/pom.xml index 513307e..a5db13e 100644 --- a/ui/pom.xml +++ b/ui/pom.xml @@ -167,4 +167,16 @@ </build> </profile> </profiles> + <dependencies> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.models.api</artifactId> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.cms.core</artifactId> + <version>0.9.1-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + </dependencies> </project> \ No newline at end of file diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/contentbreadcrumb/contentbreadcrumb.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/contentbreadcrumb/contentbreadcrumb.jsp index 18212b7..9de9e1c 100644 --- a/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/contentbreadcrumb/contentbreadcrumb.jsp +++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/contentbreadcrumb/contentbreadcrumb.jsp @@ -16,30 +16,22 @@ * specific language governing permissions and limitations * under the License. */ --%> - <%@include file="/libs/sling-cms/global.jsp"%> -<sling:getParent resource="${slingRequest.requestPathInfo.suffixResource}" var="root" level="${resource.valueMap.depth}" /> -<nav class="breadcrumb" aria-label="breadcrumbs"> +<%@page import="org.apache.sling.models.factory.ModelFactory"%> +<%@page import="org.apache.sling.cms.core.models.components.Breadcrumbs"%> +<%@include file="/libs/sling-cms/global.jsp"%><% + +%> + +<sling:adaptTo adaptable="${resource}" adaptTo="org.apache.sling.cms.core.models.components.Breadcrumbs" var="model"/><nav class="breadcrumb" aria-label="breadcrumbs"> <ul> - <li> - <a href="${resource.valueMap.prefix}${root.path}"> - <sling:encode value="${root.valueMap['jcr:title'] != null ? root.valueMap['jcr:title'] : root.valueMap['jcr:content/jcr:title']}" default="${root.name}" mode="HTML" /> - </a> - </li> - <c:if test="${site.path != slingRequest.requestPathInfo.suffix && site.path != slingRequest.requestPathInfo.suffixResource.parent.path}"> - <c:forEach var="parent" items="${sling:getParents(slingRequest.requestPathInfo.suffixResource,(resource.valueMap.depth + 1))}"> - <li> - <a href="${resource.valueMap.prefix}${parent.path}"> - <sling:encode value="${parent.valueMap['jcr:title'] != null ? parent.valueMap['jcr:title'] : parent.valueMap['jcr:content/jcr:title']}" default="${parent.name}" mode="HTML" /> - </a> - </li> - </c:forEach> - </c:if> - <c:if test="${root.path != slingRequest.requestPathInfo.suffix}"> - <li class="is-active"> - <a href="#"> - <sling:encode value="${slingRequest.requestPathInfo.suffixResource.valueMap['jcr:title'] != null ? slingRequest.requestPathInfo.suffixResource.valueMap['jcr:title'] : slingRequest.requestPathInfo.suffixResource.valueMap['jcr:content/jcr:title']}" default="${slingRequest.requestPathInfo.suffixResource.name}" mode="HTML" /> - </a> - </li> - </c:if> + <c:forEach var="item" items="${model.pathData}"> + <li> + <a href="${item.href}"> + <sling:encode value="${item.title}" mode="HTML" /> + </a> + </li> + </c:forEach> + <li>$WHY? + <li>${model.string}</li> </ul> </nav> diff --git a/ui/src/main/resources/jcr_root/web-fragment.xml b/ui/src/main/resources/jcr_root/web-fragment.xml new file mode 100644 index 0000000..78ede58 --- /dev/null +++ b/ui/src/main/resources/jcr_root/web-fragment.xml @@ -0,0 +1,5 @@ +<web-fragment id="WebFragment_ID" version="3.0" + xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd"> + <name>ui</name> +</web-fragment> \ No newline at end of file