This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.hapi-1.0.0
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-hapi.git

commit 6a6dde6bfd3b64feafb24e0a33dfa22453e18ead
Author: Bertrand Delacretaz <[email protected]>
AuthorDate: Fri Sep 25 13:30:05 2015 +0000

    SLING-5061 - HApiType.getUrl() should be an absolute URL - contributed by 
Andrei Dulvac, thanks!
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/hapi/core@1705296
 13f79535-47bb-0310-9956-ffa450edef68
---
 src/main/java/org/apache/sling/hapi/impl/HApiTypeImpl.java    | 11 ++++++++---
 src/main/java/org/apache/sling/hapi/impl/HApiUtilImpl.java    | 11 ++++++++---
 .../apache/sling/hapi/impl/MicrodataAttributeHelperImpl.java  |  3 ++-
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/sling/hapi/impl/HApiTypeImpl.java 
b/src/main/java/org/apache/sling/hapi/impl/HApiTypeImpl.java
index 8648179..0d25645 100644
--- a/src/main/java/org/apache/sling/hapi/impl/HApiTypeImpl.java
+++ b/src/main/java/org/apache/sling/hapi/impl/HApiTypeImpl.java
@@ -22,6 +22,7 @@ import org.apache.sling.hapi.HApiProperty;
 import org.apache.sling.hapi.HApiType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+
 import java.util.*;
 
 /**
@@ -30,32 +31,36 @@ import java.util.*;
 public class HApiTypeImpl implements HApiType {
 
     public static final Logger LOG = 
LoggerFactory.getLogger(HApiTypeImpl.class);
-
     private HApiType parent;
 
     private String name;
 
     private String description;
+
+    private final String serverUrl;
     private String path;
     private String fqdn;
     private List<String> parameters;
     private Map<String, HApiProperty> properties;
     private boolean isAbstract;
 
+
     /**
      * A new HApiType
      * @param name
      * @param description
+     * @param serverUrl
      * @param path
      * @param fqdn
      * @param parameters
      * @param properties
      * @param parent
      */
-    public HApiTypeImpl(String name, String description, String path, String 
fqdn, List<String> parameters, Map<String,
+    public HApiTypeImpl(String name, String description, String serverUrl, 
String path, String fqdn, List<String> parameters, Map<String,
             HApiProperty> properties, HApiType parent, boolean isAbstract) {
         this.name = name;
         this.description = description;
+        this.serverUrl = serverUrl.substring(0, serverUrl.length() - 
(serverUrl.endsWith("/") ? 1 : 0));
         this.path = path;
         this.fqdn = fqdn;
         this.parameters = parameters;
@@ -94,7 +99,7 @@ public class HApiTypeImpl implements HApiType {
      */
     @Override
     public String getUrl() {
-        return getPath() + ".html";
+        return this.serverUrl + getPath() + ".html";
     }
 
     /**
diff --git a/src/main/java/org/apache/sling/hapi/impl/HApiUtilImpl.java 
b/src/main/java/org/apache/sling/hapi/impl/HApiUtilImpl.java
index 7b448f5..c6810ea 100644
--- a/src/main/java/org/apache/sling/hapi/impl/HApiUtilImpl.java
+++ b/src/main/java/org/apache/sling/hapi/impl/HApiUtilImpl.java
@@ -46,18 +46,24 @@ public class HApiUtilImpl implements HApiUtil {
     @Property(label = "HApi Resource Type", cardinality = 0, value = 
DEFAULT_RESOURCE_TYPE)
     public static final String HAPI_RESOURCE_TYPE = 
"org.apache.sling.hapi.tools.resourcetype";
 
-
     @Property(label = "HApi Types Search Paths", cardinality=50, value = 
{"/libs/sling/hapi/types"})
     public static final String HAPI_PATHS = 
"org.apache.sling.hapi.tools.searchpaths";
 
+
+    private static final String DEFAULT_SERVER_URL = "http://localhost:8080";;
+    @Property(label = "External server URL", cardinality = 0, value = 
DEFAULT_SERVER_URL)
+    public static final String HAPI_EXTERNAL_URL = 
"org.apache.sling.hapi.tools.externalurl";
+
     public static String resourceType;
     public static String[] hApiPaths;
+    public static String serverContextPath;
 
 
     @Activate
     private void activate(ComponentContext context, Map<String, Object> 
configuration) {
         resourceType = 
PropertiesUtil.toString(configuration.get(HAPI_RESOURCE_TYPE), 
DEFAULT_RESOURCE_TYPE);
         hApiPaths = 
PropertiesUtil.toStringArray(configuration.get(HAPI_PATHS));
+        serverContextPath = 
PropertiesUtil.toString(configuration.get(HAPI_EXTERNAL_URL), 
DEFAULT_SERVER_URL);
     }
 
     /**
@@ -133,7 +139,7 @@ public class HApiUtilImpl implements HApiUtil {
         for (Value p : Arrays.asList(parameterValues)) {
             parameters.add(p.getString());
         }
-        HApiTypeImpl newType = new HApiTypeImpl(name, description, path, fqdn, 
parameters, null, null, false);
+        HApiTypeImpl newType = new HApiTypeImpl(name, description, 
serverContextPath, path, fqdn, parameters, null, null, false);
         TypesCache.getInstance(this).addType(newType);
 
         try {
@@ -151,7 +157,6 @@ public class HApiUtilImpl implements HApiUtil {
             Iterator<Node> it = typeNode.getNodes();
             while (it.hasNext()) {
                 Node propNode = it.next();
-                System.out.println("Node=" + propNode);
                 String propName = propNode.getName();
                 String propDescription = propNode.hasProperty("description") ? 
propNode.getProperty("description").getString() : "";
 
diff --git 
a/src/main/java/org/apache/sling/hapi/impl/MicrodataAttributeHelperImpl.java 
b/src/main/java/org/apache/sling/hapi/impl/MicrodataAttributeHelperImpl.java
index 4d3b8b7..85ae13d 100644
--- a/src/main/java/org/apache/sling/hapi/impl/MicrodataAttributeHelperImpl.java
+++ b/src/main/java/org/apache/sling/hapi/impl/MicrodataAttributeHelperImpl.java
@@ -35,6 +35,7 @@ public class MicrodataAttributeHelperImpl implements 
MicrodataAttributeHelper {
     private final ResourceResolver resolver;
     HApiType type;
 
+
     /**
      * Get a new microdata html attributes helper for the given HApiType 
object.
      * <p>Provides convenience methods to get the html attributes needed for 
instrumenting the markup with a Hypermedia API</p>
@@ -58,7 +59,7 @@ public class MicrodataAttributeHelperImpl implements 
MicrodataAttributeHelper {
      */
     public Map<String, String> itemtypeMap() {
         Map<String, String> attrMap = new AttrMap(2);
-        attrMap.put("itemtype", type.getPath() + ".html");
+        attrMap.put("itemtype", type.getUrl());
         attrMap.put("itemscope", 
String.valueOf(!type.getAllProperties().isEmpty()));
         
         return attrMap;

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to