raga menon

Greenhorn
+ Follow
since May 08, 2007
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by raga menon

Hi all,

i have to search the entry and display the enties. here i used the search
filter for that, when i try to compile the program am getting the error.
ERROR:

Search.printSearchEnumeration(answer);
here

code:
--------------------------------------
import javax.naming.*;
import javax.naming.directory.*;

import java.util.Hashtable;

/**
* Demonstrates how to perform a search by specifying a search filter
* and default search controls. Functionally identical to SearchRetAll.java.
*
* usage: java SearchWithFilterRetAll
*/
class SearchWithFilter
{
public static void main(String[] args) {

// Set up the environment for creating the initial context
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:2389/dc=example,dc=com");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
env.put(Context.SECURITY_CREDENTIALS, "secret");

try {
// Create initial context
DirContext ctx = new InitialDirContext(env);

// Create default search controls
SearchControls ctls = new SearchControls();

// Specify the search filter to match
// Ask for objects with attribute sn == Geisel and which have
// the "mail" attribute.
String filter = "(uid=user.10)";

// Search for objects using filter
NamingEnumeration answer = ctx.search("ou=People", filter, ctls);

// Print the answer
search.printSearchEnumeration(answer);

// Close the context when we're done
ctx.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
============================================

how could i achive this..

bye..
Raga
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 used 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
15 years ago
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
15 years ago
Hi Nathan,

Thanks for your reply.

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

please let me know how to do this

Thanks,

Raga Menon
15 years ago
Hi Nathan,

Thanks for your reply.

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

please let me know how to do this

Thanks,

Raga Menon
15 years ago
Hi Nathan,

Thanks for the reply.

I could actually read my ldif file using FileReader and I could also display the contents from the file using StringTokenizer() etc...

Now I have the following problem.

I could not display the ldif as a tree...

for eg. for the following LDIF,

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

i need to get the follwoing format.
under
dc=foo, dc=bar
|
ou=services,
|
ou=aaa
|
ou=users
ou=clinets
ou=servers

please let me know how i could achieve this.

Thanks,
Raga Menon
15 years ago
Hi,
In this program i used trees, to display ldif file.. and all the dn's and their properties are displaying but my need is if i click on Nodes then the properties of that node will be displayed seperately ie; the frame had to divided in to two halfs..the properties are displayed in second half

please help me if anyone knows..
--------------------------------------------------------------



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");

//FileReader 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(currentChild);
}
// else if (line.startsWith("-") || line.length() < 1)
// { // skip it
//} else
{
// 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();
}
}
15 years ago
Hi,

In the below program LDIF contents are mentioned in the program, but i read

the contents from a file using file reader and then it display in a Tree..

if any one knows send me reply its very urgent.. Please..


--------------------------------------------------------------------



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;
public class LDIFTree{
private static final String INPUT = "dn: CN=John Smith,OU=Legal,DC=example,DC=com\n" +
"changetype: modify\n" +
"replace:employeeID\n" +
"employeeID: 1234\n" +
"-\n" +
"replace:employeeNumber\n" +
"employeeNumber: 98722\n" +
"-\n" +
"replace: extensionAttribute6\n" +
"extensionAttribute6: JSmith98\n" +
"-\n" +
"\n" +
"dn: CN=Jane Smith,OU=Accounting,DC=example,DC=com\n" +
"changetype: modify\n" +
"replace:employeeID\n" +
"employeeID: 5678\n" +
"-\n" +
"replace:employeeNumber\n" +
"employeeNumber: 76543\n" +
"-\n" +
"replace: extensionAttribute6\n" +
"extensionAttribute6: JSmith14\n" +
"-";
public LDIFTree() {
JFrame f = new JFrame("LDIFTree");
BufferedReader reader = new BufferedReader(new StringReader(INPUT));
JTree tree = new JTree(new DefaultTreeModel(buildModel(reader)));
f.getContentPane().add(new JScrollPane(tree));
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300, 600);
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(currentChild);
}
else if (line.startsWith("-") || line.length() < 1)
{ // skip it
} else
{
// 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)
{
new LDIFTree();
}
}














----------------------
Thanks,
Raga
15 years ago