You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2016/04/09 21:05:31 UTC
svn commit: r1738370 - in /sling/trunk/samples/fling/src/main:
java/org/apache/sling/samples/fling/
java/org/apache/sling/samples/fling/page/ resources/apps/fling/page/simple/
resources/apps/fling/page/user/
Author: olli
Date: Sat Apr 9 19:05:31 2016
New Revision: 1738370
URL: http://svn.apache.org/viewvc?rev=1738370&view=rev
Log:
straighten pages and templates
Added:
sling/trunk/samples/fling/src/main/java/org/apache/sling/samples/fling/page/
sling/trunk/samples/fling/src/main/java/org/apache/sling/samples/fling/page/Page.java
sling/trunk/samples/fling/src/main/java/org/apache/sling/samples/fling/page/UserPage.java
Removed:
sling/trunk/samples/fling/src/main/java/org/apache/sling/samples/fling/Page.java
sling/trunk/samples/fling/src/main/java/org/apache/sling/samples/fling/UserPage.java
Modified:
sling/trunk/samples/fling/src/main/resources/apps/fling/page/simple/html.html
sling/trunk/samples/fling/src/main/resources/apps/fling/page/user/html.html
Added: sling/trunk/samples/fling/src/main/java/org/apache/sling/samples/fling/page/Page.java
URL: http://svn.apache.org/viewvc/sling/trunk/samples/fling/src/main/java/org/apache/sling/samples/fling/page/Page.java?rev=1738370&view=auto
==============================================================================
--- sling/trunk/samples/fling/src/main/java/org/apache/sling/samples/fling/page/Page.java (added)
+++ sling/trunk/samples/fling/src/main/java/org/apache/sling/samples/fling/page/Page.java Sat Apr 9 19:05:31 2016
@@ -0,0 +1,74 @@
+/*
+ * 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.samples.fling.page;
+
+import javax.inject.Inject;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.models.annotations.Model;
+import org.apache.sling.models.annotations.Optional;
+import org.apache.sling.models.annotations.injectorspecific.Self;
+
+import static org.apache.sling.query.SlingQuery.$;
+
+@Model(adaptables = Resource.class)
+public class Page {
+
+ @Self
+ protected Resource resource;
+
+ @Inject
+ private String title;
+
+ @Inject
+ @Optional
+ private String content;
+
+ public Page() {
+ }
+
+ public String getName() {
+ return resource.getName();
+ }
+
+ public String getPath() {
+ return resource.getPath();
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public Iterable<Page> getParents() {
+ return $(resource).parents("fling/page").map(Page.class);
+ }
+
+ public Iterable<Page> getChildren() {
+ return $(resource).children().map(Page.class);
+ }
+
+ public Iterable<Page> getSiblings() {
+ return $(resource).siblings().not($(resource)).map(Page.class);
+ }
+
+}
Added: sling/trunk/samples/fling/src/main/java/org/apache/sling/samples/fling/page/UserPage.java
URL: http://svn.apache.org/viewvc/sling/trunk/samples/fling/src/main/java/org/apache/sling/samples/fling/page/UserPage.java?rev=1738370&view=auto
==============================================================================
--- sling/trunk/samples/fling/src/main/java/org/apache/sling/samples/fling/page/UserPage.java (added)
+++ sling/trunk/samples/fling/src/main/java/org/apache/sling/samples/fling/page/UserPage.java Sat Apr 9 19:05:31 2016
@@ -0,0 +1,84 @@
+/*
+ * 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.samples.fling.page;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.annotation.PostConstruct;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+
+import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.jcr.base.util.AccessControlUtil;
+import org.apache.sling.models.annotations.Model;
+
+@Model(adaptables = Resource.class)
+public class UserPage extends Page {
+
+ private User user;
+
+ private Map<String, String> userProperties;
+
+ public UserPage() {
+ }
+
+ @PostConstruct
+ public void init() throws Exception {
+ final Session session = resource.getResourceResolver().adaptTo(Session.class);
+ final UserManager userManager = AccessControlUtil.getUserManager(session);
+ user = (User) userManager.getAuthorizable(session.getUserID());
+ userProperties = mapUserProperties(user);
+ }
+
+ public User getUser() {
+ return user;
+ }
+
+ public Map<String, String> getUserProperties() {
+ return userProperties;
+ }
+
+ private static Map<String, String> mapUserProperties(final User user) throws RepositoryException {
+ final Map<String, String> userProperties = new HashMap<>();
+ final Iterator<String> keys = user.getPropertyNames();
+ while (keys.hasNext()) {
+ final String key = keys.next();
+ final Value[] values = user.getProperty(key);
+ if (values != null && values.length > 0) {
+ if (values.length == 1) {
+ userProperties.put(key, values[0].getString());
+ } else {
+ final String[] strings = new String[values.length];
+ for (int i = 0; i < values.length; i++) {
+ strings[i] = values[i].getString();
+ }
+ userProperties.put(key, Arrays.toString(strings));
+ }
+ }
+ }
+ return userProperties;
+ }
+
+}
Modified: sling/trunk/samples/fling/src/main/resources/apps/fling/page/simple/html.html
URL: http://svn.apache.org/viewvc/sling/trunk/samples/fling/src/main/resources/apps/fling/page/simple/html.html?rev=1738370&r1=1738369&r2=1738370&view=diff
==============================================================================
--- sling/trunk/samples/fling/src/main/resources/apps/fling/page/simple/html.html (original)
+++ sling/trunk/samples/fling/src/main/resources/apps/fling/page/simple/html.html Sat Apr 9 19:05:31 2016
@@ -17,39 +17,16 @@
specific language governing permissions and limitations
under the License.
-->
-<html data-th-with="page=${resource.adaptTo(@org.apache.sling.samples.fling.Page@class)}">
+<html data-th-with="page=${resource.adaptTo(@org.apache.sling.samples.fling.page.Page@class)}">
<head data-th-replace="/apps/fling/page/fragments/head.html::default">
- <meta charset="UTF-8"/>
- <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
- <title>SIMPLE PAGE</title>
- <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"/>
- <link rel="stylesheet" href="../../../../assets/css/fling.css"/>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
- <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js" type="text/javascript"></script>
</head>
<body>
<div class="container">
<nav class="nav-main">
<div class="pull-left">
- <ul class="breadcrumb" style="direction: rtl" data-th-replace="/apps/fling/page/fragments/navigation.html::breadcrumb">
- <li class="active dropdown">
- <span>2rd BAR</span>
- </li>
- <li class="dropdown">
- <a href="#" class="dropdown-toggle" role="button" data-toggle="dropdown"><span class="caret"></span></a>
- <a href="#">1st FOO</a>
- <ul class="dropdown-menu" role="menu">
- <li role="presentation"><a role="menuitem" tabindex="-1" href="../simple/html.html">1st FOO CHILD</a></li>
- <li role="presentation"><a role="menuitem" tabindex="-1" href="../simple/html.html">2nd FOO CHILD</a></li>
- <li role="presentation"><a role="menuitem" tabindex="-1" href="../simple/html.html">3rd FOO CHILD</a></li>
- <li role="presentation"><a role="menuitem" tabindex="-1" href="../simple/html.html">4th FOO CHILD</a></li>
- </ul>
- </li>
- </ul>
+ <ul class="breadcrumb" style="direction: rtl" data-th-replace="/apps/fling/page/fragments/navigation.html::breadcrumb"></ul>
</div>
- <ul class="nav nav-pills" role="tablist" data-th-replace="/apps/fling/page/fragments/navigation.html::children">
- <li><a href="../user/html.html">3rd BAZ</a></li>
- </ul>
+ <ul class="nav nav-pills" role="tablist" data-th-replace="/apps/fling/page/fragments/navigation.html::children"></ul>
</nav>
<div class="panel panel-primary">
<div class="panel-heading">
@@ -59,9 +36,7 @@
<div data-th-utext="${page.content}"><p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p><pre>At vero eos et accusam et justo duo dolores et ea rebum.</pre></div>
<img src="../../../../assets/images/feather.png" width="355" height="111" data-th-attr="src='/fling/assets/images/feather.png'"/>
</div>
- <div class="panel-footer" data-th-replace="/apps/fling/page/fragments/panel.html::footer">
- <span>user | auth type</span>
- </div>
+ <div class="panel-footer" data-th-replace="/apps/fling/page/fragments/panel.html::footer"></div>
</div>
</div>
</body>
Modified: sling/trunk/samples/fling/src/main/resources/apps/fling/page/user/html.html
URL: http://svn.apache.org/viewvc/sling/trunk/samples/fling/src/main/resources/apps/fling/page/user/html.html?rev=1738370&r1=1738369&r2=1738370&view=diff
==============================================================================
--- sling/trunk/samples/fling/src/main/resources/apps/fling/page/user/html.html (original)
+++ sling/trunk/samples/fling/src/main/resources/apps/fling/page/user/html.html Sat Apr 9 19:05:31 2016
@@ -17,39 +17,16 @@
specific language governing permissions and limitations
under the License.
-->
-<html data-th-with="page=${resource.adaptTo(@org.apache.sling.samples.fling.UserPage@class)}">
+<html data-th-with="page=${resource.adaptTo(@org.apache.sling.samples.fling.page.UserPage@class)}">
<head data-th-replace="/apps/fling/page/fragments/head.html::default">
- <meta charset="UTF-8"/>
- <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
- <title>USER PAGE</title>
- <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"/>
- <link rel="stylesheet" href="../../../../assets/css/fling.css"/>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
- <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js" type="text/javascript"></script>
</head>
<body>
<div class="container">
<nav class="nav-main">
<div class="pull-left">
- <ul class="breadcrumb" style="direction: rtl" data-th-replace="/apps/fling/page/fragments/navigation.html::breadcrumb">
- <li class="active dropdown">
- <span>2rd BAR</span>
- </li>
- <li class="dropdown">
- <a href="#" class="dropdown-toggle" role="button" data-toggle="dropdown"><span class="caret"></span></a>
- <a href="../simple/html.html">1st FOO</a>
- <ul class="dropdown-menu" role="menu">
- <li role="presentation"><a role="menuitem" tabindex="-1" href="../simple/html.html">1st FOO CHILD</a></li>
- <li role="presentation"><a role="menuitem" tabindex="-1" href="../simple/html.html">2nd FOO CHILD</a></li>
- <li role="presentation"><a role="menuitem" tabindex="-1" href="../simple/html.html">3rd FOO CHILD</a></li>
- <li role="presentation"><a role="menuitem" tabindex="-1" href="../simple/html.html">4th FOO CHILD</a></li>
- </ul>
- </li>
- </ul>
+ <ul class="breadcrumb" style="direction: rtl" data-th-replace="/apps/fling/page/fragments/navigation.html::breadcrumb"></ul>
</div>
- <ul class="nav nav-pills" role="tablist" data-th-replace="/apps/fling/page/fragments/navigation.html::children">
- <li><a href="../user/html.html">3rd BAZ</a></li>
- </ul>
+ <ul class="nav nav-pills" role="tablist" data-th-replace="/apps/fling/page/fragments/navigation.html::children"></ul>
</nav>
<div class="panel panel-primary">
<div class="panel-heading">
@@ -80,9 +57,7 @@
</form>
<img src="../../../../assets/images/feather.png" width="355" height="111" data-th-attr="src='/fling/assets/images/feather.png'"/>
</div>
- <div class="panel-footer" data-th-replace="/apps/fling/page/fragments/panel.html::footer">
- <span>user | auth type</span>
- </div>
+ <div class="panel-footer" data-th-replace="/apps/fling/page/fragments/panel.html::footer"></div>
</div>
</div>
</body>