private int getNumDoc ( String docID ) { if ( goneContext != null ) { removeDoc ( docID ) ; } for ( int i = 0 ; i < documents . size ( ) ; i ++ ) { if ( documents . get ( i ) . getDocID ( ) . equals ( docID ) ) { // document exist if ( ! testMode && documents . get ( i ) . getXComponent ( ) == null ) { XComponent xComponent = OfficeTools . getCurrentComponent ( xContext ) ; if ( xComponent == null ) { MessageHandler . printToLogFile ( "Error: Document (ID: " + docID + ") has no XComponent -> Internal space will not be deleted when document disposes" ) ; } else { try { xComponent . addEventListener ( xEventListener ) ; } catch ( Throwable t ) { MessageHandler . printToLogFile ( "Error: Document (ID: " + docID + ") has no XComponent -> Internal space will not be deleted when document disposes" ) ; xComponent = null ; } if ( xComponent != null ) { documents . get ( i ) . setXComponent ( xContext , xComponent ) ; MessageHandler . printToLogFile ( "Fixed: XComponent set for Document (ID: " + docID + ")" ) ; } } } return i ; } } // Add new document XComponent xComponent = null ; if ( ! testMode ) { // xComponent == null for test cases xComponent = OfficeTools . getCurrentComponent ( xContext ) ; if ( xComponent == null ) { MessageHandler . printToLogFile ( "Error: Document (ID: " + docID + ") has no XComponent -> Internal space will not be deleted when document disposes" ) ; } else { try { xComponent . addEventListener ( xEventListener ) ; } catch ( Throwable t ) { MessageHandler . printToLogFile ( "Error: Document (ID: " + docID + ") has no XComponent -> Internal space will not be deleted when document disposes" ) ; xComponent = null ; } } } documents . add ( new SingleDocument ( xContext , config , docID , xComponent ) ) ; setMenuTextForSwitchOff ( xContext ) ; if ( debugMode ) { MessageHandler . printToLogFile ( "Document " + docNum + " created; docID = " + docID ) ; } return documents . size ( ) - 1 ; }
Get or Create a Number from docID Return - 1 if failed