source: trunk/gsdl-documentation/shared/ExternalRef.java@ 13632

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

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 1.2 KB
Line 
1import java.io.InputStream;
2import java.io.FileInputStream;
3
4import org.w3c.dom.Document;
5import javax.xml.parsers.DocumentBuilderFactory;
6import javax.xml.parsers.DocumentBuilder;
7import org.w3c.dom.Document;
8import org.w3c.dom.Element;
9import org.w3c.dom.Node;
10import org.w3c.dom.NodeList;
11
12
13public class ExternalRef{
14
15 public ExternalRef(){}
16
17 public String getRef(String file, String lang, String targettype, String id){
18
19 try{
20 String tfile = file+"_"+lang+".xml";
21 String path = tfile;
22
23 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
24 DocumentBuilder domBuilder = factory.newDocumentBuilder();
25 InputStream is = new FileInputStream(path);
26 Document doc = domBuilder.parse(is);
27
28 NodeList list = doc.getElementsByTagName(targettype);
29 System.out.println(list.getLength());
30 int i=0;
31 for(i=0; i<list.getLength(); i++){
32 Node node = list.item(i);
33 String id_temp = node.getAttributes().getNamedItem("id").getNodeValue();
34 if(id_temp.equals(id)) break;
35 }
36 return (++i)+"";
37
38 }catch(Exception e){
39 System.err.println(e.getMessage());
40 //e.printStackTrace();
41 return "";
42 }
43 }
44}
Note: See TracBrowser for help on using the repository browser.