1 20 21 package org.apache.directory.ldapstudio.schemas.io; 22 23 24 import java.io.BufferedWriter ; 25 import java.io.FileWriter ; 26 import java.text.DateFormat ; 27 import java.util.Date ; 28 29 import org.apache.directory.ldapstudio.schemas.model.AttributeType; 30 import org.apache.directory.ldapstudio.schemas.model.ObjectClass; 31 import org.apache.directory.ldapstudio.schemas.model.Schema; 32 33 34 38 public class SchemaWriter 39 { 40 41 47 public void write( Schema schema, String src ) throws Exception 48 { 49 StringBuffer sb = new StringBuffer (); 50 sb.append( "# " + schema.getName() + "\n" ); 51 DateFormat format = DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.MEDIUM ); 52 Date date = new Date (); 53 sb.append( "# Generated by LDAP Studio on " + format.format( date ) + "\n" ); 54 sb.append( "\n" ); 55 56 for ( AttributeType at : schema.getAttributeTypesAsArray() ) 57 { 58 sb.append( at.write() ); 59 sb.append( "\n" ); 60 } 61 62 for ( ObjectClass oc : schema.getObjectClassesAsArray() ) 63 { 64 sb.append( oc.write() ); 65 sb.append( "\n" ); 66 } 67 68 BufferedWriter bufferedWriter; 70 bufferedWriter = new BufferedWriter ( new FileWriter ( src ) ); 71 bufferedWriter.write( sb.toString() ); 72 bufferedWriter.close(); 73 } 74 } 75 | Popular Tags |