1 19 package org.netbeans.modules.xslt.model.impl; 20 21 import java.util.Collections ; 22 import java.util.LinkedHashSet ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 26 import org.netbeans.modules.xml.xam.locator.CatalogModelException; 27 import org.netbeans.modules.xslt.model.Import; 28 import org.netbeans.modules.xslt.model.Include; 29 import org.netbeans.modules.xslt.model.Stylesheet; 30 import org.netbeans.modules.xslt.model.XslModel; 31 32 33 37 final class Utilities { 38 39 private Utilities() { 41 } 42 43 54 static LinkedHashSet <XslModel> getAvailibleModels( XslModel model ){ 55 if ( model == null ) { 56 return new LinkedHashSet <XslModel>(); 57 } 58 LinkedHashSet <XslModel> list = new LinkedHashSet <XslModel>(); 59 list.add( model ); 60 collectModels( model , list ); 61 return list; 62 } 63 64 static void collectModels( XslModel model, LinkedHashSet <XslModel> list ) { 65 Stylesheet stylesheet = model.getStylesheet(); 66 if ( stylesheet == null ) { 67 return; 68 } 69 List <Include> includes = stylesheet.getChildren( Include.class ); 70 for (Include include : includes) { 71 XslModel refModel; 72 try { 73 refModel = include.resolveReferencedModel(); 74 } 75 catch (CatalogModelException e) { 76 continue; 78 } 79 if ( list.contains( refModel )) { 80 continue; 81 } 82 else { 83 list.add( refModel ); 84 collectModels(refModel, list); 85 } 86 } 87 88 LinkedList <Import> imports = 89 new LinkedList <Import>(stylesheet.getImports()); 90 Collections.reverse( imports ); 91 for (Import imprt : imports) { 92 XslModel refModel; 93 try { 94 refModel = imprt.resolveReferencedModel(); 95 } 96 catch (CatalogModelException e) { 97 continue; 99 } 100 if ( list.contains( refModel )) { 101 continue; 102 } 103 else { 104 list.add( refModel ); 105 collectModels(refModel, list); 106 } 107 } 108 } 109 110 111 static boolean equals( String first , String second ) { 112 if ( first == null ) { 113 return second == null; 114 } 115 else { 116 return first.equals(second); 117 } 118 } 119 120 } 121 | Popular Tags |