Using SubClipse To Access An External SVN Behind a Proxy Server

Proxy servers can be frustrating things! I was trying to set up access to a SVN server through Eclipse, added my proxy settings to Eclipse, installed SlikSVN & SubClipse. I didn’t think it was too much to ask to expect it to pick up the proxy settings & work ‘out of the box’. Seems I was wrong! Instead I got a message “RA layer request failed”. A big thanks to Mark’s blog for the answer of how to overcome this most inconvenient of hurdles.

In a Windows development environment, open the file: C:\Documents and Settings\MyUserId\Application Data\Subversion\servers in your favourite text editor. … Continue Reading

Java Inheritance with Generics

Sometimes you want to set a type as a more specific type on a subclass than is defined by the super class. The below example shows how to do this.

public class MostSpecific extends MediumSpecific<MySpecificModel> { }

public class MediumSpecific<T extends MyModel> extends LeastSpecific<T> { }

public class LeastSpecific<T extends MyModel> implements ILeastSpecificInterface {
	protected T model;
	public T getModel() {
		return model;
	}
}

This enables on the MostSpecific class for getModel() and model to be of type MySpecificModel within the MostSpecific class, yet it is of type MyModel in the classes MediumSpecific and LeastSpecific.

Escaping Regular Expression Pattern in Java

Sometimes you need to dynamically create regular expressions, which often means you have to escape them. The easiest and best way to do this is provided for you in the Java API.

String regexPattern = ".*[" + Pattern.quote( "!\"£$_%^&amp;*()-=[];'#,./\`¬¦|&lt;&gt;?:@~{}+" ) + "].*";

Your pattern will become .*[Q!"£$_%^&*()-=[];’#,./`¬¦|<>?:@~{}+E].*, which is escaped.

java.util.regex.Pattern.html#quote(java.lang.String)

Struts 2 Collection and Map Handling – Pitfalls

With Java Generics you must be careful!

The Struts 2 documentation states that “The framework cannot instantiate an object if it can’t determine an appropriate implementation. It recognizes well-known collection interfaces (List, Set, Map, etc) but cannot instantiate MyCustomInterface when all it sees is the interface. In this case, instantiate the target implementation first (eg. in a prepare method) or substitute in an implementation.”, but you have to be aware that the section “It recognizes well-known collection interfaces (List, Set, Map, etc) but cannot instantiate MyCustomInterface when all it sees is the interface” is quite loose. It would appear that … Continue Reading

How to fix orphaned SQL Server users

Summary
When you restore a Microsoft SQL Server database on a different machine, you cannot access the database until you fix the permissions.

Detail
The problem is that the user in the database is an “orphan”. This means that there is no login id or password associated with the user. This is true even if there is a login id that matches the user, since there is a GUID (called a SID in Microsoft-speak) that has to match as well.

This used to be a pain to fix, but currently (SQL Server 2000, SP3) there is a stored procedure that does the heavy lifting.

All … Continue Reading

InputStream to String

In Java 1.4 simply replace the StringBuilder with a StringBuffer.

private String convertStreamToString( InputStream in ) throws Exception {
	StringBuilder out = new StringBuilder();
	byte[] b = new byte[4096];
	for ( int n; ( n = in.read( b ) ) != -1; ) {
		out.append( new String( b, 0, n ) );
	}
	return out.toString();
}

EL Expression from ${xyz.abc} to %{xyz.abc}

${xyz.abc} can be accessed using <c:out value=”${xyz.abc}”/> but cannot be accessed by <s:property value=”${xyz.abc}/>. Instead you must place the expression onto the request using <c:set> and then access it from the request using <s:property>.

<c:set var="painless" value="${xyz.abc}" scope="request"/>
<s:property escapeJavaScript="true" value="%{ #request['painless'] }"/>

Java Generics Cast

When your cast simply won’t compile, you need to get a bit sneaky. Suppose you have a Map with the generic type of Map<String, List<String>> and you want to cast it to a Map<String, Object> to satisfy a return type of a method.

public interface MyInterface {
	Map<String, Object> getAttributes();
}

public class MyClass implements MyInterface {
	private Map<String, List<String>> attributes = new HashMap<String, List<String>>();

	public Map<String, Object> getAttributes() {
		return attributes; // Compile error here!
	}
}

Now if you are like me, you would have thought that List<String> is an object, but it doesn’t work like that. Instead you must use a cast with a bit more flexibility. … Continue Reading