Skip to main content

ATG Search and how to generate XHTMLs from STG file


The ATG search  indexing will give you the idx and stg files. When I analyse the stg files with some text editors like Textpad or Ultraedit , found some <html> and </html> tags and the contents inside these tags seems to be the same content of the temporary XHTML files , which will be generated during the search indexing for each indexed item. So I deicded to take the contents in between the <html> and </html> tags and save as XHTML file and it works for almost all indexed items. As you might know, these XHTML file’s <head> tag contains all the meta properties ( refine properties ) and the <body> tag have the text properties ( searchable properties ) for each indexed item.

Please note that the above steps are not an ATG recommended method to generate the XHTML files. I come across to this simple method to form the XHTML files and I am not 100% sure that this will give all the XHTML files of a search index . But I found this to be very useful for debugging any ATG search related issues.

Please find the below JAVA code written to genrate the XHTML files from an stg file. The main method is expecting the name of the stg file as a program argument. This will create a folder named “XHTML_Files” in the current directory and will save the XHTML files inside this folder.

Please find the below screen shot of XHTML files generated using this JAVA code :




Please find the below screen shot of a sample XHTML file generated using this JAVA code :





import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

public class ATGSearchStgXHTMLGenerator {
public static void main(String args[]) {
try {
String fileName =  args[0];
String xhtmlfilePath = ".\\XHTML_Files";
if(fileName ==  null){
System.out.println("Give the stg file name as input");
return;
}
File stgfile = new File(fileName);
FileReader stgfileFis = new FileReader(stgfile);
BufferedReader stgfileBr = new BufferedReader(stgfileFis);
String readLine = stgfileBr.readLine();
String outToWrite = null;
String outFileName = null;
File outFile = new File(xhtmlfilePath);
boolean exists = outFile.exists();
if(!exists){
(new File(xhtmlfilePath)).mkdir();
}
FileWriter outFileWriter = null;
int lineNumber = 1;
int xhtmlFileCount = 1;
boolean canWriteXhtmlfile = false;
do {
if(readLine.contains("<html>")
&& readLine.contains("</html>")){
outToWrite = readLine.substring(readLine.indexOf("<html>"),readLine.indexOf("</html>")+7);
outFileName = "\\XHTMLFile_";
canWriteXhtmlfile = true;
}else if(readLine.contains("<html>")
&& !readLine.contains("</html>")){
System.out.println("In the STG file at lineNumber:" +lineNumber+" ERROR: html tag found, but no end tag for");
outToWrite = readLine.substring(readLine.indexOf("<html>"),readLine.length());
outFileName = "\\XHTMLFile_Error_";
canWriteXhtmlfile = true;
}
if(canWriteXhtmlfile){
outFile =  new File(xhtmlfilePath+outFileName+(xhtmlFileCount++)+".xhtml");
outFileWriter =  new FileWriter(outFile);
outFileWriter.write(outToWrite);
outFileWriter.close();
}
readLine = stgfileBr.readLine();
lineNumber++;
canWriteXhtmlfile = false;
} while (readLine != null);
System.out.println("The STG file is processed fully till lineNumber"+lineNumber);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Comments

Popular posts from this blog

Google Chrome shortcut keys

If you are a Google Chromey guy, please find below the list of shortcut keys for some of the most used features  :-) Find more shortcut keys @  http://www.google.com/support/chrome/bin/static.py?page=guide.cs&guide=25799&topic=28650

How to convert your Blogger Blog to PDF ?

You can use a website called "blogbooker" @  http://www.blogbooker.com/blogger.php   to convert your Blogger Blog to a PDF . Please find the steps below : 1. Save your blog as an xml using Blogger Settings - Other - Export Blog option 2. Go to the website " http://www.blogbooker.com/blogger.php " and select this XML , give your blog address and select the options like date range, page size, font, ... 3. Click the  "Create Your BlogBook" button to view and save your blog as PDF

ATG - how to create and deploy a new atg module

ATG products are packaged as a number of separate application modules. Application modules exist in the ATG installation as a set of directories defined by a manifest file. To create a new module, follow the below steps : Create a module directory within your ATG installation.  Create a META-INF directory within the module directory. Note that this directory must be named META-INF.  Create a manifest file named MANIFEST.MF and include it in the META-INF directory for the module. The manifest contains the meta-data describing the module. A module located at <ATG2007.1dir>/MyModule is named MyModule and a module located at <ATG2007.1dir>/CustomModules/MyModule is named CustomModules.MyModule. Within the subdirectory that holds the module, any number of files may reside in any desired order. These files are the module resources (EAR files for J2EE applications, WAR files for web applications, EJB-JAR files for Enterprise JavaBeans, JAR files of Java classes, platform-d

Eclipse plug-in to create Class and Sequence diagrams

ModelGoon is an Eclipse plug-in avaiable for UML diagram generation from Java code. It can be used to generate Package Dependencies Diagram, Class Diagram, Interaction Diagram and Sequence Diagram. You coud get it from http://marketplace.eclipse.org/content/modelgoon-uml4java Read more about it and see some vedios about how to create the class and sequence diagram @ http://www.modelgoon.org/?tag=eclipse-plugin Find some snapshots below which gives an idea about the diagram generation.

Good features of Eclipse 3.6 (Eclipse Helios) JDT

Read the Eclipse Galileo features @  http://tips4ufromsony.blogspot.com/2011/10/good-features-of-eclipse35-eclipse.html New options in Open Resource dialog : The Open Resource dialog supports three new features: • Path patterns: If the pattern contains a /, the part before the last / is used to match a path in the workspace: • Relative paths: For example, "./T" matches all files starting with T in the folder of the active editor or selection: • Closer items on top: If the pattern matches many files with the same name, the files that are closer to the currently edited or selected resource are shown on top of the matching items list. MarketPlace :  Searching and adding new plugins for Eclipse have always been a challenge. The Eclipse Marketplace makes this much easier – it allows you to not only search a central location of all Eclipse plugins, but also allows you to find the most recent and the most popular plugins. Fix multiple proble