Skip to Content

This is one more use case of automating extracting ESR information via Simple Query. This link has the introduction and this link has a use case to compare map versions between two systems.

Below diagram represents what we intend to do.

Screen Shot 2015-03-26 at 1.05.22 pm.png

Now, let’s look at something more interesting. Here, we need to identify all graphical maps and hence need to scan the source code of the map.


– The information we want is in the third element – aptly named SourceCode .

– So the initial step are the same as in the other two blogs mentioned above .

– Once we get the SourceCode, we need to decode it using base64 decoding.

It could be implemented as :

public static String decode(String _str) {

  byte[] valueDecoded = Base64.decodeBase64(_str);

  return new String(valueDecoded);


– However, one of the most painful part when dealing with decoding files is that specifying the encoding doesn’t really work ( try it 🙂 ). This value is set when JVM initialises and hence we need to hack it to allow it to reset it to use our encoding format.

System.setProperty(“file.encoding”, “Cp1256”);
java.lang.reflect.Field charset = Charset.class
charset.set(null, null);

This is important .

– As we’re going to deal with a lot of information, it’s better to write it to disk. So the zipped file after base 64 decoding is a normal zipped file.


– Unzipping it once, we get the below file.


– and it needs to be unzipped once more before we’re able to scan the source code.


– Unzipping the file  could be implemented as follows:

ZipFile zipFile = new ZipFile(zippedFileOut);

  Enumeration<?> enu = zipFile.entries();

  while (enu.hasMoreElements()) {

  ZipEntry zipEntry = (ZipEntry) enu


  InputStream is = zipFile.getInputStream(zipEntry);

  String fileNameUnZipped = zipEntry


  newFile = new File(unzipDir

  + File.separator

  + fileNameUnZipped);

  FileOutputStream fos = new FileOutputStream(


  byte[] bytes = new byte[1024];

  int length;

  while ((length = >= 0) {

  fos.write(bytes, 0, length);





– The resulting file is still a zipped file and needs to be unzipped again as shown in the above screen-shots.

– Unzip the file and get the source code.

Once we have the source code, we can scan it to check for Value Mapping

FileUtils.readFileToString(newFile1).contains(“ValueMapService”) == true) { ..

– The output will be as in the below image.


This approach can be extended to identify all maps using a Java statement if it needs to be updated.

The github link is here for the source code . Please make sure HtmlUnit, jsoup and Apache POI libraries are added to the project.You can run the source code – just adapt the static variables in the beginning of the file.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply