转自:leo blogshark-xpdl文件的打开
这一部分有两个接口比较重要org.enhydra.shark.api.client.wfservice.RepositoryMgrorg.enhydra.shark.xpdl.XMLInterface其中XMLInterface主要是对xpdl文件中包的操作,并作解析工作,如Package openPackage(packagePath,isFromStram) xpdl文件打开过程首先上传文件(在shark的客户端代码中--UploadPackage的action中)
try {
File pkgFile=new File(pkgToUpload)
RandomAccessFile raf=new RandomAccessFile(pkgFile,"r");
byte[] utf8Bytes=null;
long noOfBytes=raf.length();
if (noOfBytes>0) {
utf8Bytes=new byte[(int)noOfBytes];
raf.seek(0);
raf.readFully(utf8Bytes);
}
if (utf8Bytes!=null) {
String rPath=uprp.getRelativeFilePath();//获得该文件的相对路径
SharkAdmin.getRepositoryManager().uploadPackage(utf8Bytes,rPath);//代表xpdl文件的byte[],xpdl文件的相对路径
} }
} catch (RepositoryInvalid ri) {
} 2.调用RepositoryMgr接口的uploadPackage(byte[],String)String path=SharkUtilities.EXTERNAL_PACKAGES_REPOSITORY+File.separator+relativePath; XMLInterface xpdlManager=new XMLInterfaceForJDK13();
Package updatedPkg=xpdlManager.openPackage(path,false);//false代表从文件中读取 3.调用XMLInterface的openPackage(path,false),返回代表elements的Package对象真正的解析xml文件也是在这里执行的openPackage(){ Package pkg=openDocument(pkgReference,openFromStream,handleExternalPackages);//打开xpdl文件,并解析,返回Package对象
}4.调用XMLInterface的parseDocument()进行解析,最关键的地方openDocument(){ if (!openFromStream) {
pkg=parseDocument(pkgReference,true);//
} } public Package parseDocument (String toParse,boolean isFile) {
Package pkg=null;
// Create a Xerces DOM Parser
DOMParser parser = new DOMParser(); // Parse the Document and traverse the DOM
try {
parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error",true);
ParsingErrors pErrors=new ParsingErrors();
parser.setErrorHandler(pErrors);
if (isValidationON) {
parser.setEntityResolver(new XPDLEntityResolver());
parser.setFeature("http://xml.org/sax/features/validation",true);
parser.setFeature("http://apache.org/xml/features/validation/schema",true);
//parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",true);
}
if (isFile) {
//System.out.println("Parsing from file");
//parser.parse(toParse);
File f=new File(toParse);
if (!f.exists()) {
f=new File(f.getCanonicalPath());
}
parser.parse(new InputSource(new FileInputStream(f))); // Fixed by Harald Meister
} else {
//System.out.println("Parsing from stream");
parser.parse(new InputSource(new StringReader(toParse)));
}
Document document = parser.getDocument();
Set errorMessages = pErrors.getErrorMessages();
if (errorMessages.size()>0) {
//System.err.println("Errors during document parsing");
if (isFile) {
parsingErrorMessages.put(toParse,errorMessages);
} else {
parsingErrorMessages.put("",errorMessages);
}
}
if (document!=null) {
pkg=new Package(this);
pkg.fromXML(document.getDocumentElement());//看到最本质的解析还是分布在各个shark.xpdl.elements包中的代表每个元素的对象中
//System.out.println("package "+pkg+" imported");
}
} catch (Exception ex) {
ex.printStackTrace();
System.err.println("Fatal error while parsing document");
Set fem=new HashSet();
fem.add("Fatal error while parsing document");
if (isFile) {
parsingErrorMessages.put(toParse,fem);
} else {
parsingErrorMessages.put("",fem);
}
return null;
}
return pkg;
}
这一部分有两个接口比较重要org.enhydra.shark.api.client.wfservice.RepositoryMgrorg.enhydra.shark.xpdl.XMLInterface其中XMLInterface主要是对xpdl文件中包的操作,并作解析工作,如Package openPackage(packagePath,isFromStram) xpdl文件打开过程首先上传文件(在shark的客户端代码中--UploadPackage的action中)
try {
File pkgFile=new File(pkgToUpload)
RandomAccessFile raf=new RandomAccessFile(pkgFile,"r");
byte[] utf8Bytes=null;
long noOfBytes=raf.length();
if (noOfBytes>0) {
utf8Bytes=new byte[(int)noOfBytes];
raf.seek(0);
raf.readFully(utf8Bytes);
}
if (utf8Bytes!=null) {
String rPath=uprp.getRelativeFilePath();//获得该文件的相对路径
SharkAdmin.getRepositoryManager().uploadPackage(utf8Bytes,rPath);//代表xpdl文件的byte[],xpdl文件的相对路径
} }
} catch (RepositoryInvalid ri) {
} 2.调用RepositoryMgr接口的uploadPackage(byte[],String)String path=SharkUtilities.EXTERNAL_PACKAGES_REPOSITORY+File.separator+relativePath; XMLInterface xpdlManager=new XMLInterfaceForJDK13();
Package updatedPkg=xpdlManager.openPackage(path,false);//false代表从文件中读取 3.调用XMLInterface的openPackage(path,false),返回代表elements的Package对象真正的解析xml文件也是在这里执行的openPackage(){ Package pkg=openDocument(pkgReference,openFromStream,handleExternalPackages);//打开xpdl文件,并解析,返回Package对象
}4.调用XMLInterface的parseDocument()进行解析,最关键的地方openDocument(){ if (!openFromStream) {
pkg=parseDocument(pkgReference,true);//
} } public Package parseDocument (String toParse,boolean isFile) {
Package pkg=null;
// Create a Xerces DOM Parser
DOMParser parser = new DOMParser(); // Parse the Document and traverse the DOM
try {
parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error",true);
ParsingErrors pErrors=new ParsingErrors();
parser.setErrorHandler(pErrors);
if (isValidationON) {
parser.setEntityResolver(new XPDLEntityResolver());
parser.setFeature("http://xml.org/sax/features/validation",true);
parser.setFeature("http://apache.org/xml/features/validation/schema",true);
//parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",true);
}
if (isFile) {
//System.out.println("Parsing from file");
//parser.parse(toParse);
File f=new File(toParse);
if (!f.exists()) {
f=new File(f.getCanonicalPath());
}
parser.parse(new InputSource(new FileInputStream(f))); // Fixed by Harald Meister
} else {
//System.out.println("Parsing from stream");
parser.parse(new InputSource(new StringReader(toParse)));
}
Document document = parser.getDocument();
Set errorMessages = pErrors.getErrorMessages();
if (errorMessages.size()>0) {
//System.err.println("Errors during document parsing");
if (isFile) {
parsingErrorMessages.put(toParse,errorMessages);
} else {
parsingErrorMessages.put("",errorMessages);
}
}
if (document!=null) {
pkg=new Package(this);
pkg.fromXML(document.getDocumentElement());//看到最本质的解析还是分布在各个shark.xpdl.elements包中的代表每个元素的对象中
//System.out.println("package "+pkg+" imported");
}
} catch (Exception ex) {
ex.printStackTrace();
System.err.println("Fatal error while parsing document");
Set fem=new HashSet();
fem.add("Fatal error while parsing document");
if (isFile) {
parsingErrorMessages.put(toParse,fem);
} else {
parsingErrorMessages.put("",fem);
}
return null;
}
return pkg;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货