Author: cziegeler
Date: Mon Feb 1 17:14:22 2016
New Revision: 1727976
URL: http://svn.apache.org/viewvc?rev=1727976&view=rev
Log:
SLING-5474 : Move sightly use objects to a different package. Apply patch from
Andrei Dulvac
Added:
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/HApiUse.java
(with props)
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/TypeView.java
(with props)
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/package-info.java
(with props)
Removed:
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/HApiUse.java
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/TypeView.java
Modified:
sling/trunk/contrib/extensions/hapi/core/src/main/resources/SLING-INF/libs/sling/hapi/components/type/type.html
Added:
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/HApiUse.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/HApiUse.java?rev=1727976&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/HApiUse.java
(added)
+++
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/HApiUse.java
Mon Feb 1 17:14:22 2016
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * 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.hapi.sightly;
+
+import java.util.Map;
+
+import javax.script.Bindings;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.scripting.SlingBindings;
+import org.apache.sling.api.scripting.SlingScriptHelper;
+import org.apache.sling.hapi.HApiUtil;
+import org.apache.sling.hapi.MicrodataAttributeHelper;
+import org.apache.sling.scripting.sightly.pojo.Use;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Sightly use class helper to provide the hypermedia API microdata attributes
for the type configured throught the 'type' binding.
+ * <p>The type can be a JCR path or a fully qualified domain name like in
+ * {@link HApiUtil#getTypeNode(org.apache.sling.api.resource.ResourceResolver,
String)}</p>
+ * <p>The convenience get methods are meant to be used in the
'data-sly-attribute' in the sightly script.</p>
+ */
+public class HApiUse implements Use {
+ private static final Logger LOG = LoggerFactory.getLogger(HApiUse.class);
+
+ private HApiUtil hapi;
+ private MicrodataAttributeHelper helper;
+ private SlingHttpServletRequest request;
+ private SlingScriptHelper sling;
+ private ResourceResolver resourceResolver;
+ private String typeId;
+ private Map<String, String> itemTypeAttr;
+ private Map<String, Map<String, String>> itemPropAttrs;
+ private Map<String, String> itemPropTypes;
+
+ /**
+ * {@inheritDoc}
+ * @param bindings
+ */
+ @Override
+ public void init(Bindings bindings) {
+ request = (SlingHttpServletRequest)
bindings.get(SlingBindings.REQUEST);
+ sling = (SlingScriptHelper) bindings.get(SlingBindings.SLING);
+ resourceResolver = request.getResourceResolver();
+ typeId = (String) bindings.get("type");
+ LOG.debug("init type: {}", typeId);
+
+ try {
+ activate();
+ } catch (Exception e) {
+ LOG.error("Failed to activate Use class", e);
+ }
+ }
+
+ /**
+ * Initializes the helper and the attribute maps for the given type though
the bindings
+ * @throws Exception
+ */
+ public void activate() throws Exception {
+ hapi = sling.getService(HApiUtil.class);
+ helper = hapi.getHelper(resourceResolver, typeId);
+ itemTypeAttr = helper.itemtypeMap();
+ itemPropAttrs = helper.allItemPropMap();
+ itemPropTypes = helper.allPropTypesMap();
+ }
+
+ /**
+ * Get the itemtype html attributes map for the type
+ * @return
+ */
+ public Map<String, String> getItemtype() {
+ LOG.debug("itemtype attrs: {}", itemTypeAttr);
+ return itemTypeAttr;
+ }
+
+ /**
+ * Get the itemprop attributes map for the type, for each property.
+ * The key is the property name and the value is a map of html attributes
for the property
+ * @return
+ */
+ public Map<String, Map<String, String>> getItemprop() {
+ LOG.debug("itemprop attrs: {}", itemPropAttrs);
+ return itemPropAttrs;
+ }
+
+ /**
+ * Get a map of the type for each property name of the type
+ * The key is the property name and the value is the type path in JCR
+ * @return
+ */
+ public Map<String, String> getProptype() {
+ LOG.debug("property type attrs: {}", itemPropTypes);
+ return itemPropTypes;
+ }
+}
Propchange:
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/HApiUse.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/HApiUse.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added:
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/TypeView.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/TypeView.java?rev=1727976&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/TypeView.java
(added)
+++
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/TypeView.java
Mon Feb 1 17:14:22 2016
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * 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.hapi.sightly;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.scripting.SlingBindings;
+import org.apache.sling.api.scripting.SlingScriptHelper;
+import org.apache.sling.hapi.HApiProperty;
+import org.apache.sling.hapi.HApiType;
+import org.apache.sling.hapi.HApiUtil;
+import org.apache.sling.scripting.sightly.pojo.Use;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.script.Bindings;
+import java.util.*;
+
+public class TypeView implements Use {
+ private static final Logger LOG = LoggerFactory.getLogger(TypeView.class);
+
+ private HApiUtil hapi;
+ private HApiType me;
+ private HApiType parent;
+
+ private String description;
+ private SlingHttpServletRequest request;
+ private SlingScriptHelper sling;
+ private Resource resource;
+ private ResourceResolver resourceResolver;
+
+ public void init(Bindings bindings) {
+ request = (SlingHttpServletRequest)
bindings.get(SlingBindings.REQUEST);
+ sling = (SlingScriptHelper) bindings.get(SlingBindings.SLING);
+ resource = (Resource)bindings.get(SlingBindings.RESOURCE);
+ resourceResolver = request.getResourceResolver();
+
+ try {
+ activate();
+ } catch (Exception e) {
+ LOG.error("Failed to activate Use class", e);
+ }
+ }
+
+ public void activate() throws Exception {
+ hapi = sling.getService(HApiUtil.class);
+ me = hapi.fromPath(resourceResolver, resource.getPath());
+ LOG.debug("me: {} resource: {}", me, resource.getPath());
+ description = me.getDescription();
+ parent = me.getParent();
+ }
+
+ public String getTitle() {
+ return me.getFqdn();
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getParentUrl() {
+ if (null != parent) {
+ return parent.getUrl();
+ } else {
+ return null;
+ }
+ }
+
+ public String getParentFqdn() {
+ if (null != parent) {
+ return parent.getFqdn();
+ } else {
+ return null;
+ }
+ }
+
+ public List<String> getParameters() {
+ return me.getParameters();
+ }
+
+ public List<HApiProperty> getProps() {
+ List<HApiProperty> props = new
ArrayList<HApiProperty>(me.getAllProperties().values());
+ LOG.debug("props: ", props);
+ return props;
+ }
+
+ public boolean getHasProps() {
+ return getProps().size() > 0;
+ }
+}
Propchange:
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/TypeView.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/TypeView.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added:
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/package-info.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/package-info.java?rev=1727976&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/package-info.java
(added)
+++
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/package-info.java
Mon Feb 1 17:14:22 2016
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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.
+
******************************************************************************/
+
+@Version("1.0.0")
+package org.apache.sling.hapi.sightly;
+
+import aQute.bnd.annotation.Version;
Propchange:
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/sightly/package-info.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Modified:
sling/trunk/contrib/extensions/hapi/core/src/main/resources/SLING-INF/libs/sling/hapi/components/type/type.html
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/hapi/core/src/main/resources/SLING-INF/libs/sling/hapi/components/type/type.html?rev=1727976&r1=1727975&r2=1727976&view=diff
==============================================================================
---
sling/trunk/contrib/extensions/hapi/core/src/main/resources/SLING-INF/libs/sling/hapi/components/type/type.html
(original)
+++
sling/trunk/contrib/extensions/hapi/core/src/main/resources/SLING-INF/libs/sling/hapi/components/type/type.html
Mon Feb 1 17:14:22 2016
@@ -17,7 +17,7 @@
~ specific language governing permissions and limitations
~ under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
-<html data-sly-use.type="org.apache.sling.hapi.TypeView" lang="${type.lang}">
+<html data-sly-use.type="org.apache.sling.hapi.sightly.TypeView"
lang="${type.lang}">
<head>
<meta charset="utf-8">