1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
public class XslGenerator {
private LinkedHashMap<String, Tag> tmap = new LinkedHashMap<String, Tag> ();
public void generate (Writer writer, List<SimplifiedModel> mappings, String rootelt) throws IOException {
for (SimplifiedModel model : mappings) {
taggenerator( model );
}
for (Iterator<Tag> v = tmap.values().iterator() ; v.hasNext() ;){
System.out.println(v.next().getName());
}
}
private void taggenerator(SimplifiedModel model) throws IOException {
String s = model.getSource ();
StringTokenizer sts = new StringTokenizer(s,"/");
String n ; String m;
n = sts.nextToken();
Tag t1 = new Tag();
if (!tmap.containsKey(n))
{
t1.setName(n);
tmap.put(n,t1);
}
while(sts.hasMoreTokens())
{
m = sts.nextToken();
if (!t1.getTags().containsKey(m))
{
Tag t2 = new Tag(m);
tmap.put(m,t2);
t1.setTags(tmap);
t1=t2;
}
}
}
public static void main(String[] args) throws IOException {
FileWriter writer = new FileWriter ("test.xsl");
String rootelt = "root";
List<SimplifiedModel> mappings = new ArrayList<SimplifiedModel> ();
mappings.add ( new SimplifiedModel ("a/b/c","r1/k"));
mappings.add ( new SimplifiedModel ("a/b/e/tt/h","r2/k/d"));
mappings.add ( new SimplifiedModel ("s/c/b","ro/kd"));
new XslGenerator().generate(writer, mappings,rootelt);
}
} |
Partager