Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

URL normalization (or URL canonicalization) in general is the process by which URLs are modified and standardized in a consistent manner. The goal of the normalization process is to transform a URL into a normalized or canonical URL so it is possible to determine if two syntactically different URLs may be equivalent. For more detail see http://en.wikipedia.org/wiki/URL_normalization

Rather than providing several traditional types of normalization for SEO purpose this java libraries provides transforming URLs into comparable and therefore sortable URLs. You can use this code whenever a URL is used as (primary) key in your application or storage system. This library produces URL by inverting the domain level labels.
Rather than providing several traditional types of normalization for SEO purpose this java libraries provides transforming URLs into comparable and therefore sortable URLs. You can use this code whenever a URL is used as (primary) key in your application or storage system. This library produces URL by inverting the domain level labels by default, but also gives the option not to.

## Examples

Expand Down
112 changes: 56 additions & 56 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.sentric</groupId>
<artifactId>url-normalization</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<name>url-normalization</name>
<url>https://github.com/sentric/url-normalization</url>
<scm>
<connection>https://github.com/sentric/url-normalization.git</connection>
<developerConnection>https://github.com/sentric/url-normalization.git</developerConnection>
<url>https://github.com/sentric/url-normalization.git</url>
</scm>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptor>src/main/assembly/jar-with-dependencies.xml</descriptor>
</configuration>
</plugin>
</plugins>
</build>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.sentric</groupId>
<artifactId>url-normalization</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<name>url-normalization</name>
<url>https://github.com/sentric/url-normalization</url>
<scm>
<connection>https://github.com/sentric/url-normalization.git</connection>
<developerConnection>https://github.com/sentric/url-normalization.git</developerConnection>
<url>https://github.com/sentric/url-normalization.git</url>
</scm>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptor>src/main/assembly/jar-with-dependencies.xml</descriptor>
</configuration>
</plugin>
</plugins>
</build>
</project>
28 changes: 14 additions & 14 deletions src/main/assembly/jar-with-dependencies.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<!-- Used to bundle dependencies with jar for testing purposes -->
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<outputDirectory>/</outputDirectory>
</dependencySet>
</dependencySets>
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<outputDirectory>/</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
157 changes: 75 additions & 82 deletions src/main/java/ch/sentric/Authority.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,120 +27,113 @@ public class Authority {

/**
* Constructor, initializing a authority.
*
* @param hostName
* the host name
* @param port
* the port
* @param user
* the username
* @param password
* the password
*
* @param hostName the host name
* @param port the port
* @param user the username
* @param password the password
*/
public Authority(final HostName hostName, final int port, final String user, final String password) {
this.hostName = hostName;
this.port = port;
this.user = user;
this.password = password;
this.hostName = hostName;
this.port = port;
this.user = user;
this.password = password;
}

/**
* Constructor, initializing a authority.
*
* @param hostName
* the host name
* @param port
* the port
* @param userInfo
* the user info, separeted by :, e.g user:password
*
* @param hostName the host name
* @param port the port
* @param userInfo the user info, separeted by :, e.g user:password
*/
public Authority(final HostName hostName, final int port, final String userInfo) {
String user = null;
String password = null;
if (null != userInfo) {
final String[] userInfoParts = userInfo.split(":", 2);
if (userInfoParts.length == 2) {
user = userInfoParts[0];
password = userInfoParts[1];
}
}
this.hostName = hostName;
this.port = port;
this.user = user;
this.password = password;
String user = null;
String password = null;
if (null != userInfo) {
final String[] userInfoParts = userInfo.split(":", 2);
if (userInfoParts.length == 2) {
user = userInfoParts[0];
password = userInfoParts[1];
}
}
this.hostName = hostName;
this.port = port;
this.user = user;
this.password = password;
}

public HostName getHostName() {
return this.hostName;
return this.hostName;
}

public int getPort() {
return this.port;
return this.port;
}

public String getUser() {
return this.user;
return this.user;
}

public String getPassword() {
return this.password;
return this.password;
}

public String getAsString() {
return (this.user != null || this.password != null ? this.user + ":" + this.password + "@" : "") + this.hostName.getAsString() + (this.port != -1 ? ":" + this.port : "");
return (this.user != null || this.password != null ? this.user + ":" + this.password + "@" : "") + this.hostName.getAsString() + (this.port != -1 ? ":" + this.port : "");
}

public String getOptimizedForProximityOrder() {
return this.hostName.getOptimizedForProximityOrder();
public String getOptimizedForProximityOrder(Boolean reverseDomainParts) {
return this.hostName.getOptimizedForProximityOrder(reverseDomainParts);
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.hostName == null) ? 0 : this.hostName.hashCode());
result = prime * result + ((this.password == null) ? 0 : this.password.hashCode());
result = prime * result + this.port;
result = prime * result + ((this.user == null) ? 0 : this.user.hashCode());
return result;
final int prime = 31;
int result = 1;
result = prime * result + ((this.hostName == null) ? 0 : this.hostName.hashCode());
result = prime * result + ((this.password == null) ? 0 : this.password.hashCode());
result = prime * result + this.port;
result = prime * result + ((this.user == null) ? 0 : this.user.hashCode());
return result;
}

@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Authority other = (Authority) obj;
if (this.hostName == null) {
if (other.hostName != null) {
return false;
}
} else if (!this.hostName.equals(other.hostName)) {
return false;
}
if (this.password == null) {
if (other.password != null) {
return false;
}
} else if (!this.password.equals(other.password)) {
return false;
}
if (this.port != other.port) {
return false;
}
if (this.user == null) {
if (other.user != null) {
return false;
}
} else if (!this.user.equals(other.user)) {
return false;
}
return true;
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Authority other = (Authority) obj;
if (this.hostName == null) {
if (other.hostName != null) {
return false;
}
} else if (!this.hostName.equals(other.hostName)) {
return false;
}
if (this.password == null) {
if (other.password != null) {
return false;
}
} else if (!this.password.equals(other.password)) {
return false;
}
if (this.port != other.port) {
return false;
}
if (this.user == null) {
if (other.user != null) {
return false;
}
} else if (!this.user.equals(other.user)) {
return false;
}
return true;
}
}
Loading