hi all
i extracted metadata(xml format) and content to my local machine..my task is to read those xml properties and map it to the objects and import them to the repository..following is my code and am getting null pointer exception wen i tried to set the object.plz help me
public class Updating {
public void doImport( String srcFileOrDir, String destFolderPath, IDfSession session,File folder)
throws DfException, ParserConfigurationException, SAXException, IOException
{
IDfClientX clientx = new DfClientX();
IDfImportOperation operation = clientx.getImportOperation();
operation.setSession( session );
IDfFolder folder1 = null;
folder1 = session.getFolderByPath( destFolderPath ); if( folder1 == null ) {
System.out.println("Folder or cabinet " + destFolderPath + " does not exist in the Docbase!");
return;
}
operation.setDestinationFolderId(folder1.getObjectId()); IDfFile myFile = clientx.getFile( srcFileOrDir );
if( myFile.exists() == false ) {
System.out.println("File or directory " + srcFileOrDir + " does not exist in the file system!");
return;
}
IDfImportNode node = (IDfImportNode) operation.add( srcFileOrDir );
operation.execute();
IDfList myNodes = operation.getNodes();
int iCount = myNodes.getCount();
System.out.println("Number of nodes after operation: " + iCount );
for( int i = 0; i < iCount; ++i ) {
IDfImportNode aNode = (IDfImportNode) myNodes.get(0);
IDfSysObject object=aNode.getObject();
// Reading the xml properties
for(File fileEntry:folder.listFiles())
{
if(!fileEntry.isDirectory())
{
System.out.println(fileEntry.getName());
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(fileEntry);
doc.getDocumentElement().normalize();
NodeList nodeLst = doc.getElementsByTagName("object");
for (int k = 0; k < nodeLst.getLength(); k++)
{
Node node1 = nodeLst.item(0);
if (node1.getNodeType() == Node.ELEMENT_NODE)
{
Element eElement = (Element) node1;
if(eElement.hasChildNodes())
{
NodeList nl = node1.getChildNodes();
for(int j=0; j<nl.getLength(); j++)
{
Node nd = nl.item(j);
if(nd.getTextContent()==null)
nd.setTextContent("");
object.save();(showing null pointer exception here)
}
}
else
{
System.out.println("no child nodes");
}
}
else
{
System.out.println("node type not equal to element node");
}
}
}
}
}
}
public static void main(String[] args) {
SampleClass sampleClass=new SampleClass();
Updating updating=new Updating();
File file=new File("c:/documentum/XmlFiles");
try {
updating.doImport("C:/Documentum/ExportFiles/","/Trainee_6/trainee6_begin",sampleClass.createSession(),file);
} catch (DfException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}