Example #1
0
 public static final ParsedFacet getInstance(
     String facetNameConfig, String facetNodeName, HippoVirtualProvider provider)
     throws Exception {
   String cacheKey = facetNameConfig + '\uFFFF' + facetNodeName;
   ParsedFacet pf = sharedCache.get(cacheKey);
   if (pf == null) {
     pf = new ParsedFacet(facetNameConfig, facetNodeName, provider);
     sharedCache.put(cacheKey, pf);
   } else {
     // we need to check if the namespace did not bump or change. IF so, we evict this item from
     // cache.
     Path currentQName = provider.resolvePath(pf.jcrPropertyName);
     // if the currentQName is equal to pf.namespacedProperty , there was no namespace bumb and we
     // can return pf
     if (!currentQName.toString().equals(pf.namespacedProperty)) {
       pf = new ParsedFacet(facetNameConfig, facetNodeName, provider);
       sharedCache.put(cacheKey, pf);
     }
   }
   return pf;
 }
Example #2
0
 public ParsedFacet(String facetNameConfig, String facetNodeName, HippoVirtualProvider provider)
     throws Exception {
   displayFacetName = facetNameConfig;
   boolean mapped = false;
   // jcrPropertyName is format: prefix:localname
   jcrPropertyName = facetNameConfig;
   if (facetNodeName != null && !"".equals(facetNodeName)) {
     displayFacetName = facetNodeName;
     mapped = true;
   }
   if (facetNameConfig.indexOf("$[") > -1) {
     try {
       rangeConfig = facetNameConfig.substring(facetNameConfig.indexOf("$[") + 1);
       JSONArray jsonArray = JSONArray.fromObject(rangeConfig);
       facetRanges = (List<FacetRange>) JSONArray.toCollection(jsonArray, FacetRange.class);
       jcrPropertyName = facetNameConfig.substring(0, facetNameConfig.indexOf("$["));
       if (!mapped) {
         displayFacetName = jcrPropertyName;
       }
       validate(facetRanges);
     } catch (IllegalArgumentException e) {
       throw (e);
     } catch (Exception e) {
       throw new Exception(
           "Malformed facet range configuration '"
               + facetNameConfig
               + "'. Valid format is for example '"
               + VALID_RANGE_EXAMPLE
               + "'",
           e);
     }
   }
   Path qName = provider.resolvePath(jcrPropertyName);
   this.namespacedProperty = qName.toString();
   if (facetRanges != null) {
     for (FacetRange range : facetRanges) {
       range.setNamespacedProperty(namespacedProperty);
     }
   }
 }