Skip to Content

Get List of all Graphical Maps using Value Mapping

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.

/wp-content/uploads/2015/03/5_671810.png

– 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
.getDeclaredField(“defaultCharset”);
charset.setAccessible(true);
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.


/wp-content/uploads/2015/03/8_671812.png


– Unzipping it once, we get the below file.


/wp-content/uploads/2015/03/9_671825.png


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

/wp-content/uploads/2015/03/10_671826.png


– Unzipping the file  could be implemented as follows:


ZipFile zipFile = new ZipFile(zippedFileOut);

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

  while (enu.hasMoreElements()) {

  ZipEntry zipEntry = (ZipEntry) enu

  .nextElement();

  InputStream is = zipFile.getInputStream(zipEntry);

  String fileNameUnZipped = zipEntry

  .getName();

  newFile = new File(unzipDir

  + File.separator

  + fileNameUnZipped);

  FileOutputStream fos = new FileOutputStream(

  newFile);

  byte[] bytes = new byte[1024];

  int length;

  while ((length = is.read(bytes)) >= 0) {

  fos.write(bytes, 0, length);

  }

  is.close();

  fos.close();

  }

– 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.

/wp-content/uploads/2015/03/12_671855.png

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.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.