1 20 21 package org.apache.directory.ldapstudio.schemas.model; 22 23 24 import java.net.URL ; 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 28 import org.apache.commons.configuration.XMLConfiguration; 29 import org.apache.directory.ldapstudio.schemas.Activator; 30 import org.eclipse.core.runtime.Platform; 31 32 33 40 public class Syntaxes 41 { 42 43 private static final ArrayList <Syntax> syntaxes; 44 45 static 47 { 48 try 49 { 50 syntaxes = new ArrayList <Syntax>(); 51 URL url = Platform.getBundle( Activator.PLUGIN_ID ).getResource( "ressources/utils/syntaxes.xml" ); XMLConfiguration config = new XMLConfiguration( url ); 53 54 Object syntaxesList = config.getProperty( "syntax.name" ); if ( syntaxesList instanceof Collection ) 57 { 58 for ( int i = 0; i < ( ( Collection ) syntaxesList ).size(); i++ ) 59 { 60 String name = config.getString( "syntax(" + i + ").name" ); String oid = config.getString( "syntax(" + i + ").oid" ); String hr = config.getString( "syntax(" + i + ").hr" ); 65 Syntax syntax = null; 67 if ( hr.equals( "Y" ) ) { syntax = new Syntax( name, oid, true ); 69 } 70 else if ( hr.equals( "N" ) ) { syntax = new Syntax( name, oid, true ); 72 } 73 74 if ( syntax != null ) 75 syntaxes.add( syntax ); 76 } 77 } 78 79 } 80 catch ( Throwable e ) 81 { 82 throw new RuntimeException ( e.getMessage() ); 83 } 84 } 85 86 87 93 public static ArrayList <Syntax> getSyntaxes() 94 { 95 return syntaxes; 96 } 97 98 99 108 public static Syntax getSyntaxFromName( String name ) 109 { 110 for ( Syntax syntax : syntaxes ) 111 { 112 if ( syntax.getName().equals( name ) ) 113 { 114 return syntax; 115 } 116 } 117 return null; 118 } 119 120 121 130 public static Syntax getSyntaxFromOid( String oid ) 131 { 132 for ( Syntax syntax : syntaxes ) 133 { 134 if ( syntax.getOid().equals( oid ) ) 135 { 136 return syntax; 137 } 138 } 139 return null; 140 } 141 } 142 | Popular Tags |