/*
(non-Javadoc)
@see org.springframework.hateoas.server.LinkRelationProvider#getItemResourceRelFor(java.lang.Class)
508536
@Override
	public LinkRelation getItemResourceRelFor(Class<?> type) {

		Assert.notNull(type, "Type must not be null!");

		Relation annotation = lookupAnnotation(type);

		if (annotation == null || Relation.NO_RELATION.equals(annotation.value())) {
			throw new IllegalStateException(String.format("Type %s is not supported!", type.getName()));
		}

		return LinkRelation.of(annotation.value());
	}
100267
public static URL getResource(Class<?> loadClass, String name,
								  boolean checkParents) throws ClassNotFoundException {
		URL url = null;
		ClassLoader loader = Thread.currentThread().getContextClassLoader();
		while (url == null && loader != null) {
			url = loader.getResource(name);
			loader = (url == null && checkParents) ? loader.getParent() : null;
		}

		loader = loadClass == null ? null : loadClass.getClassLoader();
		while (url == null && loader != null) {
			url = loader.getResource(name);
			loader = (url == null && checkParents) ? loader.getParent() : null;
		}

		if (url == null) {
			url = ClassLoader.getSystemResource(name);
		}

		return url;
	}
314586
public final AbstractItem _findById(long itemID) throws SevereMessageStoreException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "_findById", Long.valueOf(itemID));

        AbstractItem item = null;
        AbstractItemLink itemLink = getLink(itemID);
        if (null != itemLink)
        {
            item = itemLink.getItem();
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "_findById", item);
        return item;
    }
336057
private static Column getCurrentResourceColumn(DataSource dataSource, Integer size,
      Resource currentResource, String itemResourceType) {

    Iterator<Resource> items = dataSource.iterator();

    boolean hasMore = false;
    if (size != null) {
      List<Resource> list = new ArrayList<Resource>();
      while (items.hasNext() && list.size() < size) {
        list.add(items.next());
      }
      hasMore = items.hasNext();
      items = list.iterator();
    }

    Column column = new Column()
        .columnId(currentResource.getPath())
        .hasMore(hasMore)
        .metaElement(true);
    while (items.hasNext()) {
      Resource item = items.next();
      column.addItem(new ColumnItem(item)
          .resourceType(itemResourceType));
    }

    return column;
  }
474943
public CmsResource getResource() {

        return new CmsResource(
            m_base.getStructureId(),
            m_base.getResourceId(),
            m_rootPath,
            m_typeId,
            m_isFolder,
            m_base.getFlags(),
            m_base.getProjectLastModified(),
            m_base.getState(),
            m_base.getDateCreated(),
            m_base.getUserCreated(),
            m_base.getDateLastModified(),
            m_base.getUserLastModified(),
            m_base.getDateReleased(),
            m_base.getDateExpired(),
            m_base.getSiblingCount(),
            m_length,
            m_base.getDateContent(),
            m_base.getVersion());
    }
323989
public static <T> Class<T> classForName(ResourceLoader resourceLoader, String className) {
        try {
            return cast(resourceLoader.classForName(className));
        } catch (Exception e) {
            CommonLogger.LOG.cannotLoadClassUsingResourceLoader(className);
            CommonLogger.LOG.catchingTrace(e);
        }
        try {
            return cast(Class.forName(className));
        } catch (Exception | LinkageError e) {
            throw CommonLogger.LOG.cannotLoadClass(className, e);
        }
    }
825289
@Override
	public LinkRelation getCollectionResourceRelFor(Class<?> type) {
		return LinkRelation.of(StringUtils.uncapitalize(type.getSimpleName()) + "List");
	}
1076740
@Override
  public final String getFor(final Class<?> pClass, final String pThingName) {
    if ("list".equals(pThingName)) {
      return "waPrcEntitiesPage";
    }
    return null;
  }
254000
@CheckForNull
    public static WorkItem getWorkItem(Object element) {
        if (element instanceof IResource) {
            IResource resource = (IResource) element;
            if (resource.getType() == IResource.FILE && !Util.isJavaArtifact(resource) || !resource.isAccessible()) {
                // Ignore non java files or deleted/closed files/projects
                return null;
            }
            return new WorkItem((IResource) element);
        }
        if (element instanceof IJavaElement) {
            return new WorkItem((IJavaElement) element);
        }

        if (element instanceof IAdaptable) {
            Object adapter = ((IAdaptable) element).getAdapter(IResource.class);
            if (adapter instanceof IResource) {
                IResource resource = (IResource) adapter;
                if (resource.getType() == IResource.FILE && !Util.isJavaArtifact(resource) || !resource.isAccessible()) {
                    // Ignore non java files or deleted/closed files/projects
                    return null;
                }
                return new WorkItem(resource);
            }
            adapter = ((IAdaptable) element).getAdapter(IPackageFragment.class);
            if (adapter instanceof IPackageFragment) {
                return new WorkItem((IPackageFragment) adapter);
            }
            adapter = ((IAdaptable) element).getAdapter(IType.class);
            if (adapter instanceof IType) {
                return new WorkItem((IType) adapter);
            }
        }
        return null;
    }
411803
CmsContainerElementBean getElementForEditHandler(DialogContext context) {

        List<Item> selected = context.getSelectedItems();
        if (selected.size() == 1) {
            Item item = selected.get(0);
            Date instanceDate = (Date)item.getItemProperty(INSTANCEDATE_PROPERTY).getValue();
            CmsResource resource = context.getResources().get(0);
            return new CmsContainerElementBean(
                resource.getStructureId(),
                null,
                Collections.singletonMap(
                    CmsDateSeriesEditHandler.PARAM_INSTANCEDATE,
                    String.valueOf(instanceDate.getTime())),
                false);
        }
        return null;
    }
175564
@Override
    protected void changeItemLinkUrl(String itemUrl) {

        try {
            JspWriter out = getJsp().getJspContext().getOut();
            if (getCms().existsResource(itemUrl)) {
                try {
                    writePointerLink(getCms().readResource(itemUrl));
                    out.print(buildJsonItemObject(getCms().readResource(itemUrl)));
                } catch (CmsException e) {
                    // can not happen in theory, because we used existsResource() before...
                }
            } else {
                out.print(RETURNVALUE_NONE);
            }
        } catch (IOException e) {
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        }

    }
1179228
public CmsJspResourceWrapper getPageResource() {

        try {
            if (m_pageResource == null) {
                // get the container page itself, checking the history first
                m_pageResource = CmsJspResourceWrapper.wrap(
                    m_cms,
                    (CmsResource)CmsHistoryResourceHandler.getHistoryResource(m_request));
                if (m_pageResource == null) {
                    m_pageResource = CmsJspResourceWrapper.wrap(
                        m_cms,
                        m_cms.readResource(m_cms.getRequestContext().getUri()));
                }
            }
        } catch (CmsException e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
        return m_pageResource;
    }
66337
@Override
    public <T> CachedResource<T> getResource(
            Resource resource, Loader<T> builder, long checkInterval) throws IOException {
        if (Included.PLAIN == this.resourcesElementsProvider.getDefaultIncludedType()) {
            this.logger.trace(
                    "Resoure Aggregation Disabled, ignoring resource cache and loading '"
                            + resource
                            + "' directly");
            return this.loadResource(resource, builder);
        }

        // Look for the resource in the cache, since it has been wrapped with a SelfPopulatingCache
        // it should never return null.
        final GetResourceArguments<T> arguments = new GetResourceArguments<T>(resource, builder);
        final Element element =
                this.entryFactory.getWithData(this.resourceCache, resource, arguments);

        CachedResource<T> cachedResource = (CachedResource<T>) element.getObjectValue();
        if (this.logger.isTraceEnabled()) {
            this.logger.trace("Found " + cachedResource + " in cache");
        }

        // Found it, now check if the last-load time is within the check interval
        final long lastCheckTime = cachedResource.getLastCheckTime();
        if (lastCheckTime + checkInterval >= System.currentTimeMillis()) {
            if (this.logger.isTraceEnabled()) {
                this.logger.trace(
                        cachedResource
                                + " is within checkInterval "
                                + checkInterval
                                + ", returning");
            }
            return cachedResource;
        }
        if (this.logger.isTraceEnabled()) {
            this.logger.trace(
                    cachedResource
                            + " is older than checkInterval "
                            + checkInterval
                            + ", checking for modification");
        }

        // If the resource has not been modified return the cached resource.
        final boolean resourceModified = this.checkIfModified(cachedResource);
        if (!resourceModified) {
            cachedResource.setLastCheckTime(System.currentTimeMillis());
            this.resourceCache.put(
                    element); // do a cache put to notify the cache the object has been modified
            return cachedResource;
        }

        // The resource has been modified, reload it.
        cachedResource = this.loadResource(resource, builder);

        // Cache the loaded resource
        this.resourceCache.put(new Element(resource, cachedResource));

        if (this.logger.isDebugEnabled()) {
            this.logger.debug("Loaded and cached " + cachedResource);
        }

        return cachedResource;
    }
1179848
protected static <AdapterType> AdapterType getAdapter(ResourceHandle resourceHandle, Class<AdapterType> type) {
        if (type == ResourceHandle.class) {
            return type.cast(resourceHandle);
        }
        log.info("Unable to adapt resource on {} to type {}", resourceHandle.getPath(), type.getName());
        return null;
    }
78757
public static Collection<RDFNode> getListItemsOrFail(RDFNode node) {

        if (!isList(node)) {
            throw new IllegalArgumentException("Resource not an rdf:List");
        }

        return getListItemsOrEmpty(node);
    }
442150
public SourceProtocolItemStream getSourceProtocolItemStream()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
    {
      SibTr.entry(tc, "getSourceProtocolItemStream");
      SibTr.exit(tc, "getSourceProtocolItemStream", _sourceProtocolItemStream);
    }
    return _sourceProtocolItemStream;
  }
645104
public String getItemImageUrl(final TreeItemImage item, final String itemId) {

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

		// Check if has image url
		String url = item.getUrl();
		if (!Util.empty(url)) {
			return url;
		}

		// Check if has image
		Image image = item.getImage();
		if (image == null) {
			return null;
		}

		// Check static resource
		if (image instanceof InternalResource) {
			return ((InternalResource) image).getTargetUrl();
		}

		// Build targetted url
		Environment env = getEnvironment();
		Map<String, String> parameters = env.getHiddenParameters();
		parameters.put(Environment.TARGET_ID, getTargetId());

		String cacheKey = item.getImageCacheKey();

		if (Util.empty(cacheKey)) {
			// Add some randomness to the URL to prevent caching
			String random = WebUtilities.generateRandom();
			parameters.put(Environment.UNIQUE_RANDOM_PARAM, random);
		} else {
			// Remove step counter as not required for cached content
			parameters.remove(Environment.STEP_VARIABLE);
			parameters.remove(Environment.SESSION_TOKEN_VARIABLE);
			// Add the cache key
			parameters.put(Environment.CONTENT_CACHE_KEY, cacheKey);
		}

		// Item id
		parameters.put(ITEM_REQUEST_KEY, itemId);

		// The targetable path needs to be configured for the portal environment.
		url = env.getWServletPath();

		// Note the last parameter. In javascript we don't want to encode "&".
		return WebUtilities.getPath(url, parameters, true);
	}