Friday, June 06, 2008

GSM Codes

GSM codes.

These can be saved in you phonebook/ contacts list for fast access.

Most are obviously selectable by going through your phones menu, but these are much quicker, and I can never find some of them, like call waiting and call hold

Call Divert (all call types)

All
Set: **21*destination#[SEND]
Cancel: ##21#[SEND]
Query: *#21#[SEND]
No Answer
Delay nn seconds: max 30 seconds, in 5 second increments
Set: **61*destination*nn#[SEND]
Cancel: ##61#[SEND]
Query: *#61#[SEND]
Unreachable
Set: **62*destination#[SEND]
Cancel: #62#[SEND]
Query: *#62#[SEND]
Busy
Set: **67*destination#[SEND]
Cancel: ##67#[SEND]
Query: *#67#[SEND]
Cancel All
##002#[SEND]

Divert Voice Calls

All
Set: **21*destination*11#[SEND]
Cancel: ##21*11#[SEND]
Query: *#21*11#[SEND]
No Answer
Delay nn seconds: max 30 seconds, in 5 second increments
Set: **61*destination*11*nn#[SEND]
Cancel: ##61*11#[SEND]
Query: *#61*11#[SEND]
Unreachable
Set: **62*destination*11#[SEND]
Cancel: ##62*11#[SEND]
Query: *#62*11#[SEND]
Busy
Set: **67*destination*11#[SEND]
Cancel: ##67*11#[SEND]
Query: *#67*11#[SEND]

Divert Data Calls

All
Set: **21*destination*25#[SEND]
Cancel: ##21*25 [SEND]
Query: *#21*25#[SEND]
No Answer
Delay nn seconds: max 30 seconds, in 5 second increments
Set: **61*destination*25*nn#[SEND]
Cancel: ##61*25#[SEND]
Query: *#61*25#[SEND]
Unreachable
Set: **62*destination*25#[SEND]
Cancel: ##62*25#[SEND]
Query: *#62*25#[SEND]
Busy
Set: **67*destination*25#[SEND]
Cancel: ##67*25#[SEND]
Query: *#67*25#[SEND]

Divert Fax Calls

All
Set: **21*destination*13#[SEND]
Cancel: ##21*13#[SEND]
Query: *#21*13#[SEND]
No Answer
Delay nn seconds: max 30 seconds, in 5 second increments
Set: **61*destination*13*nn#[SEND]
Cancel: #61*13#[SEND]
Query: *#61*13#[SEND]
Unreachable
Set: **62*destination*13#[SEND]
Cancel: #62*13#[SEND]
Query: *#62*13#[SEND]
Busy
Set: **67*destination*13#[SEND]
Cancel: ##67*13#[SEND]
Query: *#67*13#[SEND]

Divert Line 2 Calls

All
Set: **21*destination*89#[SEND]
Cancel: #21*89#[SEND]
Query: *#21*89#[SEND]
No Answer
Delay nn seconds: max 30 seconds, in 5 second increments
Set: **61*destination*89*nn#[SEND]
Cancel: ##61*89#[SEND]
Query: *#61*89#[SEND]
Unreachable
Set: **62*destination*89#[SEND]
Cancel: ##62*89#[SEND]
Query: *#62*89#[SEND]
Busy
Set: **67*destination*89#[SEND]
Cancel: ##67*89#[SEND]
Query: *#67*89#[SEND]

Call Barring

You use call barring to control what calls can be made or received by your account.

The barring code is specific to the network. Ask your service provider.

Note that Call Barring can't work if call diverts are active, even the autodivert set by the network.

All calls
Set: **330*barring code#[SEND]
Cancel: ##330*barring code#[SEND]
Query: *#330#[SEND]

Outgoing calls
Set: **333*barring code#[SEND]
Cancel: ##333*barring code#[SEND]
Query: *#333#[SEND]

Incoming calls
Set: **35*barring code#[SEND]
Cancel: ##35*barring code#[SEND]
Query: *#35#[SEND]

Outgoing international calls
Set: **331*barring code#[SEND]
Cancel: ##331*barring code#[SEND]
Query: *#331#[SEND]

Outgoing international calls except to home country
Set: **332*barring code#[SEND]
Cancel: ##332*barring code#[SEND]
Query: *#332#[SEND]

Incoming calls when outside home country
Set: *351*barring code#[SEND]
Cancel: #351*barring code#[SEND]
Query: *#351#[SEND]
Cancel All Call Barring
#330*barring code#[SEND]

SMS

There is no provision in the GSM specification for diverting SMS messages

Bar incoming SMS messages
Set: *35*barring code*16#[SEND]
Cancel: #35*barring code*16#[SEND]

Call waiting

Set: *43#[SEND]
Cancel: #43#[SEND]
Query: *#43#[SEND]

Incoming call waiting

Reject: 0 [SEND]
Drop current call and answer: 1 [SEND]
Hold current call and answer: 2 [SEND]

Calling line identity

Outgoing CLI Release (recipient sees your number)
Release: *31# destination [SEND]
Withhold: #31# destination [SEND]
Query default: *#31#[SEND]

Incoming CLI Presentation (you see the caller's number)
Allow: *30#[SEND]
Prevent: #30#[SEND]
Query default: *#30#[SEND]

Dial number from memory

Where nnn is the memory location number
nnn#[SEND]

Change PIN codes

Change Call Barring pin code
**03*oldpin*newpin*newpin#

Change SIM pin code
**04*oldpin*newpin*newpin#

Change SIM pin2 code
**042*oldpin*newpin*newpin#

Unblock SIM pin code
**05*PUK*newpin*newpin#

Unblock SIM pin code
**06*PUK2*newpin*newpin#

Wednesday, May 14, 2008

Maven multiple source directories

By default with maven you can only specify a single source directory. Not very flexible. The following pluggin expands this, allowing you to specify many src dirs.

Heres a sample from the pom.xml

<build>


<build>
   <!-- Replaced with build-helper-maven-plugin below to allow for multiple source directories
       <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
   -->
   <testSourceDirectory>
       ${basedir}/src/test/java
   </testSourceDirectory>
   <plugins>
       <plugin>
           <artifactId>maven-compiler-plugin</artifactId>
           <configuration>
               <source>1.5</source>
               <target>1.5</target>
               <debug>false</debug>
           </configuration>
       </plugin>
       <plugin>
           <groupId>org.codehaus.mojo</groupId>
           <artifactId>build-helper-maven-plugin</artifactId>
           <version>1.1</version>
           <executions>
               <execution>
                   <id>add-source</id>
                   <phase>generate-sources</phase>
                   <goals>
                       <goal>add-source</goal>
                   </goals>
                   <configuration>
                       <sources>
                           <source>
                               ${basedir}/src/main/java
                           </source>
                           <source>
                               ${basedir}/src/types/java
                           </source>
                       </sources>
                   </configuration>
               </execution>
           </executions>
       </plugin>
   </plugins>
</build>

Tuesday, May 06, 2008

Why spring rocks in a nuthell

http://www.jroller.com/kdonald/entry/the_essence_of_spring

Injecting enums in Spring beans
Found this while searching for how to insert enums into Spring beans from the xml config file (basically you just put the enum value directly in the xml file, http://www.jroller.com/kdonald/entry/spring_hidden_gem_support_for)

Friday, May 02, 2008

PropertyPlaceholderConfigurer doesn't work with XmlBeanFactory

SImple gotcha.

I was using Spring and the PropertyPlaceholderConfigurer. This simply allows you to populate your spring config file with values from a properties file at runtime. For me the properties file is loaded from the classpath (using the classpath: prefix). this is then stored in a seperate config folder whihc is shared between all projects, thus allowing us to update the config file with needing to redploy the complete application again.

e.g.

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>jms.properties</value>
<ref bean="getNetworkServicePropertyFile" />
</list>
</property>
</bean>
<bean id="test" class="com.meteor.provisioning.Test">
<property name="jmsTemplate" value="${jms.receiveTimeout}" />
</bean>


I write a simple class to instantiate this from a Unit test.


public static BeanFactory getSpringContext() {
springConfigFile = System.getProperty("SpringConfig", springConfigFile);
if (_beanFactory == null) {
Resource resource = new ClassPathResource(springConfigFile);
//_beanFactory = new XmlBeanFactory(resource);
}
return _beanFactory;
}
public static Object getBean(String bean){
return getApplicationContext().getBean(bean);
}

and finally a test case

public class Test {
private String jmsTemplate;

public void setJmsTemplate(String jmsTemplate) {
this.jmsTemplate = jmsTemplate;
System.out.println("jmsTemplate = "+jmsTemplate);
}

@org.junit.Test
public void doTest(){
Utils.getBean("test");
}

}



It didn't work. The PropertyPlaceholderConfigurer, wasn't updating the internal spring file with values from the jms.properties. The jmsTemplate value was been returned as ${jms.receiveTimeout}

Turns out that only ApplicationContext files do the replacement. A quick update to

public static ApplicationContext getApplicationContext() {
springConfigFile = System.getProperty("SpringConfig", springConfigFile);
if (_beanFactory == null) {
_beanFactory = new ClassPathXmlApplicationContext(springConfigFile);
}
return _beanFactory;
}

fixed the problem. Thanks also to http://francisoud.blogspot.com/2007/06/spring-property-placeholder.html

Friday, April 18, 2008

N95

I recently got a N95 8GB.

A list of some of the shortcut keys













CodeResult
*#7370#Reset the phone N.B. This deletes all content off your SiM including Spiderman 3 activation code. Be sure to back it up before hand
*#0000Show phone firmware version.. e.g. my N95 8GB (aka N95-2) is V20.0.016
02-03-08
RM-320
Nokia N95 (01.01)
*#06# IMEI number (International Mobile Equipment Identity)
3 Finger Restart Call (Grenn Key) + * + 3. THen hold down start keyDoes a hard restart. can be used if phone won't start. (Also try removing battery for about 10 seconds. This worked for me)
*#92702689#
Life timer (W A R 0 A N T Y) - The amount of time your phone has spent sending and receiving calls.
*#62209526#Wireless MAC Address
*#2820#Bluetooth MAC address
*#7370# Format phone

Sunday, February 24, 2008

Converting Video and Audio

This is going to be an ongoing article as I try and locate the best free tools for the job.
Good general reference site is Afterdawn, and their forums

Ok firsts.
Copy/ Backup DVD
DVDShrink is an invaluable tool for compressing and copying and backing up DVD's to a directory on your pc. It can copy full DVD, or you can remaster the contents and remove copyright protection notices/ menus/ trailers etc.
There's a handy guide on MrBass

Some newer DVD's have copy protection which DVDShrink can't handle, then DVDDecrypter can sometimes help. If you want to burn the result onto a backup DVD (instead of just storing it on your pc) you probably will still need to run DVDShrink on the ripped files to reduce them enough to fit on your backup DVD. (Unless your DVD burner can burn multi layer)

Burning Images
ISOBurn for buringn images

Video Converting formats

handbrake. This si a great tool (oringally only on Mac, but on Windows and Linux now), for ripping dvd's to mp4, or H264 formats. Doesn't convert formats from what I can see

Super tool for convert all sorts of types

Audio

Switch is a tool. I've just tried to convert 3 mp4's. Converted for 2 of them, didn't work on one.
  • wav (PCM, ADPCM+, aLaw+, uLaw+, and others)
  • mp3 (MPEG Layer 3)
  • mp2+ (MPEG Layer 2)
  • mpga+ (MPEG Audio)
  • au
  • aif/aiff
  • gsm
  • dct
  • vox
  • raw
  • ogg
  • flac
  • amr
  • wma*
  • wmv*
  • aac* (not aacPlus)
  • m4a*
  • mid+
  • act/rcd/rec+ (newer version of format not supported)
  • rm / ra / ram+
  • dvf+ (Not all dvf recorders are supported)
  • msv+ (Not all msv recorders are supported)
  • dss+ (SP Mode only)
  • sri+
  • shn+
  • cda+
  • mov !
  • avi+
  • mpg/mpeg+
  • .m3u+^
  • .pls+^
to any of the following

  • wav (PCM, ADPCM+, aLaw+, uLaw+, and others, see here)
  • mp3
  • au
  • aif/aiff
  • gsm
  • vox
  • raw
  • ogg
  • flac
  • .rss
  • .m3u^
  • .pls^
  • .wpl
  • .amr+
  • aac+
  • m4a+
  • wma+
  • .mov!


Monday, December 10, 2007

Ruby Calnder plugin

New day new problem.

I installed a ruby on rails calendar plugin. Install worked fine. One of the install steps was to run

rake rdoc

This gave me the following problem
rake aborted!
no such file to load -- hoe
C:/dev/ruby/timesheet/vendor/plugins/calendar_helper/rakefile:4
(See full trace by running task with --trace)

Hoe it turns out is a simple ruby project for helping with rakefiles. To install Hoe

gem install hoe
(no need for sudo since I'm on windows)

Now rake rdoc gives me
rake aborted!
couldn't find HOME environment -- expanding `~/.hoerc'
C:/dev/ruby/timesheet/vendor/plugins/calendar_helper/rakefile:7:in `new'
(See full trace by running task with --trace)

This was because I was running on Windows not unix. Setting HOME environment helps this

set HOME=%HOMEPATH%

Now the problem is
rake aborted!
Don't know how to build task 'README'

This as it turns out was a problem with the rakefile. It referred to a non-existant file 'README ' in the plugin. There was however a Readme.txt file. Updating the Rakefile to refer to this finally fixed the issues.


require 'rubygems'
require 'rake'
require 'rake/rdoctask'
require 'hoe'
require './lib/calendar_helper.rb'

Hoe.new('calendar_helper', CalendarHelper::VERSION) do |p|
p.rubyforge_name = 'seattlerb'
p.author = 'Geoffrey Grosenbach'
p.email = 'boss AT topfunky.com'
p.summary = 'Generates a configurable, CSS-tagged HTML calendar.'
p.description = "A simple method to create an HTML calendar for a single month. Can be styled with CSS. Usable with Ruby on Rails."
p.url = "http://rubyforge.org/projects/seattlerb"
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
p.clean_globs = ['test/output']
end

# desc "Test task (actually runs specs)"
# task "test" do
# system "spec --format specdoc --color spec/*_spec.rb"
# end

# -- Rails-specific --

desc 'Generate documentation for the calendar_helper plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'CalendarHelper'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('Readme.txt')
rdoc.rdoc_files.include('lib/**/*.rb')
end

Sunday, December 09, 2007

Ruby on Rails install headaches

Some problems installing ruby on rails that I thought I's document.

Firstly I followed the instructions on rubyonrails.org, downloading the altest version of ruby 1.86_25, downloading and installing ruby Gems. The the next step where you actually install rails is where the trouble started

C:\apps\ruby186.25\rubygems-0.9.5>gem install rails --include-dependencies
INFO: `gem install -y` is now default and will be removed
INFO: use --ignore-dependencies to install only the gems you list
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
Bad file descriptor - connect(2) (Errno::EBADF)


First problem was web proxys.

My laptop is used both in work and at home. In work I use a http proxy to access the web. At home I don't. The problem was I had set a system variable to set a http proxy variable. (http_proxy), but I was using my laptop at home.

To check if you use a http proxy from a DOS window type the following

echo %http_proxy%

If you get a response like
http://10.105.24.70:8080

then you have a http proxy set.

For me I had to remove the proxy. This is done by
set http_proxy=

For most people however I would imagine the problem is the opposite, you may need to set the http_proxy for your DOS window. To check if you need a http_proxy, goto your web browser

For IE
Tools/ Internet Options/ Connections/ LAN Settings/ Proxy Server
Note the url and port

For Firefox goto
Tools/ Options/ Advanced/ Network tab/ Settings (phew)
Note the url and port

You can set the proxy in the dos window simply by typing
set http_proxy=http://10.105.24.70:8080

With this done you should be able to retry the install

Next problem was

C:\apps\ruby186.25\rubygems-0.9.5>gem install rails --include-dependencies
INFO: `gem install -y` is now default and will be removed
INFO: use --ignore-dependencies to install only the gems you list
Bulk updating Gem source index for: http://gems.rubyforge.org
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
OpenURI::HTTPError: 404 Not Found reading http://gems.rubyforge.org/gems/activesupport-2.0.1.gem


THis was a temporary problem. I inserted the url into a browser and it worked. When I retried the command it also worked.

Thursday, December 06, 2007

Oracle version

Ever wondered what version of oracle you were running?

Wonder no more

select name from v$database
select * from v$version

Monday, August 20, 2007

Working with saxon

Saxon didn't like the concatenation of the sequence. changing this to fn:string-join worked however.


declare namespace xf = "http://tempuri.org/xqueryTest/XQueryTransformations/csv/";

declare function xf:csv($aPIMessage1 as element(APIMessage))
as xs:string {
fn:string-join(
for $line in $aPIMessage1/AuthResponse
let $ct := concat($line/ClientTransactionReference, "," , $line/SystemReferenceNumber, ",", $line/ResponseInfo/ResponseCode , ",", $line/ResponseInfo/Result ,",", $line/ResponseInfo/Description , ",", $line/ApprovalInfo/ApprovalCode , ",", $line/ApprovalInfo/DateTime, " ")
return $ct,"")
};


declare variable $aPIMessage1 as element(APIMessage) external;

xf:csv(doc("./resp.xml")/APIMessage)

My first xquery; xml to csv

Got this working. Thought I'd post it. My first xquery. Parses an Xml response file (from a credit card authorisation system), and outputs some of the fields as a csv file. It was written using the BEA XQuery Mapper, which is a pluggin by BEA for eclipse 3.1.

Having an issue running it with Saxon at the moment


declare namespace xf = "http://tempuri.org/xqueryTest/XQueryTransformations/csv/";

declare function xf:csv($aPIMessage1 as element(APIMessage))
as xs:string {
concat(for $line in $aPIMessage1/AuthResponse
let $ct := concat($line/ClientTransactionReference, "," , $line/SystemReferenceNumber, ",", $line/ResponseInfo/ResponseCode , ",", $line/ResponseInfo/Result ,",", $line/ResponseInfo/Description , ",", $line/ApprovalInfo/ApprovalCode , ",", $line/ApprovalInfo/DateTime, " ")
return $ct)
};



declare variable $aPIMessage1 as element(APIMessage) external;

xf:csv($aPIMessage1)

Friday, May 25, 2007

Ibatis problem

Document root element "sqlMap", must match DOCTYPE root "null"

This was the unhelpful exception I was gettign when I tried to run my ibatis/ spring prototype.

My ibatis sqlMap file looked ok

<sqlmapconfig>
<sqlmap resource="db/prov.xml">
</sqlmap>
<sqlmapconfig>javascript:void(0)
Publish Post

Had a search, you must add

<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd">

to your sql map files

Note you must also have

<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">

to your sql-map-config.xml file.

Tuesday, January 30, 2007

java http proxy support

Heres a good post on getting java to use the host machines proxy settings

http://weblogs.java.net/blog/kohsuke/archive/2005/08/we_deserve_a_be.html

Upshot is to include the following in you java prog before making http requests

try {
System.setProperty("java.net.useSystemProxies","true");
} catch (SecurityException e) {
; // failing to set this property isn't fatal
}
Sweet!

Wednesday, December 20, 2006

Unlocking mobile phones

I recently got a second mobile phone, and wanted to swap sims between the two.

The phones I wanted to unlock were a Nokia 6021, and a Nokia 6070

My experience was
  • Get your IMEI code off your phone (type *#06# into the phone).
  • Figure out if you are DCT3 or DCT 4 and your phone type from this site http://www.mobyproject.com/link/dct3&4list.txt
  • Goto this site http://unlock.nokiafree.org. Enter the details and get the code
  • Take out your sim and start phone without it.
  • Type in the bottom (7th) code from the list following the instructions from http://unlock.nokiafree.org. (Press * multiple times to get letters *, P, W +)

Voila.

Of course there are risks.
This article gives a good synopsis of what to do and some exceptions that can occur
http://www.oreilly.com/pub/wlg/3935

Good luck

Monday, October 16, 2006

Misc unix commands

chmod only dirs, using find
find /dir/to/chmod/all/dirs -type d -exec chmod a+x {} \;

Move all files after a certain date (Yesterday) , using find
find /dir/ -mtime -1 -exec mv {} ./temp \;

List only directories
ls -l | grep ^d

Find last created entity (file or directory)
ls -t ${CIDIR}| head -n 1

Find last created directory (note must use long ls results, therefore we need to parse 8th elment)
ls -tl | grep ^d | head -n 1 | awk '{print $8}'

grep multiple log files in different locations. (Join multiple lines into one line)


grep EXCEPTION `ls -t /var/log/bea/logs/MWOSBDomain/servers/MWOSB1?/customaudit/LogFile1?.log.* | head -n 3 |  tr '\n' ' '`

e.g. this will grep log files in differnt locations from yesterday (based on naming convention LogFile12.log = current log file. LogFile12.log. is rolled over log file. Assuming log files roll over every night).
Top 3 files are taken from ls command (in this case I know there are 3 log directories, so top 3 files are all yesterdays file in each directory)
List output is then 'translated', converting each line break into a space, so feed into grep command.

Dirname

Discovers the dir where the current running script is running;

Useful if writing bash scripts and you want to know where the current file is (for example if loading other companion scripts)

DIR="$( cd "$( dirname "$0" )" && pwd )"

e.g

#!/bin/bash

export DIRNAME=$(cd `dirname $0` && pwd)

source ${DIRNAME}/common.sh

#echo $JAVA_HOME/bin/java -cp $CLASSPATH ie.bge.middleware.envstatus.app.SetSystemStatus $@

$JAVA_HOME/bin/java -cp $CLASSPATH ie.bge.middleware.envstatus.app.SetSystemStatus $@

N.B. script must be executable. Therefore chmod +x


Parse log file with awk
awk normally splits lines based on whitespace characters. This can be forced however using the -F switch and passing a regex.
e.g. the following splits on semi-colon, and prints the 3rd and 6th fields.
awk -F ";" '{print $3 " " $6 }'
this example splits on commas, within quotes e.g. "value1", "value2", ..
awk -F "\"*,\"*" '{print $3}' file.csv

Identify unix version
uname -r
cat /etc/*-release
cat /etc/issue
rpm -qa --queryformat "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n"|grep release|sort

Misc Tips
Whitepace gothcas when writing bash scripts.

Bash IF statment requires whitespace.
DIRNAME=mydir
if [ -d $DIRNAME ]; then
echo $DIRNAME exists
else
echo $DIRNAME does not exist
fi

1/ There must be NO whitespace in the set command (DIRNAME=mydir, ..e.g. the following won't work DIRNAME = mydir). Otherwise bash misinterprets the set operation as a command (called DIRNAME here).
2/ The whitespace between the IF statement and the [..] is required. e.g. (if [-d $DIRNAME]; then will cause an error)

Script to copy latest build folder to other location
#!/bin/bash
# Exit on Error
set -e
DIR=/usr/local/apache2/htdocs/Repository
CIDIR=/opt/continuous_integration/build_archive/
echo $#
if [ $# -ne 1 ]; then
echo Usage: PublishBuild.sh VER. Must supply version number.
exit 1
fi
VER=$1
if [ ! -d ${DIR}/$VER ]; then
mkdir ${DIR}/$VER
fi
if [ ! -d ${DIR}/${VER}/osb ]; then
mkdir ${DIR}/$VER/osb
fi
CIB=`ls -t ${CIDIR}| head -n 1`
echo cp -R ${CIDIR}/${CIB}/* ${DIR}/${VER}/osb
cp -R ${CIDIR}/${CIB}/* ${DIR}/${VER}/osb
echo Copied ${CIB} to ${VER}
exit 0

Friday, October 13, 2006

Drupal built in Global

Heres the small prog to produce this list

foreach($GLOBALS as $g=>$v){
if(is_array($v)){
echo("$g = Array {");
foreach($v as $a2=> $b2){
echo("$a2=$b2,");
}
echo("}");
}else
echo("$g = $v");
}

Heres the list
  • HTTP_POST_VARS = Array {}
  • _POST = Array {}
  • HTTP_GET_VARS = Array {q=node/11,}
  • _GET = Array {q=node/11,}
  • HTTP_COOKIE_VARS = Array {MANTIS_PROJECT_COOKIE=5,PHPSESSID=b9fb481c4b12115c83761754702db5ae,MANTIS_STRING_COOKIE=b36c8ddd894abf6d551b90aed8552328be6ab68c73aafdf3d611d932e25c67da,userwdth=null,userfontsz=null,userbg=null,phpMyAdmin=8d176d85421e8ec646ce148c4893cbec,}
  • _COOKIE = Array {MANTIS_PROJECT_COOKIE=5,PHPSESSID=b9fb481c4b12115c83761754702db5ae,MANTIS_STRING_COOKIE=b36c8ddd894abf6d551b90aed8552328be6ab68c73aafdf3d611d932e25c67da,userwdth=null,userfontsz=null,userbg=null,phpMyAdmin=8d176d85421e8ec646ce148c4893cbec,}
  • HTTP_SERVER_VARS = Array {HTTP_HOST=localhost,HTTP_USER_AGENT=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7,HTTP_ACCEPT=text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5,HTTP_ACCEPT_LANGUAGE=en-us,en;q=0.5,HTTP_ACCEPT_ENCODING=gzip,deflate,HTTP_ACCEPT_CHARSET=ISO-8859-1,utf-8;q=0.7,*;q=0.7,HTTP_KEEP_ALIVE=300,HTTP_CONNECTION=keep-alive,HTTP_REFERER=http://localhost/psoup/lia/?q=node/13,HTTP_COOKIE=MANTIS_PROJECT_COOKIE=5; PHPSESSID=b9fb481c4b12115c83761754702db5ae; MANTIS_STRING_COOKIE=b36c8ddd894abf6d551b90aed8552328be6ab68c73aafdf3d611d932e25c67da; userwdth=null; userfontsz=null; userbg=null; phpMyAdmin=8d176d85421e8ec646ce148c4893cbec,HTTP_CACHE_CONTROL=max-age=0,PATH=c:\\apps\\ruby\\ruby-184-17\\bin;c:\\apps;C:\\oracle\\product\\10.2.0\\db_2\\bin;c:\\beaSP2\\jdk141_05\\bin;c:\\apps\\ruby\\bin;c:\\apps\\sybase\\OCS-12_5\\lib3p;c:\\apps\\sybase\\OCS-12_5\\dll;c:\\apps\\sybase\\OCS-12_5\\bin;c:\\apps\\sybase\\SQLRemote\\dll;c:\\apps\\sybase\\RPL-12_5\\bin;c:\\apps\\sybase\\JS-12_5\\bin;c:\\apps\\sybase\\ASE-12_5\\dll;c:\\apps\\sybase\\ASE-12_5\\bin;C:\\Program Files\\ATI Technologies\\ATI Control Panel;c:\\apps\\imagemagick-6.1.5-q16;c:\\apps\\gpg\\bin;c:\\apps\\sybase\\OLEDB;c:\\apps\\cvs;c:\\apps\\sybase\\ODBC;c:\\apps\\sybase\\ASEP_Win32;c:\\apps\\sybase\\OCS-12_5\\dll;c:\\apps\\sybase\\OCS-12_5\\lib3p;c:\\apps\\sybase\\OCS-12_5\\bin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\Program Files\\ATI Technologies\\ATI Control Panel;c:\\apps\\apache-ant-1.6.2\\bin;C:\\Program Files\\Subversion\\bin;c:\\apps\\php-4.3.9-Win32;C:\\Program Files\\Common Files\\GTK\\2.0\\bin;c:\\Program Files\\MySQL\\MySQL Server 4.1\\bin;C:\\Program Files\\cvsnt;C:\\apps\\php-4.3.9-Win32;C:\\Program Files\\QuickTime\\QTSystem\\,SystemRoot=C:\\WINDOWS,COMSPEC=C:\\WINDOWS\\system32\\cmd.exe,PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.RB;.RBW,WINDIR=C:\\WINDOWS,SERVER_SIGNATURE=
  • Apache/2.0.58 (Win32) PHP/4.3.9 Server at localhost Port 80
  • ,SERVER_SOFTWARE=Apache/2.0.58 (Win32) PHP/4.3.9,SERVER_NAME=localhost,SERVER_ADDR=127.0.0.1,SERVER_PORT=80,REMOTE_ADDR=127.0.0.1,DOCUMENT_ROOT=C:/Program Files/Apache Software Foundation/Apache2/htdocs,SERVER_ADMIN=admin@ad.aol.aoltw.net,SCRIPT_FILENAME=C:/dev/psoup/lia/index.php,REMOTE_PORT=2251,GATEWAY_INTERFACE=CGI/1.1,SERVER_PROTOCOL=HTTP/1.1,REQUEST_METHOD=GET,QUERY_STRING=q=node/11,REQUEST_URI=/psoup/lia/?q=node/11,SCRIPT_NAME=/psoup/lia/index.php,PHP_SELF=/psoup/lia/index.php,PATH_TRANSLATED=C:/dev/psoup/lia/index.php,}
  • _SERVER = Array {HTTP_HOST=localhost,HTTP_USER_AGENT=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7,HTTP_ACCEPT=text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5,HTTP_ACCEPT_LANGUAGE=en-us,en;q=0.5,HTTP_ACCEPT_ENCODING=gzip,deflate,HTTP_ACCEPT_CHARSET=ISO-8859-1,utf-8;q=0.7,*;q=0.7,HTTP_KEEP_ALIVE=300,HTTP_CONNECTION=keep-alive,HTTP_REFERER=http://localhost/psoup/lia/?q=node/13,HTTP_COOKIE=MANTIS_PROJECT_COOKIE=5; PHPSESSID=b9fb481c4b12115c83761754702db5ae; MANTIS_STRING_COOKIE=b36c8ddd894abf6d551b90aed8552328be6ab68c73aafdf3d611d932e25c67da; userwdth=null; userfontsz=null; userbg=null; phpMyAdmin=8d176d85421e8ec646ce148c4893cbec,HTTP_CACHE_CONTROL=max-age=0,PATH=c:\\apps\\ruby\\ruby-184-17\\bin;c:\\apps;C:\\oracle\\product\\10.2.0\\db_2\\bin;c:\\beaSP2\\jdk141_05\\bin;c:\\apps\\ruby\\bin;c:\\apps\\sybase\\OCS-12_5\\lib3p;c:\\apps\\sybase\\OCS-12_5\\dll;c:\\apps\\sybase\\OCS-12_5\\bin;c:\\apps\\sybase\\SQLRemote\\dll;c:\\apps\\sybase\\RPL-12_5\\bin;c:\\apps\\sybase\\JS-12_5\\bin;c:\\apps\\sybase\\ASE-12_5\\dll;c:\\apps\\sybase\\ASE-12_5\\bin;C:\\Program Files\\ATI Technologies\\ATI Control Panel;c:\\apps\\imagemagick-6.1.5-q16;c:\\apps\\gpg\\bin;c:\\apps\\sybase\\OLEDB;c:\\apps\\cvs;c:\\apps\\sybase\\ODBC;c:\\apps\\sybase\\ASEP_Win32;c:\\apps\\sybase\\OCS-12_5\\dll;c:\\apps\\sybase\\OCS-12_5\\lib3p;c:\\apps\\sybase\\OCS-12_5\\bin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\Program Files\\ATI Technologies\\ATI Control Panel;c:\\apps\\apache-ant-1.6.2\\bin;C:\\Program Files\\Subversion\\bin;c:\\apps\\php-4.3.9-Win32;C:\\Program Files\\Common Files\\GTK\\2.0\\bin;c:\\Program Files\\MySQL\\MySQL Server 4.1\\bin;C:\\Program Files\\cvsnt;C:\\apps\\php-4.3.9-Win32;C:\\Program Files\\QuickTime\\QTSystem\\,SystemRoot=C:\\WINDOWS,COMSPEC=C:\\WINDOWS\\system32\\cmd.exe,PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.RB;.RBW,WINDIR=C:\\WINDOWS,SERVER_SIGNATURE=
  • Apache/2.0.58 (Win32) PHP/4.3.9 Server at localhost Port 80
  • ,SERVER_SOFTWARE=Apache/2.0.58 (Win32) PHP/4.3.9,SERVER_NAME=localhost,SERVER_ADDR=127.0.0.1,SERVER_PORT=80,REMOTE_ADDR=127.0.0.1,DOCUMENT_ROOT=C:/Program Files/Apache Software Foundation/Apache2/htdocs,SERVER_ADMIN=admin@ad.aol.aoltw.net,SCRIPT_FILENAME=C:/dev/psoup/lia/index.php,REMOTE_PORT=2251,GATEWAY_INTERFACE=CGI/1.1,SERVER_PROTOCOL=HTTP/1.1,REQUEST_METHOD=GET,QUERY_STRING=q=node/11,REQUEST_URI=/psoup/lia/?q=node/11,SCRIPT_NAME=/psoup/lia/index.php,PHP_SELF=/psoup/lia/index.php,PATH_TRANSLATED=C:/dev/psoup/lia/index.php,}
  • HTTP_ENV_VARS = Array {}
  • _ENV = Array {}
  • HTTP_POST_FILES = Array {}
  • _FILES = Array {}
  • _REQUEST = Array {q=node/11,MANTIS_PROJECT_COOKIE=5,PHPSESSID=b9fb481c4b12115c83761754702db5ae,MANTIS_STRING_COOKIE=b36c8ddd894abf6d551b90aed8552328be6ab68c73aafdf3d611d932e25c67da,userwdth=null,userfontsz=null,userbg=null,phpMyAdmin=8d176d85421e8ec646ce148c4893cbec,}
  • conf = Array {array_filter=1,comment_image=2,comment_page=0,comment_story=2,file_directory_temp=c:\windows\temp,filter_default_format=3,filter_html_1=1,image_help=,menu_primary_menu=2,menu_secondary_menu=2,minimum_image_size=0,minimum_page_size=0,minimum_story_size=0,nice_menus_menu_1=42,nice_menus_name_1=Nice Menu 1,nice_menus_number=1,nice_menus_type_1=down,node_options_forum=Array,node_options_image=Array,node_options_page=Array,node_options_story=Array,page_help=,story_help=,theme_default=bluemarine2,type=page,upload_image=1,upload_page=1,upload_story=1,}
  • db_url = mysql://root:@localhost/lia
  • db_prefix =
  • base_url = http://localhost/psoup/lia
  • base_path = /psoup/lia/
  • base_root = http://localhost
  • db_type = mysql
  • active_db = Resource id #6
  • HTTP_SESSION_VARS = Array {watchdog_overview_filter=all,node_overview_filter=Array,}
  • _SESSION = Array {watchdog_overview_filter=all,node_overview_filter=Array,}
  • user = Object
  • queries =
  • timers = Array {page=Array,}
  • locale = en
  • multibyte = 0
  • _menu = Array {path index=Array,items=Array,callbacks=Array,visible=Array,}
  • theme = bluemarine2
  • theme_engine = phptemplate
  • custom_theme =
  • theme_key = bluemarine2
  • sidebar_indicator =

Sunday, September 24, 2006

Wednesday, August 30, 2006

Drupal idiosyncracies

  • The always present "Create Content" menu item (even when users aren't logged in)
http://drupal.org/node/47212
In particular, simply "Reset" the menu item should fix it

  • Read More tag in postings
    http://drupal.org/node/64051
Menus
Should write module to allow new terms to be added to menu system. At moment must create terms. Then create content using those terms. As part of this you can select create menu item.

Nice Menus.
By default css only supplies styles for 1 sublevel. Thus higher sublevels autoexpand. Add the following to stop this
(see http://drupal.org/node/65482)

// Add extra layer to stop 2nd level submenus from autoexpanding
//level 2
ul.nice-menu ul,
ul.nice-menu li:hover ul ul, ul.nice-menu li.over ul ul,
ul.nice-menu li:hover li:hover ul ul, ul.nice-menu li.over li.over ul ul {
display:none;
}

ul.nice-menu li:hover ul, ul.nice-menu li.over ul,
ul.nice-menu li:hover li:hover ul, ul.nice-menu li.over li.over ul,
ul.nice-menu li:hover li:hover li:hover ul, ul.nice-menu li.over li.over li.over ul {
display:block;
}

//Level 3
ul.nice-menu ul,
ul.nice-menu li:hover ul ul, ul.nice-menu li.over ul ul,
ul.nice-menu li:hover li:hover ul ul, ul.nice-menu li.over li.over ul ul,
ul.nice-menu li:hover li:hover li:hover ul ul, ul.nice-menu li.over li.over li.over ul ul {
display:none;
}

ul.nice-menu li:hover ul, ul.nice-menu li.over ul,
ul.nice-menu li:hover li:hover ul, ul.nice-menu li.over li.over ul,
ul.nice-menu li:hover li:hover li:hover ul, ul.nice-menu li.over li.over li.over ul,
ul.nice-menu li:hover li:hover li:hover li:hover ul, ul.nice-menu li.over li.over li.over li.over ul {
display:block;

Wednesday, August 16, 2006

Java Spring and Locales

Related to my previous post. We were updating a web app and localizing it for some new countries.

The jsps used some Spring tag libs.

<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />


Spring comes with an inbuilt LocaleResolver. By default it uses the AcceptHeaderLocaleResolver which detects the clients Locale from the Http headers (which are sent with the bowsers request).

In our case we didn't want the client locale to get picket up. We wanted to set it based on the servername. (To do these we added some virtual hosts to our tomcat instance).

Then to update the Spring Locale we had to use the SessionLocaleResolver . This has to be instantiated via the Spring xml file (otherwise it will default to AceptHeaderLocaleResolver).



We then simply set the Locale froma filter.

String servername = httpRequest.getServerName();
Locale locale = null;
if(servername.indexOf(".co.uk")>0){
_log.info("Setting UK locale");
locale = Locale.UK;
}else if(servername.indexOf(".fr")>0){
_log.info("Setting FR locale");
locale = Locale.FRANCE;
}else if(servername.indexOf(".de")>0){
_log.info("Setting DE locale");
locale = Locale.GERMANY;
}else{
_log.info("Cannot ascertain originating server. Defaulting to UK locale");
locale = Locale.UK;
}


HttpServletRequest

I keep forgetting these value. So I'm writing it down here to remember

Within a servlet, or Filter (or jsp) you can access the following information about the request.

httpRequest.getContextPath(); // =/webapp
httpRequest.getRequestURI(); // =/webapp/webhome
httpRequest.getServletPath(); // = /webhome
httpRequest.getRequestURL(); // = http://mybox.my:11600/webapp/webhome?q=query&r=prevPage
httpRequest.getRequestURI(); // = http://mybox.my:11600/webapp/webhome

httpRequest.getServerName(); // = mybox.my (1)
httpRequest.getRemoteHost(); // = 10.149.93.49 (2)
httpRequest.getRemoteAddr(); // = 10.149.93.49
httpRequest.getRemoteUser(); // = null ... (3)

N.B.
If you perform a RequestDispatcher.forward() then all the above methods will reflect the new forwarded values. Personally I didn't think the javadocs made this clear.

As of Servlet spec 2.4 however you can still access the original client request data using the following attributes. (see http://www.javaworld.com/javaworld/jw-03-2003/jw-0328-servlet_p.html)

  • javax.servlet.forward.request_uri
  • javax.servlet.forward.context_path
  • javax.servlet.forward.servlet_path
  • javax.servlet.forward.path_info
  • javax.servlet.forward.query_string

Inside a forwarded servlet you'll see getRequestURI() return the path to the target servlet as always, but now if you want the original path, you can call request.getAttribute("javax.servlet.forward.request_uri"). One special caveat: if forward() happens through a getNamedDispatcher() call, these attributes aren't set because, in that case, the original path elements aren't changed.

Note from servlet spec 2.2 there already exists

  • javax.servlet.include.request_uri
  • javax.servlet.include.context_path
  • javax.servlet.include.servlet_path
  • javax.servlet.include.path_info
  • javax.servlet.include.query_string
However, these work just the opposite of the forward() attributes. In an include(), the path elements don't change, so the include attributes act as the backdoor to access the target servlet's path elements. Compare this with a forward() where the path elements change so the forward attributes represent the backdoor to the original path elements.

Should filters invoke for forwarded requests? Included requests? What about for URIs invoked via the mechanism? Before Servlet 2.4, these questions were left as open issues. Now Servlet 2.4 makes it a developer's choice. There's a new element in the deployment descriptor with possible values REQUEST, FORWARD, INCLUDE, and ERROR. You can add any number of entries to a like this:


<filter-mapping>
<filter-name>Logging Filter</filter-name>
<url-pattern>/products/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>

This indicates the filter should be applied to requests directly from the client as well as forward requests. Adding the INCLUDE and ERROR values also indicates that the filter should additionally be applied for include requests and requests. Mix and match for what you want. If you don't specify any elements, the default is REQUEST.

The last RequestDispatcher change is to allow, for the first time, relative paths in request.getRequestDispatcher() calls. The path will be interpreted relative to the current request's path. It's a minor change, but comes in handy when dispatching to a sibling servlet.




Notes:
No all these method are available on the basic ServletRequest. Normally I just cast the basic ServletRequest into a HttpServletRequest, since I am normally only writting web apps.

1/ This is the server name from the Request. You can set up your web server to be multi hosted using virtual hosts. (Heres an example for tomcat). Then you can use this variable to differentiate on which host they came in on. We are using this for setting the locale on one project. (In general it is better to choose the locale based on the request,but we have specific reasons for doing it this way).

2/ This is the clients IP address. Can be used for logging.

3/I'm guess this will show a value if the page is protected by HttpAuthentication.

For Php equivilents check out this page

http://www.php.net/reserved.variables

Thursday, July 06, 2006

Updating a Windows Service..

I needed to update mysql to use the old authentication mechanism...
http://dev.mysql.com/doc/refman/5.0/en/old-client.html

This involved adding some command line parameters to mysqld when it starts to use the old authentication mechanism. Unfortunately the Windows Services tool doesn't allow this.

Thanks to http://illiniguy.wordpress.com/2006/03/17/updating-a-windows-service/

regedit to

\\HKEY_LOCAL_MACHINE\SYSTEMCurrentControlSet\Services\___YOUR_SERVICE_NAME___

and edit away...

Saturday, April 08, 2006

Browser interoperability

I've had a lot of headaches with this. In general my approach is to use and libraries/ open source functions etc that are out there since they will almost certainly work better in a cross browser environemnt than what I throw together

This doesn't always work out however and I find myself writting css pages, javascript etc...

Anyway the problem. Looks like a bug in IE. It appears that the document.getElementById() function does not work... However on further examination it turns out that the ID attribute must be the first (or before most atribute) attribute in an html element.

For example

<img class="myimg" name="myimg" src="myimg.jpg" id="12"/>

If you then try to access this in javascript it doesn't work

docuemnt.getElementById("12") returns a null.

However if you re-jig the element so id is the first attribute then it works fine.. Bizarre.

<img id="12" class="myimg" name="myimg" src="myimg.jpg" />

[tested on IE 6.02]

Thursday, October 13, 2005

DB access in word VBA

I was working on little program to extract data from a word document, and insert it into a database. Pretty straightforward VBA for a VBA developper... Except I'm not a VBA developper.

Actually it proved quite simple up to the point where I need to make an ODBC connection to the database. Then all hell broke loose.

In time honoured VBA programming practise, when you hit upon a problem, record a macro, and do the step you want to, then view and edit the code.. .

This I did and discovered the nice looking InsertDatabase [Link to msdn]
. Worked a treat.. Read data from the odbc, and displayed in it the doc. Wonderful!

Except for the teeny weeny problem thatI wanted to display the data in a userForm. Reading the docs in that link above, the InsertDatabase method can only be called on a Range object. Try as I might I couldn't find a Range object in the UserForm.

Long story short.. I found the ADO object which solved my problems.. Gives you a full API for talking to DB's. You will need to install the reference libraries Microsoft AxtiveX Data Object library (you will need your office install media for this), and include them in your references first.

I did briefly run into the infamous Error 80004005 "Data Source Name Not Found"

But with a bit of tinkering around I got this to work.

First step, create a systemDSN (userDSN should also work) of the name for the ODBC connection you want (vba in this instance)

Then the following code calls a table there and inserts the data into my UserForm (called UserInput)


Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String

Const ConnectString = "DATABASE=vba;DESCRIPTION=Vba Test;DSN=vba;OPTION=0;PORT=0;SERVER=localhost"


cn.ConnectionString = ConnectString
'cn.CursorLocation = adUseClient
cn.Open

' Find out if the attempt to connect worked.
If cn.State = adStateOpen Then
Set rs = cn.Execute("Select * From test")
If rs.EOF Then
UserInput.namesList.AddItem "No Entries returned from Database."
Else
While Not rs.EOF
UserInput.namesList.AddItem rs("data") & ":" & rs("date")
rs.MoveNext
Wend
End If
'MsgBox (rs("data") & ":" & rs("date"))
rs.Close
Else
MsgBox "Sorry there was a problem connecting to the database."
End If

cn.Close


Wonderful..

Any questions, drop me a comment,

Thursday, August 25, 2005

more xml schema validation

I thought I had Xml validation sorted after the following entries (java and xml, and schema validation).

So today when I went to validate some xml's against a Xsd I was a bit surprised when it didn't work

What was more surprising was that it was working, and when I changed something small, it stopped.

As part of a Unit Test I was validating an xml file against a schema, and it was working fine. However I was loading the Xsd via a webserver into the parser. This wouldn't do since other developpers would want to run the unit tests and would not want the hassle of starting up a webserver and dropping the xsd file in place initally before running the tests.

So I changed the URL to load the Xsd via the file:// protocal. See below

xsd="file://"+path+"wishlist.xsd";


Running that however gave the following exception



org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'wishList'.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
....


But I knew the XSD was correct because it had been working before when I retrieved it via http:// on my webserver....

Do you see the problem? Well I didn't initially. After some poking around I found the solution.

xsd="file:///"+path+"wishlist.xsd";

See the difference. Subtle isn't it. Basically xerces insists that file needs 3 forward slashes in it url definition (file:///wishlist.xsd). That was the problem. Surely a better error message could have been generated there. (Maybe XSD not found or something)

Anyway I then started gettign the following error



org.xml.sax.SAXParseException: Invalid byte 1 of 1-byte UTF-8 sequence.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
...


Short answer to this problem was my file character encoding. I had saved my xsd using a free editor (crimson). By default it saves files in Ascii encoding. However my Xsd expected to be in UTF-8. Changing the character encoding and re-saving solved the problem.

Amazing how a simple little task can tie you down for hours..

Monday, August 15, 2005

Regular expressions tutorial

I can never remember Regular Expressions (regex).

So heres a good tutorial on the subject I found. http://www.silverstones.com/thebat/Regex.html

once you've read that, then pick one of the following results as a quick reference card.
http://www.google.ie/search?q=regex+quick+reference


---Added Jul 13 ----
Just found this great site for validating your regex's online.. Brilliant.

http://www.koralsoft.com/regextester/

Regexs
Strip html from strings
//javascript Makes <b>Hello</b> World => Hello World
tag = tag.replace(/(<([^>]+)>)/ig,"");

Split CamelCase word (Note performance might not be great for many iterations)
s.replaceAll("([A-Z])", ' $1'); // taken from here

Slight modification (don't split if more than one capital after another)
s.replaceAll("([A-Z]{1,})", ' $1');

Thursday, August 04, 2005

Remote Debugging Java with eclipse

This is a powerful feature which allows you to debug a remote server from an IDE, and step through the code to see what is happening. For example a remote web server like tomcat, or an app server like WebLogic or Websphere can be debugged.

Firstly the basis of this is a feature in the Java JVM. This means that any java executable can be debugged this way.

To start debugging on a java instance you need to include the following when you run the JVM

java -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=n,suspend=n,address=8000 -Djava.compiler=NONE

For running Weblogic Server in debug mode subtle difference
java -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 -Djava.compiler=NONE

This sets the debugger listening on a socket on port 8000.

Debugging can also be set up using shared memory, but eclipse can't use the shared memory feature so I won't deal with it here (BTW, Netbeans can use the shared memory mechanism for debugging so this can be pursued if you are using Netbeans)

Simply then within eclipse you need to select Run/Debug.... From there select Remote Debugging, select the project where you have the source code for the project, and specify the server name where the service is running and the port (8000 in our case), and you're laughing.

Easy peasy.

If you are running tomcat (well version 5.5 anyway), the startup scripts already have the debugging information included, see this link
http://jakarta.apache.org/tomcat/faq/development.html

What I've done then is simply changed the startup.bat file.

At the start (line 9) I added the following, which specifies socket based debugging (shared memory is the default), and sets the listen port to 8000
rem ++++++++++++++++++++++++++++++++++++++
rem Enable Remote Debugging
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
rem ++++++++++++++++++++++++++++++++++++++

Careful of any extra spaces of tabs on these line. An extra space caused me some problems for a while.

Then change the 2nd last line where it calls the catalina.bat file from
call "%EXECUTABLE%" %CMD_LINE_ARGS% start

to

call "%EXECUTABLE%" start %CMD_LINE_ARGS%

Now when you call the startup.bat you can simply call startup jpda to start the debugger listening on port 8000. Then you can attach your IDE to port 8000 and debug the server.

Alternatively you can simply call the catalina.bat file directly using the command

catalina.bat jpda start

But you must declare JPDA_ADDRESS=8000 and JPDA_TRANSPORT=dt_socket as environment variable (or put them in the catalina.bat)

Weblogic

Remote debugging with eclipse

To enable remote debugging for weblogic the following must be done

In the setDomainEnv.cmd or setDomainEnv.sh you must assign the variable debugFlag to true. (Note no need for quotes etc as I discovered after some time debugging)

setDomnainEnv.cmd

set debugFlag=true

setDomainEnv.sh

local debugFlag=true

Wednesday, July 13, 2005

Website notice

Just want to publicise www.billyeccles.com. This is a website I developed for, Billy Eccles (surprise surprise). Billy is a potter based in Dublin. He also happens to be my girlfriends father. So no pressure there... Anyway have a look and let me know what you think, and like in restaurants/ shops etc.

"If you don't like something on the site tell me.... If you like something, tell everyone" (and me as well).

Technical aside
You may notice that the site is a PHP site, and yet all my postings before now, have been Java related. That's correct. For this site I realised that if I was to develop anything worthwhile I needed to leverage as much free code as possible. So I'm using an open source CMS called Mambo. It saved me a lot of time.

Tuesday, July 12, 2005

Autostart Vnc

Took me a while to find this so I thought I'd write it down. Of course its easy when you know how.

Edit /etc/sysconfig/vncservers

Add the following

VNCSERVERS="1:username"

Where 1 is the display to start the vncserver on, and username is the name of the user you want to start vnc as (Not root). Simple as that. You should also run vncpasswd first and set the vnc password on the system.

Now a quick explanation

The /etc/sysconfig dir contains information on user services to be started up (unlike the /etc/rx.d dir that starts up system services). Information on these can be found in

RedHat docs


or on

/usr/share/doc/initscripts-/sysconfig.txt

Cross platform Jsp issues

I find this hard to believe, yet it seems to be true


Take a simple html tag with a jsp tag


<input name="text" value="<%=new String("Hello")%>"/%>


That works fine on tomcat. No problems...

On weblogic however, no go...

The problem is the nested quotes """

To get it to work, obviously a few solutions

<input name="text" value="<%=new String(\"Hello\")%>"/%>

or

<input name="text" value='<%=new String("Hello")%>'/%>

Both easy solutions once you know the problem. Of course it took me a while to find out that this problem. In my defence, I wasn't doing something so simple as the above example. I was having problems with a tiles definition.
After a bit of effort I now have some basic JSF pages working.

One error that stumped me for a good while was the following

javax.faces.el.PropertyNotFoundException:
Can't instantiate class ....

This came about from a backing bean I was tryign to configure from my face-config.xml


<managed-bean-name> Menubar </managed-bean-name>
<managed-bean-class> com.aol.beans.jsf.Menubar </managed-bean-class>
<managed-bean-scope> application </managed-bean-scope>
<managed-property>
<description>List of items to appear in the MenuBar and privilages, these get localised to menu.</description>
<property-name>itemsAndPrivilegeLevel</property-name>
<property-class>java.lang.String[]</property-class>
<list-entries>
<value>home,1</value>
<value>profile,1</value>
<value>performance,1</value>
<value>transaction,1</value>
<value>reference,1</value>
<value>sysAdmin,3</value>
<value>production,2</value>
<value>logout,1</value>
</list-entries>
</managed-property>
</managed-bean>


Basically I was trying to set the itemsAndPrivilegeLevel parameter in the bean.

The problem was I hadn't created a getItemsAndPrivilegeLevel method in the bean. I dodn't think I needed one (I don't), but apparently either JSF or the beans specification think different, so I have to have that method there.

The perils of globalisation

... from a programmers persepctive...

Call it globalisation or internationalisation, either way it not as straightforward as I'd like to believe.

As a java programmer it all seems easy. Use a ResourceBundle and store all your text in handy resource files. These can easily be translated as needs require. However once you've externalised all of your user displayed text to property files, thats when the fun really begins. Especially if you're dealing with a non Western script.


Funny how Japanese text looks like fractions, symbols and punctuation marks you may find yourself saying....
.....
Once you get past that stage though, then its onto the world of character encodings.

Character encoding. It's something most Western language users blissfully ignore. Its only when you try and export your freshly translated text to say Japan that things come tumbling down.

The best links I found on this are here and here.

Ah ha, maybe that 3/4 symbol isn't in fact the japanese for Hello.

In fact its garbled character encoding. Looks like its time to instruct your webserver to serve up different character sets.

I started out setting up Tomcat to send UTF-8. There are a few distinct steps involved.


1.
The JVM must be initiated using the correct charset. This sets the format of the files that java will use (includes, properties file, jsp pages etc.)

This is done with the following switch

-D=file.encoding=UTF-8

so for Tomcat, I added the following to the cataline.bat file

set CATALINA_OPTS=-D=file.encoding=UTF-8


2.
Its important to realise the standard encoding used by the OS that you are running. My version of windows is using a Western Latin-1 script. This is unable to display japanese characters. In order to get japanese characters displayed I had to install japanese character supprt.

This also means that files (for example properties files) may be stored in a different character set than you may be expecting.

In my case, I was using Crimson as an editor. Crimson saves all charcters as Ascii, thus cannot display japanese character, or even Western scripts such as é or ß characters. I had to find a unicode enabled editor. Unipad is a good one that I found.

Java properties files do not by default support unicode. They must be encoded.

Once your files are stored in a unicode mapping, you have to run it through the nativeToAscii program which escapes out any strange foreign characters and puts in the exact unicode code point instead. (Theres an ant task which can be used for this).

<native2ascii encoding="UTF-8" src="$%7Bsrc.dir%7D" dest="${build.dir}" includes="**/*.properties">.

Once your basic java environment is set, you need to be able to set the character encoding for the page. This can be set with a page directive

<%@ page contentType="text/html;charset=UTF-8" />

or in xml syntax

<jsp:directive.page contenttype="text/html;charset=UTF-8">

4.
Finally (I think) set the encoding for the HttpResponse (So you can understand any text that gets sent back)

Using jstl

<fmt:requestencoding value="UTF-8">



Now in the above example I have used UTF-8 as the encoding, this encoding maps to a variable number of bytes (from 1 to 6). Western mappings e.g. ascii will normally be covered by 1 byte, but those foreign type scripts may take up to 6 bytes to be encoded.

If you are mainly directing pages to Japanese clients then UTF-8 will be quite wasteful. A fairer encoding might be UTF-16 (doesn't seem to be supported by IE, or Mozilla browsers), or even (I going out on a bit of a limb here) Shift-JIS.



Its all very nice, if it all works well , but if it doesn't..... Can be bit nasty.

What I'm looking at now is changing the encoding deplending on the locale. The serlvet 2.4 spec has a nice mapping

<local-encoding-mapping-list>
<locale>jp</locale>
<encoding>Shift_JIS</encoding>
</local-encoding-mapping-list>

which hopefully will sort things out.

If theres no more entires on this subject then it all worked out swimmingly

Location independent loading of properties

Heres another little douzie that been slapping me across the face all day.

When writing and deploying code you don't want to have absolute paths listed for config files, resources etc, as these will invariably lead to problems when moving the application to another server.

Normally with java this entails creating a deployment directory, and including within it all classes and resources that you may need. You then load all files and properties using the deployment directory as the root.

The question then arises how do you access these properties.

For example with properties files the initial way one thinks of to load properties is as follows


FileInputStream inputStream = new FileInputStream("");
Properties prop = new Properties();
prop.load(inputStream);


The problem with this is that the is an absolute value, which knows nothing of the deployment directory that you may be running from.

The solution is to use one of the following


Class.getResourceAsStream() or
ClassLoader.getResourceAsStream()


The funny thing is that for me sometimes the first method works (e.g. when run from within Eclipse), and the 2nd one fails. Sometimes (from with tomcat) the first one fails and the 2nd one works.

In fact initially I had posted to use the 2nd method after spending a few hours tracking down why my program worked in Eclipse but failed in tomcat. It was only a day later that I discovered that the 2nd method (which works in tomcat) doesn't work in eclipse.

So now I have this slightly ugly construct to try and get around the problems

/**
* The name of the properties files. N.B. the "/" at the start means it is an absolute
* package, not a relative path from this package.
* Default propertuies location /resources/rsi.properties in the classpath may be
* overridden by setting the System property rsiserver.property.file,
* as in the test ant target, or with java -Drsiserver.property.file=myNewPropertiesFile
*/
static String propLoc="/resources/rsi.properties";
static{
// First check system property to see if specific properties file is set
propLoc = System.getProperty("rsiserver.property.file", propLoc);
prop=new Properties();
InputStream is = Utils.class.getResourceAsStream(propLoc);
if(is==null){
log.debug("Failed to load Resource ["+propLoc+"] from Utils.class.getResourcesAsStream() trying classloader.");
ClassLoader cl=Utils.class.getClassLoader();
if(log.isDebugEnabled())
log.debug("ClassLoader = "+cl);
is=cl.getResourceAsStream(propLoc);
}

try {
//Throws IOException
prop.load(is);
} catch (Exception e) {
log.fatal("Exception loading Properties file.",e);
}
}




I'm at a loss to explain it, but I suspect (hope) that its some configuration problem.

Xml schemas and Namespaces?

With the amount of headaches I'm having doing a simple task like validating an Xml doc against a schema, I'm back to wondering if I shouldn't just throw this programming lark aside..

....

In the meantime heres the root cause of my most recent heartache....

The solution is ...

String xml ="<envelope><header2>Hi</header2></envelope>";
String xsd = "http://localhost:8080/xml/test.xsd";
SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
builder.setFeature("http://apache.org/xml/features/validation/schema", true);
builder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",xsd);
builder.setValidation(true);
builder.build(new InputSource(new StringReader(xml)));


Simple isn't it

What could have been the problem?

The problem is that innocuous line builder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",xsd);

To cut a long story short Xerces has 2 modes for validating external schemas (i.e. not the schemas referenced in the Xml doc itself). 1/ Namespace enabled 2/ No Namespace.

Simple huh?

Well it is once you know that simple fact. I on the other hand didn't . (Mind you I do think it should be possbile to validate an arbitary Xml doc without necessarily knowing if its namespace enabled or not. But thats for another day)

So in summary people

If you want to avoid cryptic exceptions like

org.jdom.input.JDOMParseException: Error on line 1: cvc-elt.1: Cannot find the declaration of element 'envelope'.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:466)
at XmlTest.main(XmlTest.java:41)
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'envelope'.
.....


NB. This is the same exception you get if Xerces cannot locate your schema file, or if you don't configure the paramerters correctly. Something more intuitive would be more helpful.

do the following

1/ If your Xml doc uses namespaces

String xml ="<envelope><header2>Hi</header2></envelope>";
// Namespae of xsd1
String ns1 = "http://www.w3.org/2001/12/soap-envelope"
String xsd1 = "http://localhost:8080/xml/test.xsd";
//Namespace of xsd2
String ns2 = "http://kevinj.develop.com/weblog/weblog.xsd";
String xsd2 = "http://localhost:8080/xml/test2.xsd";

SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
builder.setFeature("http://apache.org/xml/features/validation/schema", true);
builder.setProperty(
"http://apache.org/xml/properties/schema/external-schemaLocation", ns1+" "+xsd1+" + ns2+" "+xsd2);
builder.setValidation(true);
builder.build(new InputSource(new StringReader(xml)));


You must set the Property http://apache.org/xml/properties/schema/external-schemaLocation with a space seperated String list of the schema(s) to validate against.
The list takes the following form namespace uri namespace uri .... Its composed of pairs of values, the namespace that the schema will validate and the actual location of the schema file. (It can be any uri http://, file:// etc)

This section is taken from the JDOM FAQ


Schema locations are given by setting the property "http://apache.org/xml/properties/schema/external-schemaLocation" to a list of whitespace separated name-value pairs. The 'name' is the namespace the schema is associated with, the 'value' is the location of the schema for that namespace. For example:

builder.setProperty(
"http://apache.org/xml/properties/schema/external-schemaLocation", "http://www.w3.org/2001/12/soap-envelope soap-envelope.xsd" + " " + "http://kevinj.develop.com/weblog/weblog.xsd weblog.xsd");

The above example shows how to validate against multiple schemas -- against the SOAP 1.2 schema where the namespace is http://www.w3.org/2001/12/soap-envelope and the and against a schema for namespace http://kevinj.develop.com/weblog/weblog.xsd. The files describing these schemas are in soap-envelope.xsd and weblog.xsd respectively. You can add as many of these name value pairs as necessary. The values themselves are URLs. The name value pairs follow the meaning given in the Schema recommendation (http://www.w3.org/TR/xmlschema-1/#schema-loc ).




2/ If your Xml doc does not use namespaces

String xml ="<envelope><header2>Hi</header2></envelope>";
String xsd = "http://localhost:8080/xml/test.xsd";
SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
builder.setFeature("http://apache.org/xml/features/validation/schema",true);
builder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",xsd);
builder.build(new InputSource(new StringReader(xml)));


Here we set the propertyhttp://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation (spot the difference) with simply the schema uri. (Not a List as there is only the default namespace) to validate against, and only a single items since there is no namespaces, (i.e. not a pair like before)


It may look simple but that wee little problem had me stumped for longer than I'd care to mention.

Heres some links on the stuff

The Jdom faq Jdom uses xerces so this applies to xerces as well.
xerces bugzilla entry. There was a bug with this prior to version 2.2.0

One aside. By default xerces will not throw exceptions for validation failures, the parser must be configured to do that.

Jdom will configure the parser to do this by default. (for a lazy programmer like me this simply means that I use jdom to wrap my calls to xerces, rather than actually looking up how to configure xerces)

More on xml classpaths

Just an extra note on the xml classpath issue. jdk1.4 comes with an old version of xerces that must be updated for the schema validation to work. I discovered this today when I started running into the same problem as last Friday after I changed the java.endorsed.dirs to be %JAVA_HOME%/lib/endorsed. Even though jdk1.4 ships with a version of xerces, and its in the endorsed directory, my validation failed, until I copied a newer version of the xercesImpl.jar into the endorsed dir. I've used xerces 2.6.1 which does work.

Java Xml and schemas growing paings


I've just spent the morning stumped on a problem I had working before. I was trying to validate an Xml doc against a schema but kept getting the following.


Exception in thread "main" java.lang.ClassCastException
at org.apache.xerces.impl.xs.XMLSchemaLoader.processExternalHints(XMLSchemaLoader.java:567)
at org.apache.xerces.impl.xs.XMLSchemaValidator.reset(XMLSchemaValidator.java:1345)
at org.apache.xerces.parsers.BasicParserConfiguration.reset(BasicParserConfiguration.java:543)
at org.apache.xerces.parsers.DTDConfiguration.reset(DTDConfiguration.java:640)
at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:512)
at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:595)
at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)
at org.apache.xerces.parsers.DOMParser.parse(DOMParser.java:253)
at Utils.validate(Utils.java:70)
at XmlTest.main(XmlTest.java:29)


Some investigation on the internet turned up some red herrings

  • Problem with new version of xerces. I tried older version same problem

  • Problem with JDOM. (this is the api I normally use since it is far more intuitive than the basic jaxp or xerces classes). Re doing it in pure xerces didn't help.

  • Bug in xerces.



In the end (as is often the case) I took a break from it, and I had a hunch over lunch.

The problem is jdk 1.4. It includes some xml classes by default, and you need to override these to get xerces to work correctly.

This is done with the java.endorsed.dirs
property. Set this to be the dir where your xerces is stored and Voilia it works.

e.g.

C:\dev\sandbox>java -Djava.endorsed.dirs=\apps\xerces-1_4_3\ -cp classes;\apps\xerces-1_4_3\xerces.jar XmlTest


Check out this article on Endorsed Dirs

Just be careful as well. By default <java-home>\lib\endorsed is the deafult endorsed dir and this may override it. This probably works (I'm just too lazy to bother testing it).

C:\dev\sandbox>java -Djava.endorsed.dirs=\apps\xerces-1_4_3\;%JAVA_HOME%\lib\endorsed -cp classes;\apps\xerces-1_4_3\xerces.jar XmlTest



Alternatively copy all such jars into the default endorsed dir \lib\endorsed.

Hopefully now by putting this up here, maybe I can save someone else a frustrating half day.

Let me know if I do.