Hi,
Actually i read the ldif file using the file reader and my need is to
display the LDIF contents in a tree Hierarchy .
In my ldif file each and every dn ends with dc=foo, dc=bar. how could i parse this and make it as Root node and child nodes and properties of each dn is displayed by splitting the frame. in one frame all Root dn, child dn should be display in a tree hierarchy and in another frame if i click on root node the its porperties are displayed on another frame.(properties are createtimestamp, dc,modifiersname etc.. )
for example following is LDIF file :
dn: dc=foo,dc=bar
createTimestamp: 20060530115557.500Z
dc: foo
modifiersName: cn=Directory Manager
creatorsName: cn=Directory Manager
modifyTimestamp: 20060530115557.500Z
objectclass: top
objectclass: domain
dn: ou=services,dc=foo,dc=bar
createTimestamp: 20060530120040.274Z
modifiersName: cn=Directory Manager
modifyTimestamp: 20060530120040.274Z
creatorsName: cn=Directory Manager
ou: services
objectclass: top
objectclass: organizationalunit
dn: ou=aaa,ou=services,dc=foo,dc=bar
createTimestamp: 20060530120053.649Z
modifiersName: cn=Directory Manager
modifyTimestamp: 20060530121725.967Z
creatorsName: cn=Directory Manager
ou: aaa
description: Dialin Services
objectclass: organizationalUnit
dn: ou=clients,ou=aaa,ou=services,dc=foo,dc=bar
createTimestamp: 20060530120103.852Z
modifiersName: cn=Directory Manager
modifyTimestamp: 20060530120103.852Z
creatorsName: cn=Directory Manager
ou: clients
objectclass: organizationalUnit
objectclass: top
dn: ou=servers,ou=aaa,ou=services,dc=foo,dc=bar
createTimestamp: 20060530120103.868Z
modifiersName: cn=Directory Manager
modifyTimestamp: 20060530120103.868Z
creatorsName: cn=Directory Manager
ou: servers
objectclass: organizationalUnit
objectclass: top
dn: ou=users,ou=aaa,ou=services,dc=foo,dc=bar
createTimestamp: 20060530120103.852Z
modifiersName: cn=Directory Manager
modifyTimestamp: 20060530120103.852Z
creatorsName: cn=Directory Manager
ou: users
objectclass: organizationalUnit
objectclass: top
------------------------------------------------
and i need to display the following Tree
dc=foo,dc=bar
|
dn: ou=services,dc=foo,dc=bar
|
dn: ou=aaa,ou=services,dc=foo,dc=bar
|
dn: ou=clients,ou=aaa,ou=services,dc=foo,dc=bar
dn: ou=servers,ou=aaa,ou=services,dc=foo,dc=bar
dn: ou=users,ou=aaa,ou=services,dc=foo,dc=bar
----------------------------------------------
Here is the code i wrote how to modify this
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import javax.swing.JPanel;
import com.sun.org.apache.xpath.internal.patterns.NodeTest;
import javax.swing.*;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.DefaultMutableTreeNode;
import java.io.StringReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.FileReader;
public class LDIFTree
{
public LDIFTree() throws FileNotFoundException
{
FileReader fr;
fr = new FileReader("c://data.ldif");
JFrame f = new JFrame("LDIFTree");
BufferedReader reader = new BufferedReader(fr);
JTree tree = new JTree(new DefaultTreeModel(buildModel(reader)));
f.getContentPane().add(new JScrollPane(tree));
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(400, 400);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
private TreeNode buildModel(BufferedReader reader)
{
DefaultMutableTreeNode root = new DefaultMutableTreeNode("root", true);
DefaultMutableTreeNode currentChild = null;
try
{
String line = reader.readLine();
while(line != null)
{
line = line.trim();
if (line.startsWith("dn"))
{
// add the current dn to the root
currentChild = new DefaultMutableTreeNode(line, true);
//root.add();
root.add(currentChild);
}
{
// add the property to the current dn
DefaultMutableTreeNode propertyNode = new DefaultMutableTreeNode(line, false);
currentChild.add(propertyNode);
}
line = reader.readLine();
}
}
catch (IOException x)
{
x.printStackTrace();
}
return root;
}
public static void main(String[] args) throws FileNotFoundException
{
new LDIFTree();
}
}
--------------------------------------------------
please let me know how to do this
Thanks,
Raga Menon