vidhya subramaniam

Ranch Hand
+ Follow
since Jul 14, 2001
Merit badge: grant badges
For More
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 vidhya subramaniam

I am trying to save incoming files using Javamail attachments.I have a doubt here. For example-say I have 2 files Ar111.xml and Ar22.xml. Ar11.xml seems to have contentType() Text?plain so it saves with the corresponding name, but Ar22.xml seems to have contentType() HTML/Txet. So it saves it with just A.xml. It doesnt take the whole file name into consideration. Can someone pl explain why? and how I should rectify it....

Here is my code below:
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.event.*;
import javax.activation.*;
import java.text.*;
import java.util.Calendar;

public class aiginvoice_1 {
public static void main (String args[])
throws Exception {
String host ="omnimail1.omnifax.xerox.com";
String username ="edi";
String password ="ediedi";

// Get session
Session session = Session.getInstance(
new Properties(), null);

// Get the store
Store store = session.getStore("imap");
store.connect(host,username,password);

// Get folder
Folder folder = store.getFolder("INBOX/AIG/EQ");
folder.open(Folder.READ_ONLY);

BufferedReader reader = new BufferedReader (
new InputStreamReader(System.in));

// Get directory
Message message[] = folder.getMessages();
for (int i = message.length-1,n=message.length;n>i&&i!=-1;i--) {
Date e = message[i].getSentDate();
System.out.println("Message Inbox date :"+e);

Address[] a;
if ((a=message[i].getFrom())!=null) {
for (int j=0;j<a.length;j++)
System.out.println("From : " +a[j].toString());
}
Calendar cal = Calendar.getInstance();
SimpleDateFormat fmt1 = new SimpleDateFormat("yyyy-MM-dd 06:00:00" );
cal.add(Calendar.DATE,-15); //set to 17 days earlier date (15-31)
fmt1.setCalendar(cal); //set to date after 6am
String s2 =fmt1.format(cal.getTime()); //returns yesterday's date in string format
System.out.println("Yesterday's Date in string form before conversion :"+s2 );

SimpleDateFormat fmt2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date d2 = fmt2.parse(s2); //to convert the date in string to date form
System.out.println("Yesterday's date in date type is: "+d2);
if (e.after(d2)) {

Object content = message[i].getContent();
if (content instanceof Multipart) {
System.out.println("Multipart" + i);
if ((a=message[i].getFrom()) !=null) {
for (int j=0;j<a.length;j++) {
System.out.println("From : " +a[j].toString());
String t = ((a[j].toString()).substring(3,13));
String m = "AIG - TEST";
if (t.equals(m)==false)
handleMultipart((Multipart)content);
} //end of for (int j=0)
} //end of if(a=msg[i])
}
else {
System.out.println("ElseMultipart" + i);
handlePart(message[i]);
}
} // end of (if e.after d2)
else
System.out.println("Old message");
} // end of for loop
// Close connection
folder.close(false);
store.close();
} // end of main
public static void handleMultipart(Multipart multipart)
throws MessagingException, IOException {
for (int i=0, n=multipart.getCount(); i<n; i++) {
handlePart(multipart.getBodyPart(i));
}
} //end of handleMulitipart()

public static void handlePart(Part part)
throws MessagingException, IOException {
String disposition = part.getDisposition();
String contentType = part.getContentType();
if (disposition == null) { // When just body
System.out.println("Null: " + contentType);
// Check if plain
/* if ((contentType.length() >= 10) &&
(contentType.toLowerCase().substring(
0, 10).equals("text/plain"))) {
part.writeTo(System.out);
} else { // Don't think this will happen
System.out.println("Other body: " + contentType);
part.writeTo(System.out);
}*/
} //end of if null
else if (disposition.equalsIgnoreCase(Part.ATTACHMENT)) {
System.out.println("Attachment VS: " + part.getFileName() +
" : " + contentType);
saveFile(part.getFileName(), part.getInputStream());

} else if (disposition.equalsIgnoreCase(Part.INLINE)) {
System.out.println("Inline: " +
part.getFileName() +
" : " + contentType);
} else { // Should never happen
System.out.println("Other: " + disposition);
}
} // end of handlePart()

public static void saveFile(String filename,
InputStream input) {

System.out.println(filename);
try{
if (filename == null) {
filename = File.createTempFile("VSX", ".out").getName();
}
// Do no overwrite existing file
filename = "/work/vsubra/edi/saxon/" + filename;
File file = new File(filename);
for (int i=0; file.exists(); i++) {
file = new File(filename+i);
}
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);

BufferedInputStream bis = new BufferedInputStream(input);
int aByte;
while ((aByte = bis.read()) != -1) {
bos.write(aByte);
}
bos.write(10);
// bos.flush();
bos.close();
// bis.close();
} // end of try()
catch(IOException exp){
System.out.println("IOException:" + exp);
}
} //end of saveFile()
}//end of class aiginvoice_test


Thanks,
Vidhya
19 years ago
I am using javamail to save attachments in incoming messages. My code is pasted below. While saving it picks only the first character from the file and saves it with that name. It doesnt pick the whole file name. How do i use it to name the file as the name in my attachments.
here is my code:
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.event.*;
import javax.activation.*;
import java.text.*;
import java.util.Calendar;
public class aiginvoice_1 {
public static void main (String args[])
throws Exception {
String host ="omnimail1.omnifax.xerox.com";
String username ="edi";
String password ="ediedi";
// Get session
Session session = Session.getInstance(
new Properties(), null);
// Get the store
Store store = session.getStore("imap");
store.connect(host,username,password);
// Get folder
Folder folder = store.getFolder("INBOX/AIG/EQ");
folder.open(Folder.READ_ONLY);
BufferedReader reader = new BufferedReader (
new InputStreamReader(System.in));
// Get directory
Message message[] = folder.getMessages();
for (int i = message.length-1,n=message.length;n>i&&i!=-1;i--) {
Date e = message[i].getSentDate();
System.out.println("Message Inbox date :"+e);

Address[] a;
if ((a=message[i].getFrom())!=null) {
for (int j=0;j<a.length;j++)
System.out.println("From : " +a[j].toString());
}
Calendar cal = Calendar.getInstance();
SimpleDateFormat fmt1 = new SimpleDateFormat("yyyy-MM-dd 06:00:00" );
cal.add(Calendar.DATE,-15); //set to 17 days earlier date (15-31)
fmt1.setCalendar(cal); //set to date after 6am
String s2 =fmt1.format(cal.getTime()); //returns yesterday's date in string format
System.out.println("Yesterday's Date in string form before conversion :"+s2 );
SimpleDateFormat fmt2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date d2 = fmt2.parse(s2); //to convert the date in string to date form
System.out.println("Yesterday's date in date type is: "+d2);
if (e.after(d2)) {

Object content = message[i].getContent();
if (content instanceof Multipart) {
System.out.println("Multipart" + i);
if ((a=message[i].getFrom()) !=null) {
for (int j=0;j<a.length;j++) {
System.out.println("From : " +a[j].toString());
String t = ((a[j].toString()).substring(3,13));
String m = "AIG - TEST";
if (t.equals(m)==false)
handleMultipart((Multipart)content);
} //end of for (int j=0)
} //end of if(a=msg[i])
}
else {
System.out.println("ElseMultipart" + i);
handlePart(message[i]);
}
} // end of (if e.after d2)
else
System.out.println("Old message");
} // end of for loop
// Close connection
folder.close(false);
store.close();
} // end of main
public static void handleMultipart(Multipart multipart)
throws MessagingException, IOException {
for (int i=0, n=multipart.getCount(); i<n; i++) {
handlePart(multipart.getBodyPart(i));
}
} //end of handleMulitipart()

public static void handlePart(Part part)
throws MessagingException, IOException {
String disposition = part.getDisposition();
String contentType = part.getContentType();
if (disposition == null) { // When just body
System.out.println("Null: " + contentType);
// Check if plain
/* if ((contentType.length() >= 10) &&
(contentType.toLowerCase().substring(
0, 10).equals("text/plain"))) {
part.writeTo(System.out);
} else { // Don't think this will happen
System.out.println("Other body: " + contentType);
part.writeTo(System.out);
}*/
} //end of if null
else if (disposition.equalsIgnoreCase(Part.ATTACHMENT)) {
System.out.println("Attachment VS: " + part.getFileName() +
" : " + contentType);
saveFile(part.getFileName(), part.getInputStream());

} else if (disposition.equalsIgnoreCase(Part.INLINE)) {
System.out.println("Inline: " +
part.getFileName() +
" : " + contentType);
} else { // Should never happen
System.out.println("Other: " + disposition);
}
} // end of handlePart()

public static void saveFile(String filename,
InputStream input) {
System.out.println(filename);
try{
if (filename == null) {
filename = File.createTempFile("VSX", ".out").getName();
}
// Do no overwrite existing file
filename = "/work/vsubra/edi/saxon/" + filename;
File file = new File(filename);
for (int i=0; file.exists(); i++) {
file = new File(filename+i);
}
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
BufferedInputStream bis = new BufferedInputStream(input);
int aByte;
while ((aByte = bis.read()) != -1) {
bos.write(aByte);
}
bos.write(10);
// bos.flush();
bos.close();
// bis.close();
} // end of try()
catch(IOException exp){
System.out.println("IOException:" + exp);
}
} //end of saveFile()
}//end of class aigemail

Please advise...
Vidhya
19 years ago
i have used javamail code to retrieve email attachments and save them . It was working fine. The body of the email used to be plain text and it would have html and xml attachments. It would save the attachments with the same name as the attachment .
But now they have changed the body of email as html and my code has stopped working.It does save the attachment but saves it as A0, A1, A2, etc etc instead ofactual name of the attachment. Why should my code stop as it has to just save the email attachment irrespective of the body. Can someone please help out?
Here is my code
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.event.*;
import javax.activation.*;
import java.text.*;
import java.util.Calendar;
public class test {
public static void main (String args[])
throws Exception {
String host ="omnimail1.omnifax.xerox.com";
String username ="vsubramaniam";
String password ="welcome1";
// Get session
Session session = Session.getInstance(
new Properties(), null);
// Get the store
Store store = session.getStore("imap");
store.connect(host,username,password);
// Get folder
Folder folder = store.getFolder("INBOX/test");
folder.open(Folder.READ_ONLY);

BufferedReader reader = new BufferedReader (
new InputStreamReader(System.in));

// Get directory
Message message[] = folder.getMessages();
for (int i = message.length-1,n=message.length;n>i&&i!=-1;i--) {
Date e = message[i].getSentDate();
System.out.println("Message Inbox date :"+e);

Address[] a;
if ((a=message[i].getFrom())!=null) {
for (int j=0;j<a.length;j++)
System.out.println("From : " +a[j].toString());
}
Calendar cal = Calendar.getInstance();
SimpleDateFormat fmt1 = new SimpleDateFormat("yyyy-MM-dd 06:00:00"
);
cal.add(Calendar.DATE,-4); //set to 17 days earlier date (15-31)
fmt1.setCalendar(cal); //set to date after 6am
String s2 =fmt1.format(cal.getTime()); //returns yesterday's date
in string format
System.out.println("Yesterday's Date in string form before conversion :"+
); */

SimpleDateFormat fmt2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date d2 = fmt2.parse(s2); //to convert the date in string to date form
System.out.println("Yesterday's date in date type is: "+d2); */
f (e.after(d2)) {

Object content = message[i].getContent();
if (content instanceof Multipart) {
System.out.println("Multipart" + i);
if ((a=message[i].getFrom()) !=null) {
for (int j=0;j<a.length;j++) {
System.out.println("From : " +a[j].toString());
String t = ((a[j].toString()).substring(3,13));
String m = "AIG - TEST";
if (t.equals(m)==false)
handleMultipart((Multipart)content);
} //end of for (int j=0)
} //end of if(a=msg[i])
}
else {
System.out.println("ElseMultipart" + i);
handlePart(message[i]);
}
} // end of (if e.after d2)
else
System.out.println("Old message");
} // end of for loop
// Close connection
folder.close(false);
store.close();
} // end of main
public static void handleMultipart(Multipart multipart)
throws MessagingException, IOException {
for (int i=0, n=multipart.getCount(); i<n; i++) {
handlePart(multipart.getBodyPart(i));
}
} //end of handleMulitipart()

public static void handlePart(Part part)
throws MessagingException, IOException {
String disposition = part.getDisposition();
String contentType = part.getContentType();
if (disposition == null) { // When just body
System.out.println("Null: " + contentType);
// Check if plain
/* if ((contentType.length() >= 10) &&
(contentType.toLowerCase().substring(
0, 10).equals("text/plain"))) {
part.writeTo(System.out);
} else { // Don't think this will happen
System.out.println("Other body: " + contentType);
part.writeTo(System.out);
}*/
} //end of if null
else if (disposition.equalsIgnoreCase(Part.ATTACHMENT)) {
System.out.println("Attachment VS: " + part.getFileName() +
" : " + contentType);
saveFile(part.getFileName(), part.getInputStream());

} else if (disposition.equalsIgnoreCase(Part.INLINE)) {
System.out.println("Inline: " +
part.getFileName() +
" : " + contentType);
} else { // Should never happen
System.out.println("Other: " + disposition);
}
} // end of handlePart()

public static void saveFile(String filename,
InputStream input) {

System.out.println(filename);
try{
if (filename == null) {
filename = File.createTempFile("VSX", ".out").getName();
}
// Do no overwrite existing file
filename = "/work/vsubra/edi/saxon/" + filename;
File file = new File(filename);
for (int i=0; file.exists(); i++) {
file = new File(filename+i);
}
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);

BufferedInputStream bis = new BufferedInputStream(input);
int aByte;
while ((aByte = bis.read()) != -1) {
bos.write(aByte);
}
bos.write(10);
// bos.flush();
bos.close();
// bis.close();
} // end of try()
catch(IOException exp){
System.out.println("IOException:" + exp);
}
} //end of saveFile()
}//end of class test

Thanks,
Vidhya
19 years ago
I have written a shell program that automatically loads xml data into oracle tables.
Here is the code:
cd /work/vsubra/edi/saxon
x=`ls *.xml`
echo $x
for file in ${x}
do
cat ${file} | sed 's$http://xml.cxml.org/schemas/cXML/1.2.007/cXML.dtd$/work/v
subra/edi/cXML007.dtd$g'>${file}.xml
mv ${file}.xml ${file}
echo ${file}
done
z=`ls *.xml`
for xmlfilename in ${z}
do
java com.icl.saxon.StyleSheet /work/vsubra/edi/saxon/${xmlfilename} /work/vsub
ra/edi/saxon/ariba.xsl>/work/vsubra/edi/saxon/${xmlfilename}.xml
a=$?
if [ "$a" -ne "0" ]
then
echo "Error(s) in transforming the file ${xmlfilename}"
mv -f ${xmlfilename} /work/vsubra/edi/error_files/${xmlfilename}
else
echo "Successful transformation of file ${xmlfilename}"
mv -f ${xmlfilename} /work/vsubra/edi/trans_files/${xmlfilename}
echo "Successful in moving the file ${xmlfilename}"
y=`ls *.xml`
for filename in ${y}
do
BKUP_FILE=${filename}`date +%m%d%y%H%M%S`.bkup
echo $BKUP_FILE
mv -f ${filename} /work/vsubra/edi/data/trial1.txt
echo "moved ${filename} to trial1.txt"
sqlldr userid="apps/apps" control="/work/vsubra/edi/control/xmlload.ctl"
b = $?
if [ "$b" -ne "0" ]
then
echo "Error(s), moving the ${filename} into the table omni_xmlfile"
else
echo "Completed moving the ${filename} into the table omni_xmlfile"
fi
mv -f /work/vsubra/edi/data/trial1.txt /work/vsubra/edi/backup/${BKUP_FILE}
c = $?
if [ "$c" -ne "0" ]
then
echo "Error(s), moving the ${filename} into the Backup"
exit
else
echo "Completed moving the ${filename} into the Backup"
fi
print "exec omni_loaddata" | sqlplus -s "apps/apps@nwpprd"
s = $?
if [ "$s" -ne "0" ]
then
echo "Error in loading into the temp table "
else
echo "Successful in loading into the temp table"
fi
done
fi
done
exit

But when I run it it gives me the folllowing error
ORA-29532: Java call terminated by uncaught Java exception:
oracle.xml.sql.OracleXMLSQLException: Start of root element expected.
ORA-06512: at "SYS.DBMS_XMLSAVE", line 91
ORA-06512: at "APPS.ARIBA_TEST_DATA", line 7
ORA-06512: at "APPS.OMNI_LOADDATA", line 16
ORA-06512: at line 1

Can someone explain what error this is and how can I correct it.
Thanks,
Vidhya
Roseanne,
When i open the file in IE5.5 or higher , it doesnt give me any error. I tried to open it with a text editor and compare it with files that were working fine without any error , i found that there were some extra spaces between feww lines (may be 1 enter). is that the problem, because when i rmoved those extra spaces and save it it works fine. So how can i fix this error? ( kind of some script or something)
Thanks,
Vidhya
I have an xml file called AR1048615.xml. I am trying to transform it using saxon. But during the transformation, it fails and gives me the following error:
Fatal error reported by XML parser: premature end of file (found "[EOF]")
URL: file:/work/vsubra/edi/saxon/AR1048615.xml
Line: 123
Column: 0
Error
premature end of file (found "[EOF]"): premature end of file (found "[EOF]")
Transformation failed
Error(s) in transforming the file AR1048615.xml
Line 123 is nothing but the last line /cxml
where the file is closed.
I dont see anything wrong in the xmlfile. How can I fix this
Thanks,
Vidhya
I have an xml file called AR1048615.xml. I am trying to transform it using saxon. But during the transformation, it fails and gives me the following error:
Fatal error reported by XML parser: premature end of file (found "[EOF]")
URL: file:/work/vsubra/edi/saxon/AR1048615.xml
Line: 123
Column: 0
Error
premature end of file (found "[EOF]"): premature end of file (found "[EOF]")
Transformation failed
Error(s) in transforming the file AR1048615.xml
Line 123 is nothing but the last line /cxml
where the file is closed.
I dont see anything wrong in the xmlfile. How can I fix this
Thanks,
Vidhya
Thanks,
Balaji... it worked.
21 years ago
Can you be more specific. My class path is set as
/work/vsubra. I i go to test dir within this dir and run java aigemail, it runs fine but i want to run from my home dir ie /work/vsubra
I tried giving
java -classpath /work/vsubra:/work/vsubra/test aigemail
but still it gives me runtime error.
21 years ago
I think you have mistaken me wrong. This file aigemail.java is in the directory /work/vsubra/test. I would like to execute it from anywhere, so if i have to do that then i will have to specify the full path where the file is. if i give
java /work/vsubra/test aigemail
it gives me an error
Exception in thread main no class found: /work/vsubra/test.
how can i fix this ?
Thanks,
Vidhya
21 years ago
i am in my /work/vsubra/test directory and i have a file here as aigemail.java
Now when i run the javac and java command from this dir everything runs okay.
if i try to run the java command as
java /work/vsubra/test/aigemail then it throws error:
Exception in thread main "no class defn found"
why does it give me error when i try the wholepath.
what is an option if i want to give the whole path?
thanks
21 years ago
I have one date as
String s = message[i].getSentDate().toString()
and another one is
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE,-1);
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd 'at' 14:00:00");
fmt.format(cal.getTime());
I want to put fmt.format(cal.getTime()) in a variable and compare it with s. I would like to know if the date is less or greater than the other.
Whats the best way to do it
Thanks,
Vidhya
21 years ago
thanks, that worked.
21 years ago
I have the following script:
Calendar c = Calendar.getInstance();
int a = c.get(Calendar.MONTH);
System.out.println(a);
System.out.println(c.getTime());
//GregorianCalendar cal = new GregorianCalendar();
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-mm-dd");
fmt.setCalendar(c);
System.out.println(fmt.format(c.getTime()));
c.roll(Calendar.DATE,false);
fmt.setCalendar(c);
System.out.println(fmt.format(c.getTime()));
This gives me the the following output
2003-22-29
2003-22-28
This gives the date and year right but every time i run the program the month always changes. It never gives me 2003-00-28 which it should as its 00 for January.
Can anyone tell me what I am missing?
Thanks,
Vidhya
21 years ago
import java.util.Calendar;
import java.util.Properties;
public class datecalc {
public static void main(String args[]){
Calendar rightNow = Calendar.getInstance();
int julianDay = rightNow.get(Calendar.DAY_OF_YEAR);
System.out.println(julianDay);
int day = rightNow.get(Calendar.DATE);

// Create a copy of the rightNow Calendar object
Calendar baseCal = (Calendar)rightNow.clone();
// Subtract 5 days from the date
int i =rightNow.add(Calendar.DATE, -5);
System.out.println(i);

When I do this i get an error on i as incompatible datatypes.
which datatype does add(Calendar.DATE) return?
21 years ago