View Javadoc

1   /*
2    * Copyright 2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.properties.admin.resources.representation.html.share;
17  
18  import java.net.URI;
19  
20  import javax.ws.rs.core.UriInfo;
21  
22  /**
23   * Helper to create request paths.
24   */
25  public final class HtmlPathHelper
26  {
27    // ********************************* Fields *********************************
28  
29    // --- constants ------------------------------------------------------------
30  
31    // --- members --------------------------------------------------------------
32  
33    /**
34     * The helper to construct paths.
35     */
36    private final UriInfo uriInfo;
37  
38    // ****************************** Initializer *******************************
39  
40    // ****************************** Constructors ******************************
41  
42    /**
43     * Default constructor.
44     *
45     * @param uriInfo the helper to construct paths.
46     */
47    public HtmlPathHelper(final UriInfo uriInfo)
48    {
49      this.uriInfo = uriInfo;
50    }
51  
52    // ****************************** Inner Classes *****************************
53  
54    // ********************************* Methods ********************************
55  
56    // --- init -----------------------------------------------------------------
57  
58    // --- get&set --------------------------------------------------------------
59  
60    // --- business -------------------------------------------------------------
61  
62    /**
63     * Returns an absolute path to the given css file.
64     *
65     * @param relativePath the path relative to the css folder (without leading
66     *          slash).
67     * @return the absolute path to the CSS resource on the server.
68     */
69    public String css(final String relativePath)
70    {
71      return uriInfo.getBaseUriBuilder().path("../css/" + relativePath).build()
72          .normalize().toString();
73    }
74  
75    /**
76     * Returns an absolute path to the given jquery file.
77     *
78     * @param relativePath the path relative to the jquery folder (without leading
79     *          slash).
80     * @return the absolute path to the jquery resource on the server.
81     */
82    public String jquery(final String relativePath)
83    {
84      return uriInfo.getBaseUriBuilder().path("../jquery/" + relativePath)
85          .build().normalize().toString();
86    }
87  
88    /**
89     * Returns an absolute path to a bootstrap resource.
90     *
91     * @param relativePath the path relative to the bootstrap folder (without
92     *          leading slash).
93     * @return the absolute path to the bootstrap resource on the server.
94     */
95    public String bootstrap(final String relativePath)
96    {
97      return uriInfo.getBaseUriBuilder().path("../bootstrap/" + relativePath)
98          .build().normalize().toString();
99    }
100 
101   /**
102    * Returns the path to the datasource configuration on a JBoss server.
103    *
104    * @return the path to the datasource configuration on a JBoss server.
105    */
106   public String ds()
107   {
108     final URI baseUri = uriInfo.getBaseUri();
109     final String uri =
110         baseUri.getScheme() + "://" + baseUri.getHost() + ':' + "9990"
111             + "/console/App.html#ds-metrics";
112     return uri;
113   }
114 
115   // --- object basics --------------------------------------------------------
116 
117 }