/[webpac]/openisis/current/org/openisis/RecToXml.java
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /openisis/current/org/openisis/RecToXml.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 237 - (show annotations)
Mon Mar 8 17:43:12 2004 UTC (20 years, 1 month ago) by dpavlin
File size: 2487 byte(s)
initial import of openisis 0.9.0 vendor drop

1 /*
2 openisis - an open implementation of the CDS/ISIS database
3 Version 0.8.x (patchlevel see file Version)
4 Copyright (C) 2001-2003 by Erik Grziwotz, erik@openisis.org
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 see README for more information
21 EOH */
22
23
24 package org.openisis;
25
26
27 /**
28 convert OpenIsisRecord to Xml
29 */
30
31
32 import java.io.*;
33 import java.util.*;
34
35 public class RecToXml {
36 private Fdt myFdt;
37
38 public RecToXml(Fdt fdt) {
39 myFdt=fdt;
40 }
41
42 public String toXML(Rec rec,String add) {
43 return toXML(rec,"",add);
44 }
45
46 public String toXML(Rec rec,String pre,String add) {
47 StringBuffer xml=new StringBuffer();
48 Field f;
49 Rec subRec;
50 int subLen;
51 int i=0;
52 String lastTag=null;
53 String h;
54 while(i<rec.getLen()) {
55 f=rec.getField(i);
56 if (f.tag==Integer.MAX_VALUE) {
57 //unwrap it
58 subLen=new Integer(f.val).intValue();
59 subRec=new Rec(0,rec.getFields(i+1,subLen));
60 xml.append((h=toXML(subRec,pre+add)));
61 i+=subLen;
62 if (lastTag!=null) {
63 xml.append("</"+lastTag+">");
64 lastTag=null;
65 }
66 } else {
67 if (lastTag!=null) {
68 xml.append("</"+lastTag+">");
69 lastTag=null;
70 }
71 if (f!=null && myFdt.fdById(f.tag)!=null) {
72 Field sf[]=f.getSubFields();
73 String value=f.getValue();
74 String atts="";
75 if (sf!=null && sf.length>0) {
76 atts=atts;
77 for(int j=0;j<sf.length;j++) {
78 atts=atts+" "+((char)sf[j].tag)+"=\""+sf[j].val+"\"";
79 }
80 atts=atts+" ";
81 }
82 lastTag=myFdt.fdById(f.tag).name;
83 xml.append(pre+"<"+lastTag+atts+">");
84 if (value.indexOf("&")>=0 || value.indexOf("<")>=0) {
85 value="<![CDATA["+value+"]]>";
86 }
87 xml.append(value);
88 }
89 //xml.append("</"+myFdt.fdById(f.tag).name+">\n");
90 }
91 i++;
92 }
93 if (lastTag!=null) xml.append(pre+"</"+lastTag+">");
94 return xml.toString();
95 }
96
97 }
98

  ViewVC Help
Powered by ViewVC 1.1.26