MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

  • Javascript
  • Cappuccino

Cappuccino

Cappuccino is a framework which makes it easy to create advanced web apps.

http://www.cappuccino-project.org/

Objective-J is a powerful object-oriented language which compiles to run in the browser.

API http://www.cappuccino-project.org/learn/documentation/

Get the code

Clone it using git:

   1 cd ~
   2 mkdir gitCappuccino
   3 cd  gitCappuccino
   4 git clone git://github.com/cappuccino/cappuccino.git
   5 cd ~/gitCappuccino/cappuccino

Vim editor Objective-J plugin

Run the following commands after fetching code from github:

   1 mkdir -p ~/.vim/plugin
   2 cd ~/gitCappuccino/cappuccino/Tools/Editors/Vim]
   3 cp objj.vim  ~/.vim/plugin

Emacs editor Objective-J plugin

   1 mkdir ~/cappuccinoEmacs
   2 cd ~/gitCappuccino/cappuccino/Tools/Editors/Emacs
   3 cp *.el ~/cappuccinoEmacs/
   4 touch ~/.emacs
   5 nano ~/.emacs
   6 #(add-to-list 'load-path "~/cappuccinoEmacs")
   7 #(require 'objj-mode)
   8 

Init String, stringWithFormat, CPString

   1 var str1 = [CPString initWithString: @""];
   2 var str2 = [CPString initWithString: @""]; 
   3 var str3 = [CPString stringWithFormat:"StrX %s %s %s" , [obj field1] , [obj field2] , [obj field3] ];
   4 var strLen [str3 length];

Mutable Array

   1 @import <Foundation/CPMutableArray.j>
   2 
   3 var arrayX = [[CPMutableArray alloc] init]; 

Callbacks

   1 @implementation TestObject : CPObject
   2 {
   3 }
   4 
   5 -(void)helloWorld{
   6   CPLogConsole("Called hello world");
   7 }
   8 //(...)
   9 @end
  10 
  11 //--------------------
  12 var selectorHelloWorld =  @selector(helloWorld) ;
  13 var signature = [self methodSignatureForSelector: aSelector];
  14 var invocation = [CPInvocation invocationWithMethodSignature:signature];
  15 [invocation setSelector: selectorHelloWorld];
  16 [invocation invokeWithTarget: self]; //self -> instance of TestObject
  17 

   1 @implementation TestObject : CPObject
   2 {
   3 }
   4 
   5 -(void)helloWorldMsg:(CPString) message p1:(int)intVal {
   6   CPLogConsole( message  );
   7   CPLogConsole( intVal  );
   8 }
   9 //(...)
  10 @end
  11 
  12 //--------------------
  13 var selectorHelloWorldMsg =  @selector(helloWorldMsg:p1:) ;
  14 var sig = [self methodSignatureForSelector: selectorHelloWorldMsg];
  15 var invocation = [CPInvocation invocationWithMethodSignature:sig];
  16 [invocation setSelector: selectorHelloWorldMsg];
  17 [invocation setArgument:@"Message" atIndex:2 ]; //0-> self 1->_cmd 
  18 [invocation setArgument: 1234 atIndex:3 ]; //0-> self 1->_cmd 
  19 [invocation invokeWithTarget: self]; 

Dates

   1 var datex = [CPDate dateWithTimeIntervalSince1970: dateInSeconds]; //set CPDate with seconds since 01-01-1970 UTC
   2 var strDate = [instanceCPDate description];// get string with date in format YYYY-MM-DD HH:MM:SS TZ±HHMM.               
   3 

Dictionary from JSON object

   1 - (void)connection:(CPURLConnection) connection didReceiveData:(CPString)data
   2 {
   3   var dict = [CPDictionary dictionaryWithJSObject: [data objectFromJSON]  ];    
   4   [textField setStringValue:  [dict valueForKey:@"lkeyx"] ];
   5 }
   6 
   7 - (void)connection:(CPURLConnection)connection didFailWithError:(CPString)error
   8 {
   9 }

When a number is defined on a JSON object, a CPNumber is returned in valueForKey.

   1 // JSON for aData
   2 {
   3   "subDocument":
   4   {
   5     "dateValue":12345
   6   }
   7 }

   1 var otherDict = [CPDictionary dictionaryWithJSObject: [aData objectFromJSON]  ];
   2 var dictx = [CPDictionary dictionaryWithJSObject: [otherdict valueForKey:@"subDocument"] ];
   3 var dateValue = [ [dictx valueForKey:@"dateValue"] doubleValue];                 

Load JSON array

JSON array

   1 [ {"paramx":"aaaa","valuex":"aaaaaddd"} , 
   2   {"paramx":"asassassa","valuex":"ggghfghf"} 
   3 ]

Acme class

   1 @implementation Acme : CPObject 
   2 {
   3   CPString paramx @accessors;
   4   CPString valuex @accessors;
   5 }
   6 
   7 @end

Receive data from web service

   1 -(void) connection:(CPURLConnection) connection didReceiveData:(CPString)aData {
   2     var jsonArray = [aData objectFromJSON];
   3     
   4     _tableData = [[CPMutableArray alloc] init];
   5     
   6     for(var idx=0;idx< jsonArray.length;idx++){
   7         var objx = jsonArray[idx];
   8         var dictx = [CPDictionary dictionaryWithJSObject: objx ];
   9         
  10         var acme = [Acme alloc];
  11         [acme setParamx: [dictx valueForKey:@"paramx"] ];
  12         [acme setValuex: [dictx valueForKey:@"valuex"] ];
  13         [_tableData addObject: acme];
  14     }
  15     
  16     [_tableView reloadData];
  17 }

URL request

   1   var url = [CPString  stringWithFormat:"/JEE-war/rest/getInfo/%@", [textField stringValue] ] ;   
   2   var request = [CPURLRequest requestWithURL: url ];
   3   var connection = [CPURLConnection connectionWithRequest:request delegate:self]; //calls didFailWithError and didReceiveData
   4 

Mime types Glassfish + JBoss

Adapted from https://github.com/cappuccino/cappuccino/wiki/Server-Side-Issues

You need to have the mime type of file types it doesn’t understand set to something for Cappuccino to work. Specifically, you should set the following mime-type/extension pairs. This can be done in the web.xml:

   1 <mime-mapping>
   2      <extension>j</extension>
   3      <mime-type>text/javascript</mime-type>
   4 </mime-mapping>
   5 <mime-mapping>
   6      <extension>plist</extension>
   7      <mime-type>text/xml</mime-type>
   8 </mime-mapping>
   9 <mime-mapping>
  10       <extension>sj</extension>
  11       <mime-type>text/javascript</mime-type>
  12 </mime-mapping>

Download file

http://ique.github.io/2009/11/cptableview-uploading-and-downloading-in-cappuccino/

   1     DownloadIFrame = document.createElement("iframe");
   2     DownloadIFrame.style.position = "absolute";
   3     DownloadIFrame.style.top    = "-100px";
   4     DownloadIFrame.style.left   = "-100px";
   5     DownloadIFrame.style.height = "0px";
   6     DownloadIFrame.style.width  = "0px";
   7     document.body.appendChild(DownloadIFrame);
   8     //....
   9     DownloadIFrame.src = "http://localhost:3000/uploads/fileXpto";

Index of string

Apple Foundation data types

   1 var range = [data rangeOfString:@"str xyz"];
   2 CPLogConsole( JSON.stringify(range) );
   3 // CPrange has fields location and length 
   4 // If location >=0 the string has been found
   5 

TableView

   1 //allow multiple selections , CPTableView (NSTableView)
   2 [tableviewx setAllowsMultipleSelection:YES];

Timer

   1 @import <Foundation/CPTimer.j>
   2 
   3 CPTimer _timer;
   4 
   5 // timer each 5 seconds
   6 _timer = [CPTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(timerHandler:) userInfo:nil repeats:YES];
   7 
   8 -(void)timerHandler:(id)sender {
   9     [self updateData];
  10         
  11     if( [self isVisible]==false ){
  12         // terminates the timer
  13         [_timer invalidate];
  14     }
  15 }

Button

   1 // create button
   2 CPButton cpbutton = [CPButton alloc];
   3 [cpbutton initWithFrame:CGRectMakeZero()];
   4 [cpbutton setFrameOrigin:CGPointMake(10,10)];                
   5 [cpbutton setFrameSize:CGSizeMake(100,25)];                
   6 [cpbutton setTitle: @"Buttonx"];
   7 [cpbutton setTarget: self];
   8 [cpbutton setAction: @selector(cpbuttonClicked:)];      
   9 [aView addSubview: cpbutton];
  10 // clicked handler
  11 -(void)cpbuttonClicked:(id)sender {
  12 //(...)
  13 }
  14 //enable button
  15 [cpbutton setEnabled:YES];
  16 //disable button
  17 [cpbutton setEnabled:NO];

Data transfer object

   1 @implementation SampleDTO : CPObject 
   2 {
   3   CPString date @accessors;
   4   CPString text @accessors;
   5   CPString origin @accessors;
   6   CPString destination @accessors;  
   7 }
   8 
   9 @end

To get data in the fields:

   1 [obj date];
   2 [obj text];
   3 [obj origin];
   4 [obj destination];

To set data in the fields:

   1 [obj setDate @"datex"];
   2 [obj setText @"textx"];
   3 [obj setOrigin @"originx"];
   4 [obj setDestination @"destinationx"];

Starter

  • wget http://www.cappuccino-project.org/downloads/CappuccinoStarter-0.9.7-1.zip

  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01