source: other-projects/trunk/gsdl-documentation/shared/ExternalRef.java@ 14152

Last change on this file since 14152 was 13882, checked in by lh92, 17 years ago

removed screen outputs

  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1import java.io.InputStream;
2import java.io.FileInputStream;
3import java.io.File;
4
5import org.w3c.dom.Document;
6import javax.xml.parsers.DocumentBuilderFactory;
7import javax.xml.parsers.DocumentBuilder;
8import org.w3c.dom.Document;
9import org.w3c.dom.Element;
10import org.w3c.dom.Node;
11import org.w3c.dom.NodeList;
12
13
14public class ExternalRef{
15 private String basePath;
16 public ExternalRef(){
17 }
18
19 public String getRef(String file, String lang, String targettype, String id){
20 getPath();
21 try{
22 String tfile = file+"_"+lang+".xml";
23 String path = basePath + "/xml-source/" + lang + "/" + tfile;
24
25 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
26 DocumentBuilder domBuilder = factory.newDocumentBuilder();
27 InputStream is = new FileInputStream(path);
28 Document doc = domBuilder.parse(is);
29
30 NodeList list = doc.getElementsByTagName(targettype);
31 int i=0;
32 for(i=0; i<list.getLength(); i++){
33 Node node = list.item(i);
34 String id_temp = node.getAttributes().getNamedItem("id").getNodeValue();
35 if(id_temp.equals(id)) break;
36 }
37 return (++i)+"";
38
39 }catch(Exception e){
40 System.err.println(e.getMessage());
41 //e.printStackTrace();
42 return "";
43 }
44 }
45
46 private void getPath(){
47 basePath = System.getProperty("user.dir");
48
49 //find where is the manuals directory
50 File tempfile = new File(basePath);
51 String parentPath = tempfile.getParent();
52
53 boolean find = false;
54 while(!find){
55 File tempfile2 = new File(parentPath+"/manuals");
56 if(tempfile2.exists() && tempfile2.isDirectory()){
57 basePath = parentPath+"/manuals";
58 find = true;
59 }
60 else if(parentPath.endsWith("manuals")){
61 //if the shared directory is inside the manual directory
62 basePath = parentPath;
63 find = true;
64 }
65 if(!find){
66 tempfile = new File(parentPath);
67 parentPath = tempfile.getParent();
68 }
69 }
70 }
71}
Note: See TracBrowser for help on using the repository browser.