Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.cognifide.slice.core.internal.link;
  
  /*
   * #%L
   * Slice - Core
   * $Id:$
   * $HeadURL:$
   * %%
   * Copyright (C) 2012 Cognifide Limited
  * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  *      http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * #L%
  */
 
 import java.util.List;
 
 
 
 public class LinkImpl implements Link {
 
 	private static final Pattern DOT_PATTERN = Pattern.compile("\\.");
 
 	private final String path;
 
 	private final String protocol;
 
 	private final String domain;
 
 	private final List<Stringselectors// unmodifiable list
 
 	private final String extension;
 
 	private final String suffix;
 
 	private final String queryString;
 
 	private final String fragment;

This constructor is, as of now, used only inside a framework. There is no need to use it outside the framework, as it can be provided/injected anywhere and then new link can be created.

Parameters:
path resource path is everything from the start up to the first dot after the last slash (excluding extension and suffix)
selectorsString is the dot-separated elements between the path and the extension
extension is everything between the last dot in the URL and the next slash (or the end of the string)
suffix is everything after the extension (including the slash)
 
 	public LinkImpl(String pathString selectorsStringString extensionString suffix) {
 		this(pathselectorsStringextensionsuffixnullnull);
 	}

This constructor is, as of now, used only inside a framework. There is no need to use it outside the framework, as it can be provided/injected anywhere and then new link can be created.

Parameters:
path resource path is everything from the start up to the first dot after the last slash (excluding extension and suffix)
selectorsString is the dot-separated elements between the path and the extension
extension is everything between the last dot in the URL and the next slash (or the end of the string)
suffix is everything after the extension (including the slash)
 
 	public LinkImpl(String pathString selectorsStringString extensionString suffixString queryString,
 			String fragment) {
 		this. = "";
 		this. = "";
 		this. = path;
 		this. = extension;
 		this. = suffix;
 		this. = queryString;
 		this. = fragment;
 		if (StringUtils.isBlank(selectorsString)) {
 			 = Collections.<StringemptyList();
 		} else {
 			 = Collections.unmodifiableList(Arrays.asList(.split(selectorsString)));
 		}
 	}

Creates new instance of the Link by passing the internal state. Use with caution - whenever you pass {{selectors}} list make sure it's unmodifiable.

Parameters:
path resource path is everything from the start up to the first dot after the last slash (excluding extension and suffix)
selectors list of selectors, cannot be null, should be unmodifiable
extension is everything between the last dot in the URL and the next slash (or the end of the string)
suffix is everything after the extension (including the slash)
	public LinkImpl(String pathList<StringselectorsString extensionString suffixString queryString,
			String fragment) {
		this(""""pathselectorsextensionsuffixqueryStringfragment);
	}
	public LinkImpl(String protocolString domainString pathList<StringselectorsString extension,
			String suffixString queryStringString fragment) {
		this. = protocol;
		this. = domain;
		this. = path;
		this. = selectors;
		this. = extension;
		this. = suffix;
		this. = queryString;
		this. = fragment;
	}
	public LinkImpl(RequestPathInfo pathInfo) {
		this. = pathInfo.getResourcePath();
		String[] selectorsArray = pathInfo.getSelectors();
		this. = Collections.unmodifiableList(Arrays.asList(selectorsArray));
		this. = pathInfo.getExtension();
		this. = pathInfo.getSuffix();
		this. = "";
		this. = "";
		this. = "";
		this. = "";
	}

Creates string representation of this link.

Returns:
string representation like this: /resource/path.selector.ext/suffix?queryParam=value#fragment
	public String toString() {
		StringBuilder result = new StringBuilder();
		appendPath(result);
		appendSuffix(result);
		return result.toString();
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.cognifide.slice.commons.util.link.Link#getExtension()
	 */
	public String getExtension() {
		return ;
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.cognifide.slice.commons.util.link.Link#getPath()
	 */
	public String getPath() {
		return ;
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.cognifide.slice.commons.util.link.Link#getSelectors()
	 */
	public List<StringgetSelectors() {
		return ;
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.cognifide.slice.commons.util.link.Link#getSelectorsString()
	 */
		if (.isEmpty()) {
			// this is not how does the CQ's PathInfo works, but returning null does not seem to be a good
			// idea
			return "";
		}
		StringBuilder builder = new StringBuilder();
		for (String selector : ) {
			builder.append(selector);
			builder.append(".");
		}
		int lastindex = builder.length() - 1;
		return builder.substring(0, lastindex);
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.cognifide.slice.commons.util.link.Link#getSuffix()
	 */
	public String getSuffix() {
		return ;
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.cognifide.slice.commons.util.link.Link#getQueryString()
	 */
	public String getQueryString() {
		return ;
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.cognifide.slice.commons.util.link.Link#getfragment()
	 */
	public String getFragment() {
		return ;
	}
	public String getDomain() {
		return ;
	}
	public String getProtocol() {
		return ;
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.cognifide.slice.commons.util.link.Link#hasSuffix()
	 */
	public boolean hasSuffix() {
		return StringUtils.isNotBlank();
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.cognifide.slice.commons.util.link.Link#containsSelector(java.util.regex.Pattern)
	 */
	public boolean containsSelector(Pattern selectorPattern) {
		if (selectorPattern != null) {
			for (String s : ) {
				if (selectorPattern.matcher(s).matches()) {
					return true;
				}
			}
		}
		return false;
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.cognifide.slice.commons.util.link.Link#containsSelector(java.lang.String)
	 */
	public boolean containsSelector(String selector) {
		if (StringUtils.isNotBlank(selector)) {
			for (String s : ) {
				if (StringUtils.equals(selectors)) {
					return true;
				}
			}
		}
		return false;
	}
	private void appendProtocolAndDomain(StringBuilder result) {
		if (StringUtils.isNotBlank()) {
			if (!StringUtils.endsWith("://")) {
				result.append("://");
			}
		}
		if (StringUtils.isNotBlank()) {
			result.append();
		}
	}
	private void appendPath(StringBuilder result) {
		result.append(StringUtils.defaultString());
	}
	private void appendSelectors(StringBuilder result) {
		for (String selector : ) {
			result.append(".");
			result.append(selector);
		}
	}
	private void appendExtension(StringBuilder result) {
		if (StringUtils.isNotBlank()) {
			result.append(".");
		}
	}
	private void appendSuffix(StringBuilder result) {
		if (hasSuffix()) {
			if (.charAt(0) != '/') {
				result.append("/");
			}
			result.append();
		}
	}
	private void appendQueryString(StringBuilder result) {
		if (StringUtils.isNotBlank()) {
			if (.charAt(0) != '?') {
				result.append("?");
			}
		}
	}
	private void appendFragment(StringBuilder result) {
		if (StringUtils.isNotBlank()) {
			if (.charAt(0) != '#') {
				result.append("#");
			}
		}
	}
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (( == null) ? 0 : .hashCode());
		result = prime * result + (( == null) ? 0 : .hashCode());
		result = prime * result + (( == null) ? 0 : .hashCode());
		result = prime * result + (( == null) ? 0 : .hashCode());
		result = prime * result + (( == null) ? 0 : .hashCode());
		result = prime * result + (( == null) ? 0 : .hashCode());
		result = prime * result + (( == null) ? 0 : .hashCode());
		result = prime * result + (( == null) ? 0 : .hashCode());
		return result;
	}
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final LinkImpl other = (LinkImplobj;
		if (!StringUtils.equals(other.domain)) {
			return false;
		}
		if (!StringUtils.equals(other.extension)) {
			return false;
		}
		if (!StringUtils.equals(other.fragment)) {
			return false;
		}
		if (!StringUtils.equals(other.path)) {
			return false;
		}
		if (!StringUtils.equals(other.protocol)) {
			return false;
		}
		if (!StringUtils.equals(other.queryString)) {
			return false;
		}
		if (!StringUtils.equals(getSelectorsString(), other.getSelectorsString())) {
			return false;
		}
		if (!StringUtils.equals(other.suffix)) {
			return false;
		}
		return true;
	}
New to GrepCode? Check out our FAQ X