Convert the incoming Resource to a JCR path (but don't attempt to load the node).

@param resource Jena Resource to convert
@param values a map that will receive the matching URI template variables for future use.
@return String of JCR path
424438
private String asString(final Resource resource, final Map<String, String> values) {
        if (uriTemplate.match(resource.getURI(), values) && values.containsKey("path")) {
            String path = "/" + values.get("path");

            final Matcher matcher = FORWARD_COMPONENT_PATTERN.matcher(path);

            if (matcher.matches()) {
                final boolean metadata = matcher.group(1) != null;
                final boolean versioning = matcher.group(2) != null;
                final boolean webacAcl = matcher.group(4) != null;

                if (versioning) {
                    path = replaceOnce(path, "/" + FCR_VERSIONS, "/" + LDPCV_TIME_MAP);
                }

                if (metadata) {
                    path = replaceOnce(path, "/" + FCR_METADATA, "/" + FEDORA_DESCRIPTION);
                }

                if (webacAcl) {
                    path = replaceOnce(path, "/" + FCR_ACL, "/" + CONTAINER_WEBAC_ACL);
                }
            }

            path = forward.convert(path);

            if (path == null) {
                return null;
            }

            try {
                path = URLDecoder.decode(path, "UTF-8");
            } catch (final UnsupportedEncodingException e) {
                LOGGER.debug("Unable to URL-decode path " + e + " as UTF-8", e);
            }

            if (path.isEmpty()) {
                return "/";
            }

            // Validate path
            if (path.contains("//")) {
                throw new InvalidResourceIdentifierException("Path contains empty element! " + path);
            }
            return path;
        }

        if (isRootWithoutTrailingSlash(resource)) {
            return "/";
        }

        return null;
    }
1143694
private Set<String> getResourceNamesFromJar(String path, URL resourceURL) {

		URLConnection con = null;

		try {
			if (resourceURL.toString().startsWith(JawrConstant.JAR_URL_PREFIX)) {
				con = resourceURL.openConnection();
			}
		} catch (IOException e) {

			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug("Unable to find resources name for path '" + path + "'", e);
			}
			return Collections.emptySet();
		}

		JarFile jarFile;
		String jarFileUrl;
		String rootEntryPath;
		boolean newJarFile = false;

		try {
			if (con instanceof JarURLConnection) {
				// Should usually be the case for traditional JAR files.
				JarURLConnection jarCon = (JarURLConnection) con;
				jarCon.setUseCaches(true);
				jarFile = jarCon.getJarFile();
				JarEntry jarEntry = jarCon.getJarEntry();
				rootEntryPath = (jarEntry != null ? jarEntry.getName() : "");
			} else {
				// No JarURLConnection -> need to resort to URL file parsing.
				// We'll assume URLs of the format "jar:path!/entry", with the
				// protocol
				// being arbitrary as long as following the entry format.
				// We'll also handle paths with and without leading "file:"
				// prefix.
				String urlFile = resourceURL.getFile();
				int separatorIndex = urlFile.indexOf(JAR_URL_SEPARATOR);
				if (separatorIndex != -1) {
					jarFileUrl = urlFile.substring(0, separatorIndex);
					rootEntryPath = urlFile.substring(separatorIndex + JAR_URL_SEPARATOR.length());
					jarFile = getJarFile(jarFileUrl);
				} else {
					jarFile = new JarFile(urlFile);
					rootEntryPath = "";
				}
				newJarFile = true;
			}
		} catch (IOException e) {
			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug("Unable to find resources name for path '" + path + "'", e);
			}
			return Collections.emptySet();
		}
		try {
			if (!"".equals(rootEntryPath) && !rootEntryPath.endsWith("/")) {
				// Root entry path must end with slash to allow for proper
				// matching.
				// The Sun JRE does not return a slash here, but BEA JRockit
				// does.
				rootEntryPath = rootEntryPath + "/";
			}
			Set<String> result = new LinkedHashSet<>(8);
			for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
				JarEntry entry = entries.nextElement();
				String entryPath = entry.getName();
				if (isDirectChildPath(rootEntryPath, entryPath)) {
					String relativePath = entryPath.substring(rootEntryPath.length());
					result.add(relativePath);
				}
			}
			return result;
		} finally {
			// Close jar file, but only if freshly obtained -
			// not from JarURLConnection, which might cache the file reference.
			if (newJarFile) {
				try {
					jarFile.close();
				} catch (IOException e) {
					// Nothing to do
				}
			}
		}
	}
139522
private void convertStoragePathValue(
            final Map<String, String> data,
            final StorageTree storageTree,
            final String name,
            final String propValue,
            final Map<String, Object> renderingOptions
    ) throws ConfigurationException
    {
        //a storage path property
        String root = null;
        if (null != renderingOptions.get( StringRenderingConstants.STORAGE_PATH_ROOT_KEY)) {
            root = renderingOptions.get(StringRenderingConstants.STORAGE_PATH_ROOT_KEY).toString();
        }
        String filter = null;
        if (null != renderingOptions.get(StringRenderingConstants.STORAGE_FILE_META_FILTER_KEY)) {
            filter = renderingOptions.get(StringRenderingConstants.STORAGE_FILE_META_FILTER_KEY).toString();
        }
        boolean clearValue = isValueConversionFailureRemove(renderingOptions);
        if (null != root && !PathUtil.hasRoot(propValue, root)) {
            if(clearValue) {
                data.remove(name);
            }
            return;
        }
        try {
            Resource<ResourceMeta> resource = storageTree.getResource(propValue);
            ResourceMeta contents = resource.getContents();
            //test filter
            if (filter != null) {
                String[] filterComponents = filter.split("=", 2);
                if (filterComponents.length == 2) {
                    String key = filterComponents[0];
                    String test = filterComponents[1];
                    Map<String, String> meta = contents.getMeta();
                    if (meta == null || !test.equals(meta.get(key))) {
                        if(clearValue) {
                            data.remove(name);
                        }
                        return;
                    }
                }
            }
            //finally load storage contents into a string
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            contents.writeContent(byteArrayOutputStream);
            data.put(name, new String(byteArrayOutputStream.toByteArray()));
        } catch (StorageException | IOException e) {
            if(clearValue) {
                data.remove(name);
                return;
            }
            throw new ConfigurationException("Unable to load configuration key '" +
                    name + "' value from storage path:  " + propValue, e);
        }
    }
753120
private FedoraResource getResourceFromSubject(final String subjectUri) {
        final UriTemplate uriTemplate =
            new UriTemplate(uriInfo.getBaseUriBuilder().clone().path(FedoraLdp.class).toTemplate());
        final Map<String, String> values = new HashMap<>();
        uriTemplate.match(subjectUri, values);
        if (values.containsKey("path")) {
            try {
                return translator().convert(translator().toDomain(values.get("path")));
            } catch (final RuntimeException e) {
                if (e.getCause() instanceof PathNotFoundException) {
                    //there is at least one case (ie Time Map endpoints - aka /fcr:versions) where the underlying jcr
                    // node will not exist while the end point is visible to the user.
                    return null;
                } else {
                    throw e;
                }
            }
        }
        return null;
    }
903249
public URL getResource(String resourceName, BeanContextChild child)
	{
		if (resourceName == null || child == null)
		{
			throw new NullPointerException();
		}
		if (!contains(child))
		{
			throw new IllegalArgumentException(Messages.getString("beans.6D"));
		}

		return ClassLoader.getSystemResource(resourceName);
	}
307983
public static JCalValue object(ListMultimap<String, Object> value) {
		Map<String, JsonValue> object = new LinkedHashMap<String, JsonValue>();
		for (Map.Entry<String, List<Object>> entry : value) {
			String key = entry.getKey();
			List<Object> list = entry.getValue();

			JsonValue v;
			if (list.size() == 1) {
				v = new JsonValue(list.get(0));
			} else {
				List<JsonValue> array = new ArrayList<JsonValue>(list.size());
				for (Object element : list) {
					array.add(new JsonValue(element));
				}
				v = new JsonValue(array);
			}
			object.put(key, v);
		}
		return new JCalValue(new JsonValue(object));
	}
648221
protected JCTree resource() {
        JCModifiers optFinal = optFinal(Flags.FINAL);
        JCExpression type = parseType();
        int pos = token.pos;
        Name ident = ident();
        return variableDeclaratorRest(pos, optFinal, type, ident, true, null);
    }
750236
public static JCalValue structured(List<List<?>> values) {
		List<JsonValue> array = new ArrayList<JsonValue>(values.size());

		for (List<?> list : values) {
			if (list.isEmpty()) {
				array.add(new JsonValue(""));
				continue;
			}

			if (list.size() == 1) {
				Object value = list.get(0);
				if (value == null) {
					value = "";
				}
				array.add(new JsonValue(value));
				continue;
			}

			List<JsonValue> subArray = new ArrayList<JsonValue>(list.size());
			for (Object value : list) {
				if (value == null) {
					value = "";
				}
				subArray.add(new JsonValue(value));
			}
			array.add(new JsonValue(subArray));
		}

		return new JCalValue(new JsonValue(array));
	}
980360
public String resource_to_string(base_resource resrc, String id, options option,Boolean warning, String onerror) 
	{
		String result = "{ ";
			if (option != null || (warning!=null && warning==true) || (!onerror.equals(""))) { 
				result = result + "\"params\":{";
				if(option != null)
				{
					if (option.get_action() != null) {
						result = result + "\"action\":\"" + option.get_action() + "\",";
					}					
				}
				if(warning != null && warning==true)
				{
					result = result + "\"warning\":\"yes\",";
				}
				if((!onerror.equals("")))
				{			
					result = result +"\"onerror\":\"" + onerror +"\"";			
				}		
				result  = result + "},";
			}
		
		if (id != null)
			result = result + "\"sessionid\":\"" + id + "\",";
		
		result = result + "\"" + resrc.get_object_type() + "\":" + this.resource_to_string(resrc) + "}";
		return result;
	}
573879
private Set<String> getStringSet(I_CmsXmlContentLocation val, String path) {

        Set<String> valueSet = new HashSet<String>();
        if ((val != null)) {
            List<I_CmsXmlContentValueLocation> singleValueLocs = val.getSubValues(path);
            for (I_CmsXmlContentValueLocation singleValueLoc : singleValueLocs) {
                String value = singleValueLoc.getValue().getStringValue(m_cms).trim();
                valueSet.add(value);
            }
        }
        return valueSet;
    }
168084
protected String determineResourceName(final Resource resource) {
        String resourceName = null;

        if (resource instanceof ContextResource) {
            resourceName = ((ContextResource) resource).getPathWithinContext();

        } else if (resource instanceof ByteArrayResource) {
            resourceName = resource.getDescription();

        } else {
            try {
                resourceName = resource.getFile().getAbsolutePath();
            } catch (IOException e) {
                resourceName = resource.getFilename();
            }
        }
        return resourceName;
    }
594388
public static Map toMap(final Object value, final Locale locale) {
        return builder().locale(locale).build().mapper().convertValue(value, LinkedHashMap.class);
    }
1126120
@NotNull
    public static XPath createXPath(@Nullable final String... values) {
        final NamespaceContext context = new NamespaceContextMap(values);
        final XPath xPath = XPathFactory.newInstance().newXPath();
        xPath.setNamespaceContext(context);
        return xPath;
    }
487059
public String getMappingForResourceType(String resourceType) {

        String[] resourceTypeParams = getResourceTypes().get(resourceType);
        if (resourceTypeParams == null) {
            return null;
        } else {
            return resourceTypeParams[1];
        }
    }
165210
@SuppressWarnings({ "unused", "null" })
  public static @NotNull String jcrQueryLiteral(@NotNull String value) {
    if (value == null) {
      throw new IllegalArgumentException("Invalid query string value: " + value);
    }
    return "'" + StringUtils.replace(value, "'", "''") + "'";
  }
700204
public static final String printResourceType(ResourceType value)
   {
      return (Integer.toString(value == null ? ResourceType.WORK.getValue() : value.getValue()));
   }
80411
private void getAnchorLegacyMetadataFromRel(ValueMap resourceProps, Element element) {
    // Check href attribute - do not change elements with no href or links to anchor names
    String href = element.getAttributeValue("href");
    String linkWindowTarget = element.getAttributeValue("target");
    if (href == null || href.startsWith("#")) {
      return;
    }

    // get link metadata from rel element
    JSONObject metadata = null;
    String metadataString = element.getAttributeValue("rel");
    if (StringUtils.isNotEmpty(metadataString)) {
      try {
        metadata = new JSONObject(metadataString);
      }
      catch (JSONException ex) {
        log.debug("Invalid link metadata: " + metadataString, ex);
      }
    }
    if (metadata == null) {
      metadata = new JSONObject();
    }

    // transform link metadata to virtual JCR resource with JCR properties
    JSONArray metadataPropertyNames = metadata.names();
    if (metadataPropertyNames != null) {
      for (int i = 0; i < metadataPropertyNames.length(); i++) {
        String metadataPropertyName = metadataPropertyNames.optString(i);

        // check if value is array
        JSONArray valueArray = metadata.optJSONArray(metadataPropertyName);
        if (valueArray != null) {
          // store array values
          List<String> values = new ArrayList<String>();
          for (int j = 0; j < valueArray.length(); j++) {
            values.add(valueArray.optString(j));
          }
          resourceProps.put(metadataPropertyName, values.toArray(new String[values.size()]));
        }
        else {
          // store simple value
          Object value = metadata.opt(metadataPropertyName);
          if (value != null) {
            resourceProps.put(metadataPropertyName, value);
          }
        }
      }
    }

    // detect link type
    LinkType linkType = null;
    String linkTypeString = resourceProps.get(LinkNameConstants.PN_LINK_TYPE, String.class);
    for (Class<? extends LinkType> candidateClass : linkHandlerConfig.getLinkTypes()) {
      LinkType candidate = AdaptTo.notNull(adaptable, candidateClass);
      if (StringUtils.isNotEmpty(linkTypeString)) {
        if (StringUtils.equals(linkTypeString, candidate.getId())) {
          linkType = candidate;
          break;
        }
      }
      else if (candidate.accepts(href)) {
        linkType = candidate;
        break;
      }
    }
    if (linkType == null) {
      // skip further processing if link type was not detected
      return;
    }

    // workaround: strip off ".html" extension if it was added automatically by the RTE
    if (linkType instanceof InternalLinkType || linkType instanceof MediaLinkType) {
      String htmlSuffix = "." + FileExtension.HTML;
      if (StringUtils.endsWith(href, htmlSuffix)) {
        href = StringUtils.substringBeforeLast(href, htmlSuffix);
      }
    }

    // store link reference (property depending on link type)
    resourceProps.put(linkType.getPrimaryLinkRefProperty(), href);
    resourceProps.put(LinkNameConstants.PN_LINK_WINDOW_TARGET, linkWindowTarget);

  }