@@ -204,6 +204,9 @@ Clazz.cloneFinals = function () {
204204/* public */
205205Clazz . isClassDefined = Clazz . isDefinedClass = function ( clazzName ) {
206206 if ( clazzName != null && clazzName . length != 0 ) {
207+ if ( Clazz . allClasses [ clazzName ] ) {
208+ return true ;
209+ }
207210 var pkgFrags = clazzName . split ( / \. / ) ;
208211 var pkg = null ;
209212 for ( var i = 0 ; i < pkgFrags . length ; i ++ ) {
@@ -222,7 +225,13 @@ Clazz.isClassDefined = Clazz.isDefinedClass = function (clazzName) {
222225 }
223226 }
224227 //error (clazzName + " / " + (pkg != null));
225- return pkg != null ;
228+ //return pkg != null;
229+ if ( pkg != null ) {
230+ Clazz . allClasses [ clazzName ] = true ;
231+ return true ;
232+ } else {
233+ return false ;
234+ }
226235 } else {
227236 /* consider null or empty name as non-defined class */
228237 return false ;
@@ -735,6 +744,7 @@ Clazz.innerFunctions.newInstance = function () {
735744 }
736745}
737746
747+ /* public */
738748Clazz . forName = function ( clazzName ) {
739749 if ( Clazz . isClassDefined ( clazzName ) ) {
740750 return Clazz . evalType ( clazzName ) ;
@@ -747,3 +757,98 @@ Clazz.forName = function (clazzName) {
747757 alert ( "[Java2Script] Error: No ClassLoader!" ) ;
748758 }
749759} ;
760+
761+ /* protected */
762+ Clazz . cssAlreadyAggregated = false ;
763+ Clazz . cssForcedUsingFile = true ;
764+
765+ countxx = 0 ;
766+ /* private */
767+ Clazz . cssForIE = function ( key ) {
768+ var value = window [ key ] ;
769+ window [ key ] = true ; // loaded and release css text
770+ return value ;
771+ } ;
772+
773+ /**
774+ * Register css for the given class. If the given css text is null, it will
775+ * try to find relative *.css file instead loading css text directly.
776+ * @param clazzName Qualified name of a class
777+ * @param cssText Optional, if given, it will loaded into the page directly.
778+ */
779+ /* public */
780+ Clazz . registerCSS = function ( clazzName , cssText ) {
781+ if ( Clazz . cssAlreadyAggregated || window [ "ClazzLoader" ] == null ) {
782+ return ;
783+ }
784+ clazzName = ClazzLoader . unwrapArray ( [ clazzName ] ) [ 0 ] ;
785+ var cssPath = ClazzLoader . getClasspathFor ( clazzName , false , ".css" ) ;
786+ var basePath = ClazzLoader . getClasspathFor ( clazzName , true ) ;
787+ /*
788+ * Check whether the css resources is loaded or not
789+ */
790+ if ( ! ClazzLoader . isResourceExisted ( clazzName , cssPath , basePath ) ) {
791+ if ( cssText == null || Clazz . cssForcedUsingFile ) {
792+ var cssLink = document . createElement ( "LINK" ) ;
793+ cssLink . rel = "stylesheet" ;
794+ cssLink . id = clazzName ;
795+ cssLink . href = cssPath ;
796+ document . getElementsByTagName ( "HEAD" ) [ 0 ] . appendChild ( cssLink ) ;
797+ } else {
798+ var prefix = "" ;
799+ var idx = cssPath . lastIndexOf ( "/" ) ;
800+ if ( idx != - 1 ) {
801+ prefix = cssPath . substring ( 0 , idx + 1 ) ;
802+ }
803+ if ( document . createStyleSheet != null ) {
804+ // prepare for createStyleSheet with "javascript:...";
805+ /*
806+ * TODO: Make more tests on the correctness of prefix!
807+ */
808+ //var protocol = window.location.protocol;
809+ //var host = window.location.host;
810+ var location = window . location . href . toString ( ) ;
811+ //if (protocol == "file:" || host == "") {
812+ var idx = location . lastIndexOf ( "/" ) ;
813+ if ( idx != - 1 ) {
814+ prefix = location . substring ( 0 , idx + 1 ) + prefix ;
815+ }
816+ //}
817+ }
818+ /*
819+ * Fix the css images location
820+ */
821+ cssText = cssText . replace ( / ( u r l \s * \( \s * [ ' " ] ) ( .* ) ( [ ' " ] ) / ig,
822+ //"
823+ function ( $0 , $1 , $2 , $3 ) {
824+ if ( $2 . indexOf ( "/" ) == 0
825+ || $2 . indexOf ( "http://" ) == 0
826+ || $2 . indexOf ( "https://" ) == 0
827+ || $2 . indexOf ( "file:/" ) == 0
828+ || $2 . indexOf ( "ftp://" ) == 0
829+ || $2 . indexOf ( "javascript:" ) == 0 ) {
830+ return $0 ;
831+ }
832+ return $1 + prefix + $2 + $3 ;
833+ } ) ;
834+ if ( document . createStyleSheet != null ) {
835+ /*
836+ * Internet Explorer does not support loading dynamic css styles
837+ * by <STYLE>!
838+ */
839+ var cssID = "css." + clazzName ;
840+ window [ cssID ] = cssText ;
841+ /*
842+ * TODO: Keep eyes open on IE. Maybe IE won't initialize this
843+ * javascript-kind of CSS!
844+ */
845+ document . createStyleSheet ( "javascript:Clazz.cssForIE (\"" + cssID + "\");" ) ;
846+ } else {
847+ var cssStyle = document . createElement ( "STYLE" ) ;
848+ cssStyle . id = clazzName ;
849+ cssStyle . appendChild ( document . createTextNode ( cssText ) ) ;
850+ document . getElementsByTagName ( "HEAD" ) [ 0 ] . appendChild ( cssStyle ) ;
851+ }
852+ }
853+ }
854+ } ;
0 commit comments