Hello,
I am trying to parse the XML files that the user selects(XML files are
on anoher OS400 system called "wkdis3"). But i am permenantly getting
that error:
Directory0: \\wkdis3\ROOT\h ome
Canonicalpath-Directory4: \\wkdis3\ROOT\h ome\bwe\
You selected the file named AAA.XML
getXmlAlgorithm Document(): IOException Not logged in
sun.net.ftp.Ftp LoginException: Not logged in
at sun.net.ftp.Ftp Client.readRepl y(Unknown Source)
at sun.net.ftp.Ftp Client.issueCom mand(Unknown Source)
at sun.net.ftp.Ftp Client.login(Un known Source)
at sun.net.http://www.protocol.ftp.FtpURLConnec...onnect(Unknown Source)
at sun.net.http://www.protocol.ftp.FtpURLConnec...Stream(Unknown
Source)
at org.apache.xerc es.impl.XMLEnti tyManager.setup CurrentEntity(U nknown
Source)
at org.apache.xerc es.impl.XMLVers ionDetector.det ermineDocVersio n(Unknown
Source)
at org.apache.xerc es.parsers.XML1 1Configuration. parse(Unknown Source)
at org.apache.xerc es.parsers.XML1 1Configuration. parse(Unknown Source)
at org.apache.xerc es.parsers.XMLP arser.parse(Unk nown Source)
at org.apache.xerc es.parsers.DOMP arser.parse(Unk nown Source)
at org.apache.xerc es.jaxp.Documen tBuilderImpl.pa rse(Unknown Source)
at javax.xml.parse rs.DocumentBuil der.parse(Unkno wn Source)
at ParseTest.<init >(ParseTest.jav a:110)
at ParseTest.main( ParseTest.java: 221)
Below is my sourcefile ParseTest.java. .Does anyone any idea about how
to fix that IOException with ftp..for validating xerces i had to set
some feautures from an URI. I thought maybe that could be the
reason.Any idea?
import java.io.File;
import java.io.IOExcep tion;
//import java.util.HashM ap;
//import java.util.Map;
import javax.swing.JFi leChooser;
import javax.xml.parse rs.DocumentBuil der;
import javax.xml.parse rs.DocumentBuil derFactory;
import javax.xml.parse rs.ParserConfig urationExceptio n;
//import org.apache.exca libur.source.So urceParameters;
//import org.apache.exca libur.source.So urceResolver;
import org.w3c.dom.Doc ument;
import org.xml.sax.Err orHandler;
import org.xml.sax.SAX Exception;
import org.xml.sax.SAX ParseException;
import com.ibm.as400.a ccess.AS400;
import com.ibm.as400.a ccess.IFSJavaFi le;
import com.ibm.as400.v access.IFSFileS ystemView;
public class ParseTest {
private File file;
public ParseTest(File file)
{
this.file=file;
DocumentBuilder Factory factory =DocumentBuilde rFactory.newIns tance();
//Logging with anonymus user,resolving ftp source
//ftp://user:password@( protected):port/path
/* SourceParameter s params = new SourceParameter s();
params.setParam eter("user", "anonymous" );
params.setParam eter("password" , "");
Map map = new HashMap();
map.put(SourceR esolver.URI_PAR AMETERS, params);
targetSrc = resolver.resolv eURI("http://xml.org/sax/features/validation",
null,map);
*/
// set attributes for validation (including xml schema)
try {
// factory.setAttr ibute(targetSrc , new Boolean(true));
factory.setAttr ibute("http://xml.org/sax/features/validation", new
Boolean(true));
factory.setAttr ibute("http://apache.org/xml/features/validation/schema",
new Boolean(true));
factory.setVali dating(true);
}catch (IllegalArgumen tException e) {
// thrown if the underlying implementation doesn't recognize the
attributes
System.out.prin tln("Underlying implementation doesn't recognize
the attribute.");
System.out.prin tln("getXmlAlgo rithmDocument() :IllegalArgumen tException
" + e.getMessage()+ "\n");
e.printStackTra ce();
//return null;
}
DocumentBuilder builder = null;
Document doc = null;
ErrorHandler errorHandler = new MyErrorHandler( );
try {
// get an instance of a builder
builder = factory.newDocu mentBuilder();
// Register the error handler
builder.setErro rHandler(new MyErrorHandler( ));//If an application
does not register an ErrorHandler, XML parsing errors will go
unreported and bizarre behaviour may result.
}
catch (ParserConfigur ationException e) {
System.out.prin tln("getXmlAlgo rithmDocument() :ParserConfigur ationException
" + e.getMessage()+ "\n");
e.printStackTra ce();
// return null;
}
try {
// parse the algorithm file and get document
doc = builder.parse(f ile);
}
catch (SAXParseExcept ion e) {
System.out.prin tln("\n** Parsing error" + ", line " +
e.getLineNumber ()
+ ", uri " + e.getSystemId() );
System.out.prin tln("getXmlAlgo rithmDocument() : SAXParseExcepti on "
+ e.getMessage()+ "\n");
e.printStackTra ce();
// return null;
}
catch (SAXException e) {
// parser throws SAXException ,If any parse errors occur
System.out.prin tln("getXmlAlgo rithmDocument() : SAXException " +
e.getMessage()+ "\n");
e.printStackTra ce();
// return null;
}
catch (IOException e) {
// parser throws IOException
System.out.prin tln("getXmlAlgo rithmDocument() : IOException " +
e.getMessage()+ "\n");
e.printStackTra ce();
// return null;
}
catch (IllegalArgumen tException e) {
// parser throws IllegalArgument Exception, If the file is null
System.out.prin tln("getXmlAlgo rithmDocument() :
IllegalArgument Exception " +
e.getMessage()+ "\n");
e.printStackTra ce();
// return null;
}
}
public static void main(String[] args) throws IOException {
// Work with /Dir/File.txt on the system wkdis3.
AS400 system = new AS400("wkdis3") ;
IFSJavaFile dir = new IFSJavaFile(sys tem, "//wkdis3/ROOT/home/bwe/");
String directory0 = dir.getParent() ;
System.out.prin tln ("Directory0 : " + directory0);
String directory4=dir. getCanonicalPat h();
System.out.prin tln ("Canonicalp ath-Directory4: " + directory4);
// IFSJavaFile dir = new IFSJavaFile( "\\wkdis3\ROOT\ home\bwe");
JFileChooser chooser = new JFileChooser(di r, new
IFSFileSystemVi ew(system));
Frame parent = new Frame();
int returnVal = chooser.showOpe nDialog(parent) ;
if (returnVal == JFileChooser.AP PROVE_OPTION) {
IFSJavaFile chosenFile =
(IFSJavaFile)(c hooser.getSelec tedFile());
System.out.prin tln("You selected the file named " +
chosenFile.getN ame());
String filename = chosenFile.getN ame();
// XML files are here:("\\wkdis3 \ROOT\home\bwe\ AABB.XML");
//IFSJavaFile file = new IFSJavaFile(sys tem,directory4+ filename);
//File f=file;
File f=new File(directory4 +filename);
ParseTest xIncludeTest = new ParseTest(f);
}
}
}
class MyErrorHandler implements ErrorHandler {
/
public void warning(SAXPars eException exception) throws SAXException
{
System.out.prin tln("**Parsing Warning**\n" +
" Line: " +exception.getL ineNumber() + "\n" +
" URI: " +exception.getS ystemId() + "\n" +
" Message: " +exception.getM essage());
throw new SAXException("W arning encountered");
}
public void error(SAXParseE xception exception) throws SAXException {
System.out.prin tln("**Parsing Error**\n" +
" Line: " +exception.getL ineNumber() + "\n" +
" URI: " +exception.getS ystemId() + "\n" +
" Message: " +exception.getM essage());
throw new SAXException("E rror encountered");
}
public void fatalError(SAXP arseException exception) throws
SAXException {
System.out.prin tln("**Parsing Fatal Error**\n" +
" Line: " +exception.getL ineNumber() + "\n" +
" URI: " +exception.getS ystemId() + "\n" +
" Message: " +exception.getM essage());
throw new SAXException("F atal Error encountered");
}
}