Reseeding SharePoint ID field

March 4th, 2010

I was desperate, so I tried to delete items from the trash bin, thinking the seed value would change. No such luck. The UpdateListItems service ID starts from the last item +1.

SharePoint Column Names

February 26th, 2010

For example: Column name “Upload Comment” is actually stored as “Upload_x0020_Comment”. I actually knew this from looking at code in SharePoint Designer, but it never occurred to me that this caused  my UpdateListItems (Cmd=’New’) web service to fail. It failed by not inserting the item, not by flashing “Error Will Robinson” messages at me. So, I replaced spaces in column names with “_x0020_”, and it worked. The java code to do this is: replaceAll(” “,”_x0020_”);

So instead of:  <Field Name = “Upload Comment>A Comment</Field>

I used this: <Field Name = “Upload_x0020_Comment>A Comment</Field>

I am using a java program to build javascript that invokes the UpdateListItems web service. The datasource is Lotus Notes. At this point, you must copy the javascript into a content editor web part. The script builds the javascript including a button. Clicking the button makes the magic happen. More on this later.

Good article concerning this is at http://httpcode.com/blogs/CommentView,guid,fb4a2a24-c1e7-4f23-9317-5ae7f1430036.aspx

SharePoint Sequence Number - [ID]

February 23rd, 2010

I am developing software that uses SharePoint Web Services (UpdateListItems) to add or bulk load items into a list from a Lotus Notes extract. More on this later when I finish. Sequence numbers are not one up numbers from the last item (last item + 1). Instead they are true sequence number, similar to Oracle and Sybase. I found this out by bulk loading a few items then deleting them and reloading. So, if you are starting from a scratch list or a list that you have not loaded/deleted any items from, then this is not big deal. However, if you have loaded/deleted items, then the numbers will be out of sequence.

As far as I can tell, there is no sequence number reset. Too bad.

My Friend Richard Gunter

January 31st, 2010

Rich and I were working at Computer Sciences Corporation at the time, but we were in different divisions and did not know each other. Rich called me up on day and said he wanted to talk to me about a job. It was early 1988. I wanted out of the Pentagon, so I said, “sure, lets talk.” We arranged to meet. The interview went something like this:

Rich: I have a job that I think you could do.
Me: What is it?
Rich: I can’t tell you.
Me: Where is it?
Rich: I can’t tell you that either
—Pause—
Me: When do I start?
Rich: Monday.

Rich made a big impression on me that day. He was like that. I did not know it at the time, but the decision I made that day was - bar none - the best career decision I have ever made.

Rich solved problems by brutally applying logic. I on the other hand thought logic - while important - was no substitute for roll-up-your-sleeve ingenuity, common sense and - yes- wild ideas. I pushed him to look outside the rigid, structured and logical world that was embedded in his genius mind. He was systematic, I was innovative. We made a great team.

I knew Rich for twelve years. The first two years he mentored me. He did not have to do that, but he did. It was two of the most important years of my career. I would have done anything to please Rich. He deserved the very best work I could produce, and he got it.

I was walking through the halls when I saw Nancy. She said, “Did you hear that Rich passed away?” At first I thought she was joking. I remember thinking how cruel to joke about that. But, then I looked at her ashen face and watery eyes. I was shocked beyond words. I rushed back to my desk and called Melinda. She was crying. I knew it was true. I put down the phone, gathered my things, walked to my car and drove home. I was in a daze. I arrived home, walked upstairs, closed the door and cried for what seemed like forever. I cried for my friend and mentor like you would for a lost parent.

There are those that you think will live forever. Rich was one of those people. Rich was our leader, he was our friend. He was bigger than life and a true one of a kind original.

After all these years I still miss Rich. I miss carpooling with him. I miss brainstorming with him. I miss having lunch with him. I miss walking over to his desk and saying, “Hey Rich, you got a minute?”

Rich pass away ten years ago today.

Resize Image Utility

February 6th, 2009

Java has excellent capability for images, sound, multimedia, etc. I developed this utility to, yes you guessed it, save some cycles and pain and aggravation for yours truly. This utility takes an image and resizes it based on input parameters. It requires three parameters: 1) url to the image, 2) width you want the resized image, 3) height you want the resized image. Now, as everybody know, it is impossible to resize objects exactly as asked for and keep a decent aspect. If I try, for example to take a large photo and resize it to 100×100, well… it’s not going to look good. The utility resizes while keeping the image “viewable”, so if I ask to resize to 100×100, the utility will select the best ratio. It still may look nasty, but as least it is consistently nasty!

The utility works for all images, but it works best for jpg. URLs to images behind ssl will not work. I suppose I could set up ssl connection, but… nah. Why make this hard! If you are faced with this issue, I suggest copying ssl image to your hard drive and point the utility there.

If you are using a Mac, trying this out will be easy. All you have to do is copy the code (see below) to a file, save it, compile it and run it. That’s it sports fans. Have I mentioned that I love my iMac? All the jar files were already setup and I did not even have to include a class path! Insane. For those out there who have run java programs before, you know that finding the necessary jar files can be a PIA. Well, if you are not using a Mac, all bets are off. You are on your own, although I run this at work on Windows XP.

At work, I made a slight modification to the utility to accept - in addition to url - a directory. Being able to ingest everything in a folder and resize is sweet. All I do is copy all the images I want to a folder and point the utility to it. Double sweet.

Note to reader: Adobe Photoshop does a better job of resizing images.

Run from my Mac:
javac ResizeImage
java ResizeImage http://animals.nationalgeographic.com/staticfiles/NGS/Shared/StaticFiles/animals/images/800/orca-killer-whale.jpg 300 300

Image before: http://animals.nationalgeographic.com/staticfiles/NGS/Shared/StaticFiles/animals/images/800/orca-killer-whale.jpg

Image after: http://www.csatechconsulting.com/blog/wp-content/uploads/2009/02/staticfilesngssharedstaticfilesanimalsimages800orcakillerwhale.jpg

ResizeImage.java:

import java.io.*; import java.net.URL; import java.net.MalformedURLException; import com.sun.image.codec.jpeg.*; import java.awt.*; import java.awt.image.*; public class ResizeImage{ public static void createThumbnail(String url, String width, String height){ try{ // get url handle URL my_url = new URL(url); // get image object so we can get width, height of image Image image = Toolkit.getDefaultToolkit().getImage(my_url); // let's track the object MediaTracker mt = new MediaTracker(new Container()); mt.addImage(image, 0); // wait for image to load mt.waitForID(0); // convert input width/height to integers int thumbWidth = Integer.parseInt(width); int thumbHeight = Integer.parseInt(height); double thumbRatio = (double)thumbWidth / (double)thumbHeight; // get width/height of image int imageWidth = image.getWidth(null); int imageHeight = image.getHeight(null); double imageRatio = (double)imageWidth / (double)imageHeight; if (thumbRatio < imageRatio) thumbHeight = (int)(thumbWidth / imageRatio); else thumbWidth = (int)(thumbHeight * imageRatio); BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB); // resize image Graphics2D graphics2D = thumbImage.createGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null); // extract the file name from the url and replace "evil" characters String fName = my_url.getFile().replaceAll("/","").replaceAll(":","").replaceAll("-",""); // create output file BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(fName)); // write resized image to output file JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage); int quality = Integer.parseInt("100"); // we want good quality quality = Math.max(0, Math.min(quality, 100)); param.setQuality((float)quality / 100.0f, false); encoder.setJPEGEncodeParam(param); encoder.encode(thumbImage); // close output file out.close(); } catch(MalformedURLException e){ e.printStackTrace(); } catch(Exception e){ e.printStackTrace(); } } public static void main(String[] args){ // must have 3 parameters: 1) url of image, 2) width you want the new image, 3) height you want the new image String url = args[0]; String w = args[1]; String h = args[2]; createThumbnail(url, w, h); } }

Extract filename from string

February 5th, 2009

The following Perl program extracts a filename from a given string. It takes one string parameter.


Syntax:
Perl FilenameExtract.pl Paramerter1

Example:
Perl FilenameExtract.pl http://www.csatechconsulting.com/images/WashingtonFlags.JPG

Returns: WashingtonFlags.JPG

FilenameExtract.pl:

if (@ARGV ==0) { print "You must include one parametern"; exit(); } $_ = $ARGV[0]; $wholePath = ~m{([^/]*)$}; $fileName = $1; print "$1n";

Printing CGI Environment Variables

February 2nd, 2009

A Web/Application server interacts with CGI (Common Gateway Interface) scripts via environment variables. These variables are set by the server running the script and may be accessed (read only) by the script.  As noted, they are set every time a script is run. I have used the QUERY_STRING variable in the past to get the string that was passed to the script. I think of these as session variables that you can not create and/or update that contain server information.

I also have used the HTTP_REFERER to refer back to who called the script.


Env.pl

#!/usr/bin/perl print "Content-type: text/html\n\n"; foreach $key (sort keys(%ENV)) { print "$key = $ENV{$key}<p>"; }

Click here to see my web server variables
CGI Info: http://www.cs.unc.edu/Courses/jbs/lessons/www/arch/cgi/

In Memory of a Friend - Richard Arnold Gunter

January 31st, 2009

Have you ever been introduced to someone you immediately liked? Someone whose presence, calming voice and demeanor put you at ease. Someone whom you knew was brilliant, but was gracious enough to make you feel important. That is how I felt when I first met Rich in 1988.  Rich grew up in rural southwest Virginia, a place very similar to where I grew up in rural middle Tennessee. Both our fathers died very young; his from diabetes and mine from heart disease. We immediately became friends.

Rich worked hard growing up, put himself through college and earned a masters degree in statistics from The Johns Hopkins University. If you were fortunate enough to know Rich, you knew how brilliant he was. When he said something, you listened. I was in dozens of meetings with him over the years and on many occasions he would absolutely stun me with his intellect. It was humbling.

Rich was fifteen years older than me and to say that he was a father figure would be an understatement. I would have done anything to please him. Occasionally when I did not please him, he would scold me about the virtues of being prepared, of being timely, and more importantly of being right. He expected perfection and I would have walk to the end of the Earth to provide it. He took me under his wing and mentored me for several years. His mentoring was the highlight of my career.

Rich was a man of uncompromising character and principle, of honesty and integrity, of loyalty and determination, of wit and wisdom, of pride and patriotism. He was a friend you always wanted and a mentor you waited your entire life to meet.

Rich passed away nine years ago today.

RSS Transformer

January 28th, 2009

This program takes a RSS feed either from a file or a URL, applies a stylesheet (either file or URL) to it and produces html for viewing with a browser. I compiled and ran an example on my mac - see the html attachment below.

There are three parameters:

  1. xml - may be file or url
  2. xsl - may be file or url
  3. html - file that the transformer puts results

There are hundreds of RSS publishers. From CNN to Reuters to NBC to NPR and everything in between. Google ‘RSS News’ and you will see what I mean.

I apologize for the plain presentation. When time permits, I will add styles (css) to the xsl to shine it up for acceptable presentation.

As a quick note, I use this a lot to test xsl before I move them to my J2EE container. Moving them to the container may take up to 15 minutes at my site. It may not sound much, but in general you may have to make several rounds of changes (i.e. debug) before the xsl is correct. So this is a huge savings as the utility runs in less than three seconds. Why not let the browser transform the xsl? You’d be surprised how different the browser transformers are compared to the java one. Just as a side note, I used this utility today several times as I was testing a new xsl. This is a great utility!

Examples:

NPR Topics: News
java Rss http://www.npr.org/rss/rss.php?id=1001 http://csatechconsulting.com/attachments/055_Rss.xsl Rss.html
Reuters: Top News
jara Rss http://feeds.reuters.com/reuters/topNews http://csatechconsulting.com/attachments/055_Rss.xsl Rss.html

BBC Front Page:
java Rss http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml http://csatechconsulting.com/attachments/055_Rss.xsl Rss.html

RSS Tracking FedEx Package:
java Rss http://www.simpletracking.com/RSSTracking.aspx?TrackingNumber=979887377090 http://csatechconsulting.com/attachments/055_Rss.xsl Rss.html

Rss.java

import java.io.*; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import javax.xml.transform.TransformerException; public class Rss { public static void Rss (String xml, String xsl, String out){ try{ Source xmlSource = new StreamSource(xml); Source xslSource = new StreamSource(xsl); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(xslSource); FileOutputStream file = new FileOutputStream(out); transformer.transform(xmlSource, new StreamResult(file)); } catch (TransformerException e){ System.out.println("Transformer error:" + e.getCause()); } catch (Exception e){ System.out.println("Error:" + e.getCause()); } } public static void main(String[] args){ String xml = args[0]; // xml file or url String xsl = args[1]; // xsl file or url String output = args[2]; // html output file Rss(xml, xsl, output); } }

XSL:
http://csatechconsulting.com/attachments/055_Rss.xsl

Output (from Rss.java):
http://csatechconsulting.com/attachments/055_Rss.html

Utility that Finds and Replaces String In File

January 25th, 2009

This is a handy utility that finds and replaces a text string in one or more files using Perl regular expression.

I frequently use this to globally change text when I have many files that I need to change. Not long ago, I had 38 xsl attachments that I had to change because the path to my css changed. All the reorganizations are insane! Next change is to store the css as an Oracle artifact. Anyway,  I have half of my object in a weblogic container, but I decided to change those manually. Since the attachments are stored in Oracle as Blobs, I used my Download java program to extract the attachments to disk. Then I used this utility to change the 38 files to the new css file path. Then I used my Upload java program to load them from disk back to the Oracle Blob. This literally took 20 minutes to do, and since I did not have to rely on manually (i.e. fat fingering) doing the changes, there were no runs, no drips, and more importantly no errors!

You may ask why I did not use this method for the files in the container. There are approximately 200 files in the container. In case the pooch was injured (i.e. I screwed up), I have backups, for sure, but said backups are not easily obtained. How difficult you ask. Jumping through fire hoops after skinny dipping in a gasoline bubble bath comes to mind. I would not go so far as to say that I was concerned about the possibility of doing extra work, although the thought did cross my mind, but I really dislike fire and I absolutely dislike the backup custodian, and did not want to take a chance dealing with either.

Example:

Windows: perl -pi.bak -e “s/old-css-path/new-css-path/g” 1.xsl 2.xsl 3.xsl

Mac: perl -pi.bak -e ’s/old-css-path/new-css-path/g’ *.xsl

The ‘g’ modifier (at the end of the expression) will replace all occurrences in the file. Omitting the ‘g’ will only change the first occurrence. Include the ‘i’ modifier will do case-insensitive matching (find).

The above example (windows version) changes three files; 1.xsl, 2.xsl, 3.xsl in the current directory,  make a backups copy (i.e. 1.xsl.bak) of each file, and changes the string ‘old-css-path’ to ‘new-css-path’ if applicable.

Note: I could not get the wildcard ‘*’ to work in the windows environment. It seems to me that ‘*.xsl’ should work, but no such luck. You can stack them up as shown. Oh well, Windows lovers; you’re out of luck. It worked as advertised on my iMac running OS X . Go figure. Also, note that I have to use double quotes around the expression in windows. I received errors otherwise.

switches:
‘p’ - loops over code segment

‘i’ - specifies edit in place, including extension will make backup of file before changing

‘e’ - used to enter one or more lines of script in command line