40 using namespace java::captain; |
40 using namespace java::captain; |
41 using namespace java::storage; |
41 using namespace java::storage; |
42 using namespace java::util; |
42 using namespace java::util; |
43 |
43 |
44 |
44 |
|
45 _LIT(KHexValueStart, "0x"); |
|
46 _LIT(KPercentage, "%"); |
45 _LIT(KSemiColon, ";"); |
47 _LIT(KSemiColon, ";"); |
|
48 _LIT(KMidletNameArg, "midlet-name="); |
|
49 _LIT(KMidletVendorArg, "midlet-vendor="); |
|
50 _LIT(KMidletNArg, "midlet-n="); |
|
51 _LIT(KMidletUidArg, "midlet-uid="); |
|
52 |
46 |
53 |
47 const TInt KExtraLenForLoggingAndPrompting = 22; |
54 const TInt KExtraLenForLoggingAndPrompting = 22; |
48 const TInt KArgumentValueMaxLen = 1568; // Support worst case % encoded args of 512 chars |
55 const TInt KArgumentValueMaxLen = 1568; // Support worst case % encoded args of 512 chars |
49 |
56 |
50 // The Uid of the Web Browser process |
57 // The Uid of the Web Browser process |
56 * If aMidletName is empty, return the Uid of the first application in |
63 * If aMidletName is empty, return the Uid of the first application in |
57 * package aPackageId. |
64 * package aPackageId. |
58 * |
65 * |
59 * @param aJs JavaStorage connection, must be open |
66 * @param aJs JavaStorage connection, must be open |
60 * @param aPackageId the id of the package |
67 * @param aPackageId the id of the package |
61 * @param aMidletName the name of the desired application in the package, can be empty |
68 * @param aMidletId the numerical id of the desired application in the |
|
69 * package, can be empty |
62 * @param aUid the Uid the found application is returned in this param |
70 * @param aUid the Uid the found application is returned in this param |
63 * @return KErrNone if Uid was found, otherwise one of the Symbian error codes |
71 * @return KErrNone if Uid was found, otherwise one of the Symbian error codes |
64 * @throws JavaStorageException if accessing Java Storage fails |
72 * @throws JavaStorageException if accessing Java Storage fails |
65 */ |
73 */ |
66 static TInt getOneApplicationFromPackage( |
74 static TInt getOneApplicationFromPackage( |
67 JavaStorage& aJs, |
75 JavaStorage& aJs, |
68 const std::wstring& aPackageId, |
76 const std::wstring& aPackageId, |
69 const std::wstring& aMidletName, |
77 const std::wstring& aMidletId, |
70 TInt32 &aUid) |
78 TInt32 &aUid) |
71 { |
79 { |
|
80 std::wstring midletId = L"MIDlet-"; |
|
81 if (aMidletId.length() == 0) |
|
82 { |
|
83 midletId.append(L"1"); |
|
84 } |
|
85 else |
|
86 { |
|
87 midletId.append(aMidletId); |
|
88 } |
|
89 |
72 JavaStorageEntry attribute; |
90 JavaStorageEntry attribute; |
73 JavaStorageApplicationEntry_t findPattern; |
91 JavaStorageApplicationEntry_t findPattern; |
74 JavaStorageApplicationList_t foundEntries; |
92 JavaStorageApplicationList_t foundEntries; |
75 |
93 |
76 // Get ID from APPLICATION_TABLE based on PACKAGE_ID and NAME |
94 |
|
95 // Get MIDlet-n from APPLICATION_PACKAGE_ATTRIBUTES_TABLE based on |
|
96 // PACKAGE_ID and NAME. |
|
97 attribute.setEntry(ID, aPackageId); |
|
98 findPattern.insert(attribute); |
|
99 attribute.setEntry(NAME, midletId); |
|
100 findPattern.insert(attribute); |
|
101 attribute.setEntry(VALUE, L""); |
|
102 findPattern.insert(attribute); |
|
103 aJs.search(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, findPattern, foundEntries); |
|
104 |
|
105 if (foundEntries.size() < 1) |
|
106 { |
|
107 return KErrNotFound; |
|
108 } |
|
109 |
|
110 // Found the MIDlet-n argument. Now getting the MIDlet name and |
|
111 // main class. Name is the first argument and main class is the last |
|
112 // in the comma separated list. |
|
113 std::wstring value = foundEntries.front().begin()->entryValue(); |
|
114 int pos = value.find_first_of(L","); |
|
115 std::wstring midletName = value.substr(0, pos); |
|
116 pos = value.find_last_of(L","); |
|
117 std::wstring className = value.substr(pos+1); |
|
118 |
|
119 // Trim white spaces. |
|
120 JavaCommonUtils::trimWstring(midletName, L' '); |
|
121 JavaCommonUtils::trimWstring(className, L' '); |
|
122 findPattern.clear(); |
|
123 foundEntries.clear(); |
|
124 |
|
125 // Get ID from APPLICATION_TABLE based on PACKAGE_ID and MAIN_CLASS |
77 attribute.setEntry(PACKAGE_ID, aPackageId); |
126 attribute.setEntry(PACKAGE_ID, aPackageId); |
78 findPattern.insert(attribute); |
127 findPattern.insert(attribute); |
79 if (aMidletName.length() > 0) |
128 attribute.setEntry(NAME, midletName); |
80 { |
129 findPattern.insert(attribute); |
81 attribute.setEntry(NAME, aMidletName); |
130 attribute.setEntry(MAIN_CLASS, className); |
82 findPattern.insert(attribute); |
131 findPattern.insert(attribute); |
83 } |
|
84 attribute.setEntry(ID, L""); |
132 attribute.setEntry(ID, L""); |
85 findPattern.insert(attribute); |
133 findPattern.insert(attribute); |
86 |
134 |
87 aJs.search(APPLICATION_TABLE, findPattern, foundEntries); |
135 aJs.search(APPLICATION_TABLE, findPattern, foundEntries); |
88 |
136 |
351 * command line given in aMidletCmdLine or find the midlet |
394 * command line given in aMidletCmdLine or find the midlet |
352 * based on the 'midlet-name' and 'midlet-vendor' from |
395 * based on the 'midlet-name' and 'midlet-vendor' from |
353 * Java Storage / AppArc and return the Uid of the midlet. |
396 * Java Storage / AppArc and return the Uid of the midlet. |
354 * |
397 * |
355 * @param aMidletCmdLine command line to be parsed, the format is |
398 * @param aMidletCmdLine command line to be parsed, the format is |
356 * [midlet-name=XXX;midlet-vendor=XXX;|midlet-uid=YYY;]midlet-args=XXX |
399 * [midlet-name=XXX;midlet-vendor=XXX;|midlet-uid=YYY;]<midlet_args> |
357 * @param aUid will contain the Uid parsed from command line |
400 * @param aUid will contain the Uid parsed from command line |
358 * @return KErrNone if the command line specified Uid |
401 * @return KErrNone if the command line specified Uid |
359 */ |
402 */ |
360 static TInt getUidFromCommandLine(const TPtrC &aMidletCmdLine, TInt32 &aUid) |
403 static TInt getUidFromCommandLine(const TPtrC &aMidletCmdLine, TInt32 &aUid) |
361 { |
404 { |
362 _LIT(KMidletUidArg, "midlet-uid="); |
|
363 _LIT(KHexValueStart, "0x"); |
|
364 TInt err(KErrNone); |
405 TInt err(KErrNone); |
365 TInt argPos = aMidletCmdLine.FindF(KMidletUidArg); |
406 TInt argPos = aMidletCmdLine.FindF(KMidletUidArg); |
366 if (KErrNotFound != argPos) |
407 if (KErrNotFound != argPos) |
367 { |
408 { |
368 TPtrC uidToParse = aMidletCmdLine.Mid(argPos + KMidletUidArg.iTypeLength); |
409 TPtrC uidToParse = aMidletCmdLine.Mid(argPos + KMidletUidArg.iTypeLength); |
439 // The following feature is not supported yet. |
480 // The following feature is not supported yet. |
440 // It needs changes also to Java Installer and to |
481 // It needs changes also to Java Installer and to |
441 // Symbian Settings UI |
482 // Symbian Settings UI |
442 TInt maxExtraSpaceForDocumentArg = 0; |
483 TInt maxExtraSpaceForDocumentArg = 0; |
443 #ifdef RD_JAVA_SUPPORT_JAVA_APPS_AS_MIME_TYPE_HANDLERS |
484 #ifdef RD_JAVA_SUPPORT_JAVA_APPS_AS_MIME_TYPE_HANDLERS |
444 _LIT(KDocumentOnlyCmdLine, "midlet-args=document="); |
485 _LIT(KDocumentOnlyCmdLine, "document="); |
445 TFullName documentName; |
486 TFullName documentName; |
446 documentName = commandLine->DocumentName(); |
487 documentName = commandLine->DocumentName(); |
447 if (documentName.Length() > 0) |
488 if (documentName.Length() > 0) |
448 { |
489 { |
449 maxExtraSpaceForDocumentArg = |
490 maxExtraSpaceForDocumentArg = |
539 (wchar_t *)(cmdLineBuf.PtrZ())); |
580 (wchar_t *)(cmdLineBuf.PtrZ())); |
540 } |
581 } |
541 |
582 |
542 // Uid has already been determined, the whole command line is not needed |
583 // Uid has already been determined, the whole command line is not needed |
543 // anymore, only the arguments for the Java application |
584 // anymore, only the arguments for the Java application |
544 _LIT(KMidletArgs, "midlet-args="); |
585 |
545 TInt argsPos = cmdLineBuf.FindF(KMidletArgs); |
586 // Find the last argument that is used to identify the MIDlet |
546 TBool cmdLineIsNotEmpty = EFalse; |
587 TBool cmdLineIsNotEmpty = EFalse; |
547 if (argsPos >= 0) |
588 TInt lastArgPos = cmdLineBuf.FindF(KMidletUidArg); |
548 { |
589 TInt currArgPos = cmdLineBuf.FindF(KMidletNArg); |
549 // Pass everything that follows "midlet-args=" |
590 if (currArgPos > lastArgPos) |
550 cmdLineBuf.Delete(0, argsPos + KMidletArgs.iTypeLength); |
591 { |
|
592 lastArgPos = currArgPos; |
|
593 } |
|
594 currArgPos = cmdLineBuf.FindF(KMidletVendorArg); |
|
595 if (currArgPos > lastArgPos) |
|
596 { |
|
597 lastArgPos = currArgPos; |
|
598 } |
|
599 currArgPos = cmdLineBuf.FindF(KMidletNameArg); |
|
600 if (currArgPos > lastArgPos) |
|
601 { |
|
602 lastArgPos = currArgPos; |
|
603 } |
|
604 |
|
605 // Find the place where the last identity argument ends |
|
606 cmdLineBuf.Delete(0, lastArgPos); |
|
607 lastArgPos = cmdLineBuf.Find(KSemiColon); |
|
608 if (lastArgPos >= 0) |
|
609 { |
|
610 // Pass everything that follows "<last_identity_arg_name>=....;" |
|
611 cmdLineBuf.Delete(0, lastArgPos + 1); |
551 cmdLineIsNotEmpty = ETrue; |
612 cmdLineIsNotEmpty = ETrue; |
552 } |
613 } |
553 else |
614 else |
554 { |
615 { |
555 // No arguments for the Java application |
616 // No arguments for the Java application |
735 * This executable can be started also directly from other native processes |
796 * This executable can be started also directly from other native processes |
736 * to start a Java application with arguments specified in normal process |
797 * to start a Java application with arguments specified in normal process |
737 * command line. |
798 * command line. |
738 * |
799 * |
739 * The command line format is |
800 * The command line format is |
740 * [midlet-name=XXX;midlet-vendor=XXX;[midlet-n=XXX;]|midlet-uid=YYY;]midlet-args=XXX |
801 * [midlet-name=XXX;midlet-vendor=XXX;[midlet-app-name=XXX;]|midlet-uid=YYY;]<midlet_args> |
741 * for example |
802 * for example |
742 * midlet-name=Chess;midlet-vendor=Nokia;midlet-args=startMode=playChessDemo;sound=off; |
803 * midlet-name=Chess;midlet-vendor=Nokia;startMode=playChessDemo;sound=off; |
743 * 'midlet-args' specifies the arguments passed to Java application. |
804 * 'midlet-uid' or 'midlet-name'+'midlet-vendor'+ optional 'midlet-app-name' specify |
744 * 'midlet-uid' or 'midlet-name'+'midlet-vendor' specify the Java application to be started |
805 * the Java application to be started |
745 * |
806 * |
746 * Sample code for starting MIDlet from native code |
807 * Sample code for starting MIDlet from native code |
747 * @code |
808 * @code |
748 RProcess rProcess; |
809 RProcess rProcess; |
749 TInt err = rProcess.Create(_L("javalauncher.exe"), |
810 TInt err = rProcess.Create(_L("javalauncher.exe"), |
750 _L("midlet-uid=0x10137c4d;midlet-args=startMode=startFromCmdLine;sound=ON;landscapeMode=true;")); |
811 _L("midlet-uid=0x10137c4d;startMode=startFromCmdLine;sound=ON;landscapeMode=true;")); |
751 if (KErrNone == err) |
812 if (KErrNone == err) |
752 { |
813 { |
753 TRequestStatus status; |
814 TRequestStatus status; |
754 rProcess.Logon(status); |
815 rProcess.Logon(status); |
755 rProcess.Resume(); |
816 rProcess.Resume(); |