2 // Copyright 2006 The Android Open Source Project
4 // Build resource files from raw assets.
7 #include "AaptAssets.h"
8 #include "StringPool.h"
10 #include "ResourceTable.h"
15 // ==========================================================================
16 // ==========================================================================
17 // ==========================================================================
29 status_t
parsePackage(const sp
<AaptGroup
>& grp
);
32 // ==========================================================================
33 // ==========================================================================
34 // ==========================================================================
36 static String8
parseResourceName(const String8
& leaf
)
38 const char* firstDot
= strchr(leaf
.string(), '.');
39 const char* str
= leaf
.string();
42 return String8(str
, firstDot
-str
);
48 ResourceTypeSet::ResourceTypeSet()
50 KeyedVector
<String8
,sp
<AaptGroup
> >()
54 class ResourceDirIterator
57 ResourceDirIterator(const sp
<ResourceTypeSet
>& set
, const String8
& resType
)
58 : mResType(resType
), mSet(set
), mSetPos(0), mGroupPos(0)
62 inline const sp
<AaptGroup
>& getGroup() const { return mGroup
; }
63 inline const sp
<AaptFile
>& getFile() const { return mFile
; }
65 inline const String8
& getBaseName() const { return mBaseName
; }
66 inline const String8
& getLeafName() const { return mLeafName
; }
67 inline String8
getPath() const { return mPath
; }
68 inline const ResTable_config
& getParams() const { return mParams
; }
80 // Try to get next file in this current group.
81 if (mGroup
!= NULL
&& mGroupPos
< mGroup
->getFiles().size()) {
83 file
= group
->getFiles().valueAt(mGroupPos
++);
85 // Try to get the next group/file in this directory
86 } else if (mSetPos
< mSet
->size()) {
87 mGroup
= group
= mSet
->valueAt(mSetPos
++);
88 if (group
->getFiles().size() < 1) {
91 file
= group
->getFiles().valueAt(0);
101 String8
leaf(group
->getLeaf());
102 mLeafName
= String8(leaf
);
103 mParams
= file
->getGroupEntry().toParams();
104 NOISY(printf("Dir %s: mcc=%d mnc=%d lang=%c%c cnt=%c%c orient=%d density=%d touch=%d key=%d inp=%d nav=%d\n",
105 group
->getPath().string(), mParams
.mcc
, mParams
.mnc
,
106 mParams
.language
[0] ? mParams
.language
[0] : '-',
107 mParams
.language
[1] ? mParams
.language
[1] : '-',
108 mParams
.country
[0] ? mParams
.country
[0] : '-',
109 mParams
.country
[1] ? mParams
.country
[1] : '-',
111 mParams
.density
, mParams
.touchscreen
, mParams
.keyboard
,
112 mParams
.inputFlags
, mParams
.navigation
));
114 mPath
.appendPath(file
->getGroupEntry().toDirName(mResType
));
115 mPath
.appendPath(leaf
);
116 mBaseName
= parseResourceName(leaf
);
117 if (mBaseName
== "") {
118 fprintf(stderr
, "Error: malformed resource filename %s\n",
119 file
->getPrintableSource().string());
120 return UNKNOWN_ERROR
;
123 NOISY(printf("file name=%s\n", mBaseName
.string()));
132 const sp
<ResourceTypeSet
> mSet
;
135 sp
<AaptGroup
> mGroup
;
142 ResTable_config mParams
;
145 // ==========================================================================
146 // ==========================================================================
147 // ==========================================================================
149 bool isValidResourceType(const String8
& type
)
151 return type
== "anim" || type
== "drawable" || type
== "layout"
152 || type
== "values" || type
== "xml" || type
== "raw"
153 || type
== "color" || type
== "menu";
156 static sp
<AaptFile
> getResourceFile(const sp
<AaptAssets
>& assets
, bool makeIfNecessary
=true)
158 sp
<AaptGroup
> group
= assets
->getFiles().valueFor(String8("resources.arsc"));
161 file
= group
->getFiles().valueFor(AaptGroupEntry());
167 if (!makeIfNecessary
) {
170 return assets
->addFile(String8("resources.arsc"), AaptGroupEntry(), String8(),
174 static status_t
parsePackage(const sp
<AaptAssets
>& assets
, const sp
<AaptGroup
>& grp
)
176 if (grp
->getFiles().size() != 1) {
177 fprintf(stderr
, "WARNING: Multiple AndroidManifest.xml files found, using %s\n",
178 grp
->getFiles().valueAt(0)->getPrintableSource().string());
181 sp
<AaptFile
> file
= grp
->getFiles().valueAt(0);
184 status_t err
= parseXMLResource(file
, &block
);
185 if (err
!= NO_ERROR
) {
188 //printXMLBlock(&block);
190 ResXMLTree::event_code_t code
;
191 while ((code
=block
.next()) != ResXMLTree::START_TAG
192 && code
!= ResXMLTree::END_DOCUMENT
193 && code
!= ResXMLTree::BAD_DOCUMENT
) {
197 if (code
!= ResXMLTree::START_TAG
) {
198 fprintf(stderr
, "%s:%d: No start tag found\n",
199 file
->getPrintableSource().string(), block
.getLineNumber());
200 return UNKNOWN_ERROR
;
202 if (strcmp16(block
.getElementName(&len
), String16("manifest").string()) != 0) {
203 fprintf(stderr
, "%s:%d: Invalid start tag %s, expected <manifest>\n",
204 file
->getPrintableSource().string(), block
.getLineNumber(),
205 String8(block
.getElementName(&len
)).string());
206 return UNKNOWN_ERROR
;
209 ssize_t nameIndex
= block
.indexOfAttribute(NULL
, "package");
211 fprintf(stderr
, "%s:%d: <manifest> does not have package attribute.\n",
212 file
->getPrintableSource().string(), block
.getLineNumber());
213 return UNKNOWN_ERROR
;
216 assets
->setPackage(String8(block
.getAttributeStringValue(nameIndex
, &len
)));
221 // ==========================================================================
222 // ==========================================================================
223 // ==========================================================================
225 static status_t
makeFileResources(Bundle
* bundle
, const sp
<AaptAssets
>& assets
,
226 ResourceTable
* table
,
227 const sp
<ResourceTypeSet
>& set
,
230 String8
type8(resType
);
231 String16
type16(resType
);
233 bool hasErrors
= false;
235 ResourceDirIterator
it(set
, String8(resType
));
237 while ((res
=it
.next()) == NO_ERROR
) {
238 if (bundle
->getVerbose()) {
239 printf(" (new resource id %s from %s)\n",
240 it
.getBaseName().string(), it
.getFile()->getPrintableSource().string());
242 String16
baseName(it
.getBaseName());
243 const char16_t* str
= baseName
.string();
244 const char16_t* const end
= str
+ baseName
.size();
246 if (!((*str
>= 'a' && *str
<= 'z')
247 || (*str
>= '0' && *str
<= '9')
248 || *str
== '_' || *str
== '.')) {
249 fprintf(stderr
, "%s: Invalid file name: must contain only [a-z0-9_.]\n",
250 it
.getPath().string());
255 String8 resPath
= it
.getPath();
256 resPath
.convertToResPath();
257 table
->addEntry(SourcePos(it
.getPath(), 0), String16(assets
->getPackage()),
263 assets
->addResource(it
.getLeafName(), resPath
, it
.getFile(), type8
);
266 return hasErrors
? UNKNOWN_ERROR
: NO_ERROR
;
269 static status_t
preProcessImages(Bundle
* bundle
, const sp
<AaptAssets
>& assets
,
270 const sp
<ResourceTypeSet
>& set
)
272 ResourceDirIterator
it(set
, String8("drawable"));
273 Vector
<sp
<AaptFile
> > newNameFiles
;
274 Vector
<String8
> newNamePaths
;
276 while ((res
=it
.next()) == NO_ERROR
) {
277 res
= preProcessImage(bundle
, assets
, it
.getFile(), NULL
);
278 if (res
!= NO_ERROR
) {
286 status_t
postProcessImages(const sp
<AaptAssets
>& assets
,
287 ResourceTable
* table
,
288 const sp
<ResourceTypeSet
>& set
)
290 ResourceDirIterator
it(set
, String8("drawable"));
292 while ((res
=it
.next()) == NO_ERROR
) {
293 res
= postProcessImage(assets
, table
, it
.getFile());
294 if (res
!= NO_ERROR
) {
299 return res
< NO_ERROR
? res
: (status_t
)NO_ERROR
;
302 static void collect_files(const sp
<AaptDir
>& dir
,
303 KeyedVector
<String8
, sp
<ResourceTypeSet
> >* resources
)
305 const DefaultKeyedVector
<String8
, sp
<AaptGroup
> >& groups
= dir
->getFiles();
306 int N
= groups
.size();
307 for (int i
=0; i
<N
; i
++) {
308 String8 leafName
= groups
.keyAt(i
);
309 const sp
<AaptGroup
>& group
= groups
.valueAt(i
);
311 const DefaultKeyedVector
<AaptGroupEntry
, sp
<AaptFile
> >& files
314 if (files
.size() == 0) {
318 String8 resType
= files
.valueAt(0)->getResourceType();
320 ssize_t index
= resources
->indexOfKey(resType
);
323 sp
<ResourceTypeSet
> set
= new ResourceTypeSet();
324 set
->add(leafName
, group
);
325 resources
->add(resType
, set
);
327 sp
<ResourceTypeSet
> set
= resources
->valueAt(index
);
328 index
= set
->indexOfKey(leafName
);
330 set
->add(leafName
, group
);
332 sp
<AaptGroup
> existingGroup
= set
->valueAt(index
);
333 int M
= files
.size();
334 for (int j
=0; j
<M
; j
++) {
335 existingGroup
->addFile(files
.valueAt(j
));
342 static void collect_files(const sp
<AaptAssets
>& ass
,
343 KeyedVector
<String8
, sp
<ResourceTypeSet
> >* resources
)
345 const Vector
<sp
<AaptDir
> >& dirs
= ass
->resDirs();
348 for (int i
=0; i
<N
; i
++) {
349 sp
<AaptDir
> d
= dirs
.itemAt(i
);
350 collect_files(d
, resources
);
352 // don't try to include the res dir
353 ass
->removeDir(d
->getLeaf());
360 ATTR_LEADING_SPACES
= -3,
361 ATTR_TRAILING_SPACES
= -4
363 static int validateAttr(const String8
& path
, const ResXMLParser
& parser
,
364 const char* ns
, const char* attr
, const char* validChars
, bool required
)
368 ssize_t index
= parser
.indexOfAttribute(ns
, attr
);
370 if (index
>= 0 && (str
=parser
.getAttributeStringValue(index
, &len
)) != NULL
) {
372 for (size_t i
=0; i
<len
; i
++) {
374 const char* p
= validChars
;
384 fprintf(stderr
, "%s:%d: Tag <%s> attribute %s has invalid character '%c'.\n",
385 path
.string(), parser
.getLineNumber(),
386 String8(parser
.getElementName(&len
)).string(), attr
, (char)str
[i
]);
392 fprintf(stderr
, "%s:%d: Tag <%s> attribute %s can not start with a space.\n",
393 path
.string(), parser
.getLineNumber(),
394 String8(parser
.getElementName(&len
)).string(), attr
);
395 return ATTR_LEADING_SPACES
;
397 if (str
[len
-1] == ' ') {
398 fprintf(stderr
, "%s:%d: Tag <%s> attribute %s can not end with a space.\n",
399 path
.string(), parser
.getLineNumber(),
400 String8(parser
.getElementName(&len
)).string(), attr
);
401 return ATTR_TRAILING_SPACES
;
406 fprintf(stderr
, "%s:%d: Tag <%s> missing required attribute %s.\n",
407 path
.string(), parser
.getLineNumber(),
408 String8(parser
.getElementName(&len
)).string(), attr
);
409 return ATTR_NOT_FOUND
;
414 static void checkForIds(const String8
& path
, ResXMLParser
& parser
)
416 ResXMLTree::event_code_t code
;
417 while ((code
=parser
.next()) != ResXMLTree::END_DOCUMENT
418 && code
> ResXMLTree::BAD_DOCUMENT
) {
419 if (code
== ResXMLTree::START_TAG
) {
420 ssize_t index
= parser
.indexOfAttribute(NULL
, "id");
422 fprintf(stderr
, "%s:%d: WARNING: found plain 'id' attribute; did you mean the new 'android:id' name?\n",
423 path
.string(), parser
.getLineNumber());
429 static void applyFileOverlay(const sp
<AaptAssets
>& assets
,
430 const sp
<ResourceTypeSet
>& baseSet
,
433 // Replace any base level files in this category with any found from the overlay
434 // Also add any found only in the overlay.
435 sp
<AaptAssets
> overlay
= assets
->getOverlay();
436 String8
resTypeString(resType
);
438 // work through the linked list of overlays
439 while (overlay
.get()) {
440 KeyedVector
<String8
, sp
<ResourceTypeSet
> >* overlayRes
= overlay
->getResources();
442 // get the overlay resources of the requested type
443 ssize_t index
= overlayRes
->indexOfKey(resTypeString
);
445 sp
<ResourceTypeSet
> overlaySet
= overlayRes
->valueAt(index
);
447 // for each of the resources, check for a match in the previously built
448 // non-overlay "baseset".
449 size_t overlayCount
= overlaySet
->size();
450 for (size_t overlayIndex
=0; overlayIndex
<overlayCount
; overlayIndex
++) {
451 size_t baseIndex
= baseSet
->indexOfKey(overlaySet
->keyAt(overlayIndex
));
452 if (baseIndex
!= UNKNOWN_ERROR
) {
453 // look for same flavor. For a given file (strings.xml, for example)
454 // there may be a locale specific or other flavors - we want to match
456 sp
<AaptGroup
> overlayGroup
= overlaySet
->valueAt(overlayIndex
);
457 sp
<AaptGroup
> baseGroup
= baseSet
->valueAt(baseIndex
);
459 DefaultKeyedVector
<AaptGroupEntry
, sp
<AaptFile
> > baseFiles
=
460 baseGroup
->getFiles();
461 DefaultKeyedVector
<AaptGroupEntry
, sp
<AaptFile
> > overlayFiles
=
462 overlayGroup
->getFiles();
463 size_t overlayGroupSize
= overlayFiles
.size();
464 for (size_t overlayGroupIndex
= 0;
465 overlayGroupIndex
<overlayGroupSize
;
466 overlayGroupIndex
++) {
467 size_t baseFileIndex
=
468 baseFiles
.indexOfKey(overlayFiles
.keyAt(overlayGroupIndex
));
469 if(baseFileIndex
< UNKNOWN_ERROR
) {
470 baseGroup
->removeFile(baseFileIndex
);
472 // didn't find a match fall through and add it..
474 baseGroup
->addFile(overlayFiles
.valueAt(overlayGroupIndex
));
477 // this group doesn't exist (a file that's only in the overlay)
479 baseSet
->add(overlaySet
->keyAt(overlayIndex
),
480 overlaySet
->valueAt(overlayIndex
));
483 // this overlay didn't have resources for this type
486 overlay
= overlay
->getOverlay();
491 #define ASSIGN_IT(n) \
493 ssize_t index = resources->indexOfKey(String8(#n)); \
495 n ## s = resources->valueAt(index); \
499 status_t
buildResources(Bundle
* bundle
, const sp
<AaptAssets
>& assets
)
501 // First, look for a package file to parse. This is required to
502 // be able to generate the resource information.
503 sp
<AaptGroup
> androidManifestFile
=
504 assets
->getFiles().valueFor(String8("AndroidManifest.xml"));
505 if (androidManifestFile
== NULL
) {
506 fprintf(stderr
, "ERROR: No AndroidManifest.xml file found.\n");
507 return UNKNOWN_ERROR
;
510 status_t err
= parsePackage(assets
, androidManifestFile
);
511 if (err
!= NO_ERROR
) {
515 NOISY(printf("Creating resources for package %s\n",
516 assets
->getPackage().string()));
518 ResourceTable
table(bundle
, String16(assets
->getPackage()));
519 err
= table
.addIncludedResources(bundle
, assets
);
520 if (err
!= NO_ERROR
) {
524 NOISY(printf("Found %d included resource packages\n", (int)table
.size()));
526 // --------------------------------------------------------------
527 // First, gather all resource information.
528 // --------------------------------------------------------------
530 // resType -> leafName -> group
531 KeyedVector
<String8
, sp
<ResourceTypeSet
> > *resources
=
532 new KeyedVector
<String8
, sp
<ResourceTypeSet
> >;
533 collect_files(assets
, resources
);
535 sp
<ResourceTypeSet
> drawables
;
536 sp
<ResourceTypeSet
> layouts
;
537 sp
<ResourceTypeSet
> anims
;
538 sp
<ResourceTypeSet
> xmls
;
539 sp
<ResourceTypeSet
> raws
;
540 sp
<ResourceTypeSet
> colors
;
541 sp
<ResourceTypeSet
> menus
;
551 assets
->setResources(resources
);
552 // now go through any resource overlays and collect their files
553 sp
<AaptAssets
> current
= assets
->getOverlay();
554 while(current
.get()) {
555 KeyedVector
<String8
, sp
<ResourceTypeSet
> > *resources
=
556 new KeyedVector
<String8
, sp
<ResourceTypeSet
> >;
557 current
->setResources(resources
);
558 collect_files(current
, resources
);
559 current
= current
->getOverlay();
561 // apply the overlay files to the base set
562 applyFileOverlay(assets
, drawables
, "drawable");
563 applyFileOverlay(assets
, layouts
, "layout");
564 applyFileOverlay(assets
, anims
, "anim");
565 applyFileOverlay(assets
, xmls
, "xml");
566 applyFileOverlay(assets
, raws
, "raw");
567 applyFileOverlay(assets
, colors
, "color");
568 applyFileOverlay(assets
, menus
, "menu");
570 bool hasErrors
= false;
572 if (drawables
!= NULL
) {
573 err
= preProcessImages(bundle
, assets
, drawables
);
574 if (err
== NO_ERROR
) {
575 err
= makeFileResources(bundle
, assets
, &table
, drawables
, "drawable");
576 if (err
!= NO_ERROR
) {
584 if (layouts
!= NULL
) {
585 err
= makeFileResources(bundle
, assets
, &table
, layouts
, "layout");
586 if (err
!= NO_ERROR
) {
592 err
= makeFileResources(bundle
, assets
, &table
, anims
, "anim");
593 if (err
!= NO_ERROR
) {
599 err
= makeFileResources(bundle
, assets
, &table
, xmls
, "xml");
600 if (err
!= NO_ERROR
) {
606 err
= makeFileResources(bundle
, assets
, &table
, raws
, "raw");
607 if (err
!= NO_ERROR
) {
614 while(current
.get()) {
615 KeyedVector
<String8
, sp
<ResourceTypeSet
> > *resources
=
616 current
->getResources();
618 ssize_t index
= resources
->indexOfKey(String8("values"));
620 ResourceDirIterator
it(resources
->valueAt(index
), String8("values"));
622 while ((res
=it
.next()) == NO_ERROR
) {
623 sp
<AaptFile
> file
= it
.getFile();
624 res
= compileResourceFile(bundle
, assets
, file
, it
.getParams(),
625 (current
!=assets
), &table
);
626 if (res
!= NO_ERROR
) {
631 current
= current
->getOverlay();
634 if (colors
!= NULL
) {
635 err
= makeFileResources(bundle
, assets
, &table
, colors
, "color");
636 if (err
!= NO_ERROR
) {
642 err
= makeFileResources(bundle
, assets
, &table
, menus
, "menu");
643 if (err
!= NO_ERROR
) {
648 // --------------------------------------------------------------------
649 // Assignment of resource IDs and initial generation of resource table.
650 // --------------------------------------------------------------------
652 if (table
.hasResources()) {
653 sp
<AaptFile
> resFile(getResourceFile(assets
));
654 if (resFile
== NULL
) {
655 fprintf(stderr
, "Error: unable to generate entry for resource data\n");
656 return UNKNOWN_ERROR
;
659 err
= table
.assignResourceIds();
660 if (err
< NO_ERROR
) {
665 // --------------------------------------------------------------
666 // Finally, we can now we can compile XML files, which may reference
668 // --------------------------------------------------------------
670 if (layouts
!= NULL
) {
671 ResourceDirIterator
it(layouts
, String8("layout"));
672 while ((err
=it
.next()) == NO_ERROR
) {
673 String8 src
= it
.getFile()->getPrintableSource();
674 err
= compileXmlFile(assets
, it
.getFile(), &table
);
675 if (err
== NO_ERROR
) {
677 block
.setTo(it
.getFile()->getData(), it
.getFile()->getSize(), true);
678 checkForIds(src
, block
);
684 if (err
< NO_ERROR
) {
691 ResourceDirIterator
it(anims
, String8("anim"));
692 while ((err
=it
.next()) == NO_ERROR
) {
693 err
= compileXmlFile(assets
, it
.getFile(), &table
);
694 if (err
!= NO_ERROR
) {
699 if (err
< NO_ERROR
) {
706 ResourceDirIterator
it(xmls
, String8("xml"));
707 while ((err
=it
.next()) == NO_ERROR
) {
708 err
= compileXmlFile(assets
, it
.getFile(), &table
);
709 if (err
!= NO_ERROR
) {
714 if (err
< NO_ERROR
) {
720 if (drawables
!= NULL
) {
721 err
= postProcessImages(assets
, &table
, drawables
);
722 if (err
!= NO_ERROR
) {
727 if (colors
!= NULL
) {
728 ResourceDirIterator
it(colors
, String8("color"));
729 while ((err
=it
.next()) == NO_ERROR
) {
730 err
= compileXmlFile(assets
, it
.getFile(), &table
);
731 if (err
!= NO_ERROR
) {
736 if (err
< NO_ERROR
) {
743 ResourceDirIterator
it(menus
, String8("menu"));
744 while ((err
=it
.next()) == NO_ERROR
) {
745 String8 src
= it
.getFile()->getPrintableSource();
746 err
= compileXmlFile(assets
, it
.getFile(), &table
);
747 if (err
!= NO_ERROR
) {
751 block
.setTo(it
.getFile()->getData(), it
.getFile()->getSize(), true);
752 checkForIds(src
, block
);
755 if (err
< NO_ERROR
) {
761 const sp
<AaptFile
> manifestFile(androidManifestFile
->getFiles().valueAt(0));
762 String8
manifestPath(manifestFile
->getPrintableSource());
764 // Perform a basic validation of the manifest file. This time we
765 // parse it with the comments intact, so that we can use them to
766 // generate java docs... so we are not going to write this one
767 // back out to the final manifest data.
768 err
= compileXmlFile(assets
, manifestFile
, &table
,
769 XML_COMPILE_ASSIGN_ATTRIBUTE_IDS
770 | XML_COMPILE_STRIP_WHITESPACE
| XML_COMPILE_STRIP_RAW_VALUES
);
771 if (err
< NO_ERROR
) {
775 block
.setTo(manifestFile
->getData(), manifestFile
->getSize(), true);
776 String16
manifest16("manifest");
777 String16
permission16("permission");
778 String16
permission_group16("permission-group");
779 String16
uses_permission16("uses-permission");
780 String16
instrumentation16("instrumentation");
781 String16
application16("application");
782 String16
provider16("provider");
783 String16
service16("service");
784 String16
receiver16("receiver");
785 String16
activity16("activity");
786 String16
action16("action");
787 String16
category16("category");
788 String16
data16("scheme");
789 const char* packageIdentChars
= "abcdefghijklmnopqrstuvwxyz"
790 "ABCDEFGHIJKLMNOPQRSTUVWXYZ._0123456789";
791 const char* packageIdentCharsWithTheStupid
= "abcdefghijklmnopqrstuvwxyz"
792 "ABCDEFGHIJKLMNOPQRSTUVWXYZ._0123456789-";
793 const char* classIdentChars
= "abcdefghijklmnopqrstuvwxyz"
794 "ABCDEFGHIJKLMNOPQRSTUVWXYZ._0123456789$";
795 const char* processIdentChars
= "abcdefghijklmnopqrstuvwxyz"
796 "ABCDEFGHIJKLMNOPQRSTUVWXYZ._0123456789:";
797 const char* authoritiesIdentChars
= "abcdefghijklmnopqrstuvwxyz"
798 "ABCDEFGHIJKLMNOPQRSTUVWXYZ._0123456789-:;";
799 const char* typeIdentChars
= "abcdefghijklmnopqrstuvwxyz"
800 "ABCDEFGHIJKLMNOPQRSTUVWXYZ._0123456789:-/*+";
801 const char* schemeIdentChars
= "abcdefghijklmnopqrstuvwxyz"
802 "ABCDEFGHIJKLMNOPQRSTUVWXYZ._0123456789-";
803 ResXMLTree::event_code_t code
;
804 sp
<AaptSymbols
> permissionSymbols
;
805 sp
<AaptSymbols
> permissionGroupSymbols
;
806 while ((code
=block
.next()) != ResXMLTree::END_DOCUMENT
807 && code
> ResXMLTree::BAD_DOCUMENT
) {
808 if (code
== ResXMLTree::START_TAG
) {
810 if (block
.getElementNamespace(&len
) != NULL
) {
813 if (strcmp16(block
.getElementName(&len
), manifest16
.string()) == 0) {
814 if (validateAttr(manifestPath
, block
, NULL
, "package",
815 packageIdentChars
, true) != ATTR_OKAY
) {
818 } else if (strcmp16(block
.getElementName(&len
), permission16
.string()) == 0
819 || strcmp16(block
.getElementName(&len
), permission_group16
.string()) == 0) {
820 const bool isGroup
= strcmp16(block
.getElementName(&len
),
821 permission_group16
.string()) == 0;
822 if (validateAttr(manifestPath
, block
, RESOURCES_ANDROID_NAMESPACE
, "name",
823 isGroup
? packageIdentCharsWithTheStupid
824 : packageIdentChars
, true) != ATTR_OKAY
) {
827 SourcePos
srcPos(manifestPath
, block
.getLineNumber());
828 sp
<AaptSymbols
> syms
;
830 syms
= permissionSymbols
;
832 sp
<AaptSymbols
> symbols
=
833 assets
->getSymbolsFor(String8("Manifest"));
834 syms
= permissionSymbols
= symbols
->addNestedSymbol(
835 String8("permission"), srcPos
);
838 syms
= permissionGroupSymbols
;
840 sp
<AaptSymbols
> symbols
=
841 assets
->getSymbolsFor(String8("Manifest"));
842 syms
= permissionGroupSymbols
= symbols
->addNestedSymbol(
843 String8("permission_group"), srcPos
);
847 ssize_t index
= block
.indexOfAttribute(RESOURCES_ANDROID_NAMESPACE
, "name");
848 const uint16_t* id
= block
.getAttributeStringValue(index
, &len
);
850 fprintf(stderr
, "%s:%d: missing name attribute in element <%s>.\n",
851 manifestPath
.string(), block
.getLineNumber(),
852 String8(block
.getElementName(&len
)).string());
857 char* p
= idStr
.lockBuffer(idStr
.size());
858 char* e
= p
+ idStr
.size();
859 bool begins_with_digit
= true; // init to true so an empty string fails
862 if (*e
>= '0' && *e
<= '9') {
863 begins_with_digit
= true;
866 if ((*e
>= 'a' && *e
<= 'z') ||
867 (*e
>= 'A' && *e
<= 'Z') ||
869 begins_with_digit
= false;
872 if (isGroup
&& (*e
== '-')) {
874 begins_with_digit
= false;
880 idStr
.unlockBuffer();
881 // verify that we stopped because we hit a period or
882 // the beginning of the string, and that the
883 // identifier didn't begin with a digit.
884 if (begins_with_digit
|| (e
!= p
&& *(e
-1) != '.')) {
886 "%s:%d: Permission name <%s> is not a valid Java symbol\n",
887 manifestPath
.string(), block
.getLineNumber(), idStr
.string());
890 syms
->addStringSymbol(String8(e
), idStr
, srcPos
);
891 const uint16_t* cmt
= block
.getComment(&len
);
892 if (cmt
!= NULL
&& *cmt
!= 0) {
893 //printf("Comment of %s: %s\n", String8(e).string(),
894 // String8(cmt).string());
895 syms
->appendComment(String8(e
), String16(cmt
), srcPos
);
897 //printf("No comment for %s\n", String8(e).string());
899 syms
->makeSymbolPublic(String8(e
), srcPos
);
900 } else if (strcmp16(block
.getElementName(&len
), uses_permission16
.string()) == 0) {
901 if (validateAttr(manifestPath
, block
, RESOURCES_ANDROID_NAMESPACE
, "name",
902 packageIdentChars
, true) != ATTR_OKAY
) {
905 } else if (strcmp16(block
.getElementName(&len
), instrumentation16
.string()) == 0) {
906 if (validateAttr(manifestPath
, block
, RESOURCES_ANDROID_NAMESPACE
, "name",
907 classIdentChars
, true) != ATTR_OKAY
) {
910 if (validateAttr(manifestPath
, block
,
911 RESOURCES_ANDROID_NAMESPACE
, "targetPackage",
912 packageIdentChars
, true) != ATTR_OKAY
) {
915 } else if (strcmp16(block
.getElementName(&len
), application16
.string()) == 0) {
916 if (validateAttr(manifestPath
, block
, RESOURCES_ANDROID_NAMESPACE
, "name",
917 classIdentChars
, false) != ATTR_OKAY
) {
920 if (validateAttr(manifestPath
, block
,
921 RESOURCES_ANDROID_NAMESPACE
, "permission",
922 packageIdentChars
, false) != ATTR_OKAY
) {
925 if (validateAttr(manifestPath
, block
,
926 RESOURCES_ANDROID_NAMESPACE
, "process",
927 processIdentChars
, false) != ATTR_OKAY
) {
930 if (validateAttr(manifestPath
, block
,
931 RESOURCES_ANDROID_NAMESPACE
, "taskAffinity",
932 processIdentChars
, false) != ATTR_OKAY
) {
935 } else if (strcmp16(block
.getElementName(&len
), provider16
.string()) == 0) {
936 if (validateAttr(manifestPath
, block
, RESOURCES_ANDROID_NAMESPACE
, "name",
937 classIdentChars
, true) != ATTR_OKAY
) {
940 if (validateAttr(manifestPath
, block
,
941 RESOURCES_ANDROID_NAMESPACE
, "authorities",
942 authoritiesIdentChars
, true) != ATTR_OKAY
) {
945 if (validateAttr(manifestPath
, block
,
946 RESOURCES_ANDROID_NAMESPACE
, "permission",
947 packageIdentChars
, false) != ATTR_OKAY
) {
950 if (validateAttr(manifestPath
, block
,
951 RESOURCES_ANDROID_NAMESPACE
, "process",
952 processIdentChars
, false) != ATTR_OKAY
) {
955 } else if (strcmp16(block
.getElementName(&len
), service16
.string()) == 0
956 || strcmp16(block
.getElementName(&len
), receiver16
.string()) == 0
957 || strcmp16(block
.getElementName(&len
), activity16
.string()) == 0) {
958 if (validateAttr(manifestPath
, block
, RESOURCES_ANDROID_NAMESPACE
, "name",
959 classIdentChars
, true) != ATTR_OKAY
) {
962 if (validateAttr(manifestPath
, block
,
963 RESOURCES_ANDROID_NAMESPACE
, "permission",
964 packageIdentChars
, false) != ATTR_OKAY
) {
967 if (validateAttr(manifestPath
, block
,
968 RESOURCES_ANDROID_NAMESPACE
, "process",
969 processIdentChars
, false) != ATTR_OKAY
) {
972 if (validateAttr(manifestPath
, block
,
973 RESOURCES_ANDROID_NAMESPACE
, "taskAffinity",
974 processIdentChars
, false) != ATTR_OKAY
) {
977 } else if (strcmp16(block
.getElementName(&len
), action16
.string()) == 0
978 || strcmp16(block
.getElementName(&len
), category16
.string()) == 0) {
979 if (validateAttr(manifestPath
, block
,
980 RESOURCES_ANDROID_NAMESPACE
, "name",
981 packageIdentChars
, true) != ATTR_OKAY
) {
984 } else if (strcmp16(block
.getElementName(&len
), data16
.string()) == 0) {
985 if (validateAttr(manifestPath
, block
,
986 RESOURCES_ANDROID_NAMESPACE
, "mimeType",
987 typeIdentChars
, true) != ATTR_OKAY
) {
990 if (validateAttr(manifestPath
, block
,
991 RESOURCES_ANDROID_NAMESPACE
, "scheme",
992 schemeIdentChars
, true) != ATTR_OKAY
) {
999 if (table
.validateLocalizations()) {
1004 return UNKNOWN_ERROR
;
1007 // Generate final compiled manifest file.
1008 manifestFile
->clearData();
1009 err
= compileXmlFile(assets
, manifestFile
, &table
);
1010 if (err
< NO_ERROR
) {
1015 //printXMLBlock(&block);
1017 // --------------------------------------------------------------
1018 // Generate the final resource table.
1019 // Re-flatten because we may have added new resource IDs
1020 // --------------------------------------------------------------
1022 if (table
.hasResources()) {
1023 sp
<AaptSymbols
> symbols
= assets
->getSymbolsFor(String8("R"));
1024 err
= table
.addSymbols(symbols
);
1025 if (err
< NO_ERROR
) {
1029 sp
<AaptFile
> resFile(getResourceFile(assets
));
1030 if (resFile
== NULL
) {
1031 fprintf(stderr
, "Error: unable to generate entry for resource data\n");
1032 return UNKNOWN_ERROR
;
1035 err
= table
.flatten(bundle
, resFile
);
1036 if (err
< NO_ERROR
) {
1040 if (bundle
->getPublicOutputFile()) {
1041 FILE* fp
= fopen(bundle
->getPublicOutputFile(), "w+");
1043 fprintf(stderr
, "ERROR: Unable to open public definitions output file %s: %s\n",
1044 (const char*)bundle
->getPublicOutputFile(), strerror(errno
));
1045 return UNKNOWN_ERROR
;
1047 if (bundle
->getVerbose()) {
1048 printf(" Writing public definitions to %s.\n", bundle
->getPublicOutputFile());
1050 table
.writePublicDefinitions(String16(assets
->getPackage()), fp
);
1056 rt
.add(resFile
->getData(), resFile
->getSize(), NULL
);
1057 printf("Generated resources:\n");
1061 // These resources are now considered to be a part of the included
1062 // resources, for others to reference.
1063 err
= assets
->addIncludedResources(resFile
);
1064 if (err
< NO_ERROR
) {
1065 fprintf(stderr
, "ERROR: Unable to parse generated resources, aborting.\n");
1072 static const char* getIndentSpace(int indent
)
1074 static const char whitespace
[] =
1077 return whitespace
+ sizeof(whitespace
) - 1 - indent
*4;
1080 static status_t
fixupSymbol(String16
* inoutSymbol
)
1082 inoutSymbol
->replaceAll('.', '_');
1083 inoutSymbol
->replaceAll(':', '_');
1087 static String16
getAttributeComment(const sp
<AaptAssets
>& assets
,
1088 const String8
& name
,
1089 String16
* outTypeComment
= NULL
)
1091 sp
<AaptSymbols
> asym
= assets
->getSymbolsFor(String8("R"));
1093 //printf("Got R symbols!\n");
1094 asym
= asym
->getNestedSymbols().valueFor(String8("attr"));
1096 //printf("Got attrs symbols! comment %s=%s\n",
1097 // name.string(), String8(asym->getComment(name)).string());
1098 if (outTypeComment
!= NULL
) {
1099 *outTypeComment
= asym
->getTypeComment(name
);
1101 return asym
->getComment(name
);
1107 static status_t
writeLayoutClasses(
1108 FILE* fp
, const sp
<AaptAssets
>& assets
,
1109 const sp
<AaptSymbols
>& symbols
, int indent
, bool includePrivate
)
1111 const char* indentStr
= getIndentSpace(indent
);
1112 if (!includePrivate
) {
1113 fprintf(fp
, "%s/** @doconly */\n", indentStr
);
1115 fprintf(fp
, "%spublic static final class styleable {\n", indentStr
);
1118 String16
attr16("attr");
1119 String16
package16(assets
->getPackage());
1121 indentStr
= getIndentSpace(indent
);
1122 bool hasErrors
= false;
1125 size_t N
= symbols
->getNestedSymbols().size();
1126 for (i
=0; i
<N
; i
++) {
1127 sp
<AaptSymbols
> nsymbols
= symbols
->getNestedSymbols().valueAt(i
);
1128 String16
nclassName16(symbols
->getNestedSymbols().keyAt(i
));
1129 String8
realClassName(nclassName16
);
1130 if (fixupSymbol(&nclassName16
) != NO_ERROR
) {
1133 String8
nclassName(nclassName16
);
1135 SortedVector
<uint32_t> idents
;
1136 Vector
<uint32_t> origOrder
;
1137 Vector
<bool> publicFlags
;
1140 size_t NA
= nsymbols
->getSymbols().size();
1141 for (a
=0; a
<NA
; a
++) {
1142 const AaptSymbolEntry
& sym(nsymbols
->getSymbols().valueAt(a
));
1143 int32_t code
= sym
.typeCode
== AaptSymbolEntry::TYPE_INT32
1145 bool isPublic
= true;
1147 String16
name16(sym
.name
);
1148 uint32_t typeSpecFlags
;
1149 code
= assets
->getIncludedResources().identifierForName(
1150 name16
.string(), name16
.size(),
1151 attr16
.string(), attr16
.size(),
1152 package16
.string(), package16
.size(), &typeSpecFlags
);
1154 fprintf(stderr
, "ERROR: In <declare-styleable> %s, unable to find attribute %s\n",
1155 nclassName
.string(), sym
.name
.string());
1158 isPublic
= (typeSpecFlags
&ResTable_typeSpec::SPEC_PUBLIC
) != 0;
1161 origOrder
.add(code
);
1162 publicFlags
.add(isPublic
);
1167 String16 comment
= symbols
->getComment(realClassName
);
1168 fprintf(fp
, "%s/** ", indentStr
);
1169 if (comment
.size() > 0) {
1170 fprintf(fp
, "%s\n", String8(comment
).string());
1172 fprintf(fp
, "Attributes that can be used with a %s.\n", nclassName
.string());
1174 bool hasTable
= false;
1175 for (a
=0; a
<NA
; a
++) {
1176 ssize_t pos
= idents
.indexOf(origOrder
.itemAt(a
));
1181 "%s <p>Includes the following attributes:</p>\n"
1182 "%s <table border=\"2\" width=\"85%%\" align=\"center\" frame=\"hsides\" rules=\"all\" cellpadding=\"5\">\n"
1183 "%s <colgroup align=\"left\" />\n"
1184 "%s <colgroup align=\"left\" />\n"
1185 "%s <tr><th>Attribute<th>Summary</tr>\n",
1192 const AaptSymbolEntry
& sym
= nsymbols
->getSymbols().valueAt(a
);
1193 if (!publicFlags
.itemAt(a
) && !includePrivate
) {
1196 String8
name8(sym
.name
);
1197 String16
comment(sym
.comment
);
1198 if (comment
.size() <= 0) {
1199 comment
= getAttributeComment(assets
, name8
);
1201 if (comment
.size() > 0) {
1202 const char16_t* p
= comment
.string();
1203 while (*p
!= 0 && *p
!= '.') {
1205 while (*p
!= 0 && *p
!= '}') {
1215 comment
= String16(comment
.string(), p
-comment
.string());
1217 String16
name(name8
);
1219 fprintf(fp
, "%s <tr><th><code>{@link #%s_%s %s:%s}</code><td>%s</tr>\n",
1220 indentStr
, nclassName
.string(),
1221 String8(name
).string(),
1222 assets
->getPackage().string(),
1223 String8(name
).string(),
1224 String8(comment
).string());
1228 fprintf(fp
, "%s </table>\n", indentStr
);
1230 for (a
=0; a
<NA
; a
++) {
1231 ssize_t pos
= idents
.indexOf(origOrder
.itemAt(a
));
1233 const AaptSymbolEntry
& sym
= nsymbols
->getSymbols().valueAt(a
);
1234 if (!publicFlags
.itemAt(a
) && !includePrivate
) {
1237 String16
name(sym
.name
);
1239 fprintf(fp
, "%s @see #%s_%s\n",
1240 indentStr
, nclassName
.string(),
1241 String8(name
).string());
1244 fprintf(fp
, "%s */\n", getIndentSpace(indent
));
1247 "%spublic static final int[] %s = {\n"
1249 indentStr
, nclassName
.string(),
1250 getIndentSpace(indent
+1));
1252 for (a
=0; a
<NA
; a
++) {
1255 fprintf(fp
, ",\n%s", getIndentSpace(indent
+1));
1260 fprintf(fp
, "0x%08x", idents
[a
]);
1263 fprintf(fp
, "\n%s};\n", indentStr
);
1265 for (a
=0; a
<NA
; a
++) {
1266 ssize_t pos
= idents
.indexOf(origOrder
.itemAt(a
));
1268 const AaptSymbolEntry
& sym
= nsymbols
->getSymbols().valueAt(a
);
1269 if (!publicFlags
.itemAt(a
) && !includePrivate
) {
1272 String8
name8(sym
.name
);
1273 String16
comment(sym
.comment
);
1274 String16 typeComment
;
1275 if (comment
.size() <= 0) {
1276 comment
= getAttributeComment(assets
, name8
, &typeComment
);
1278 getAttributeComment(assets
, name8
, &typeComment
);
1280 String16
name(name8
);
1281 if (fixupSymbol(&name
) != NO_ERROR
) {
1285 uint32_t typeSpecFlags
= 0;
1286 String16
name16(sym
.name
);
1287 assets
->getIncludedResources().identifierForName(
1288 name16
.string(), name16
.size(),
1289 attr16
.string(), attr16
.size(),
1290 package16
.string(), package16
.size(), &typeSpecFlags
);
1291 //printf("%s:%s/%s: 0x%08x\n", String8(package16).string(),
1292 // String8(attr16).string(), String8(name16).string(), typeSpecFlags);
1293 const bool pub
= (typeSpecFlags
&ResTable_typeSpec::SPEC_PUBLIC
) != 0;
1295 fprintf(fp
, "%s/**\n", indentStr
);
1296 if (comment
.size() > 0) {
1297 fprintf(fp
, "%s <p>\n%s @attr description\n", indentStr
, indentStr
);
1298 fprintf(fp
, "%s %s\n", indentStr
, String8(comment
).string());
1301 "%s <p>This symbol is the offset where the {@link %s.R.attr#%s}\n"
1302 "%s attribute's value can be found in the {@link #%s} array.\n",
1304 pub
? assets
->getPackage().string()
1305 : assets
->getSymbolsPrivatePackage().string(),
1306 String8(name
).string(),
1307 indentStr
, nclassName
.string());
1309 if (typeComment
.size() > 0) {
1310 fprintf(fp
, "\n\n%s %s\n", indentStr
, String8(typeComment
).string());
1312 if (comment
.size() > 0) {
1315 "%s <p>This corresponds to the global attribute"
1316 "%s resource symbol {@link %s.R.attr#%s}.\n",
1317 indentStr
, indentStr
,
1318 assets
->getPackage().string(),
1319 String8(name
).string());
1322 "%s <p>This is a private symbol.\n", indentStr
);
1325 fprintf(fp
, "%s @attr name %s:%s\n", indentStr
,
1326 "android", String8(name
).string());
1327 fprintf(fp
, "%s*/\n", indentStr
);
1329 "%spublic static final int %s_%s = %d;\n",
1330 indentStr
, nclassName
.string(),
1331 String8(name
).string(), (int)pos
);
1337 fprintf(fp
, "%s};\n", getIndentSpace(indent
));
1338 return hasErrors
? UNKNOWN_ERROR
: NO_ERROR
;
1341 static status_t
writeSymbolClass(
1342 FILE* fp
, const sp
<AaptAssets
>& assets
, bool includePrivate
,
1343 const sp
<AaptSymbols
>& symbols
, const String8
& className
, int indent
)
1345 fprintf(fp
, "%spublic %sfinal class %s {\n",
1346 getIndentSpace(indent
),
1347 indent
!= 0 ? "static " : "", className
.string());
1351 status_t err
= NO_ERROR
;
1353 size_t N
= symbols
->getSymbols().size();
1354 for (i
=0; i
<N
; i
++) {
1355 const AaptSymbolEntry
& sym
= symbols
->getSymbols().valueAt(i
);
1356 if (sym
.typeCode
!= AaptSymbolEntry::TYPE_INT32
) {
1359 if (!includePrivate
&& !sym
.isPublic
) {
1362 String16
name(sym
.name
);
1363 String8
realName(name
);
1364 if (fixupSymbol(&name
) != NO_ERROR
) {
1365 return UNKNOWN_ERROR
;
1367 String16
comment(sym
.comment
);
1368 bool haveComment
= false;
1369 if (comment
.size() > 0) {
1373 getIndentSpace(indent
), String8(comment
).string());
1374 } else if (sym
.isPublic
&& !includePrivate
) {
1375 sym
.sourcePos
.warning("No comment for public symbol %s:%s/%s",
1376 assets
->getPackage().string(), className
.string(),
1377 String8(sym
.name
).string());
1379 String16
typeComment(sym
.typeComment
);
1380 if (typeComment
.size() > 0) {
1385 getIndentSpace(indent
), String8(typeComment
).string());
1389 getIndentSpace(indent
), String8(typeComment
).string());
1393 fprintf(fp
,"%s */\n", getIndentSpace(indent
));
1395 fprintf(fp
, "%spublic static final int %s=0x%08x;\n",
1396 getIndentSpace(indent
),
1397 String8(name
).string(), (int)sym
.int32Val
);
1400 for (i
=0; i
<N
; i
++) {
1401 const AaptSymbolEntry
& sym
= symbols
->getSymbols().valueAt(i
);
1402 if (sym
.typeCode
!= AaptSymbolEntry::TYPE_STRING
) {
1405 if (!includePrivate
&& !sym
.isPublic
) {
1408 String16
name(sym
.name
);
1409 if (fixupSymbol(&name
) != NO_ERROR
) {
1410 return UNKNOWN_ERROR
;
1412 String16
comment(sym
.comment
);
1413 if (comment
.size() > 0) {
1417 getIndentSpace(indent
), String8(comment
).string(),
1418 getIndentSpace(indent
));
1419 } else if (sym
.isPublic
&& !includePrivate
) {
1420 sym
.sourcePos
.warning("No comment for public symbol %s:%s/%s",
1421 assets
->getPackage().string(), className
.string(),
1422 String8(sym
.name
).string());
1424 fprintf(fp
, "%spublic static final String %s=\"%s\";\n",
1425 getIndentSpace(indent
),
1426 String8(name
).string(), sym
.stringVal
.string());
1429 sp
<AaptSymbols
> styleableSymbols
;
1431 N
= symbols
->getNestedSymbols().size();
1432 for (i
=0; i
<N
; i
++) {
1433 sp
<AaptSymbols
> nsymbols
= symbols
->getNestedSymbols().valueAt(i
);
1434 String8
nclassName(symbols
->getNestedSymbols().keyAt(i
));
1435 if (nclassName
== "styleable") {
1436 styleableSymbols
= nsymbols
;
1438 err
= writeSymbolClass(fp
, assets
, includePrivate
, nsymbols
, nclassName
, indent
);
1440 if (err
!= NO_ERROR
) {
1445 if (styleableSymbols
!= NULL
) {
1446 err
= writeLayoutClasses(fp
, assets
, styleableSymbols
, indent
, includePrivate
);
1447 if (err
!= NO_ERROR
) {
1453 fprintf(fp
, "%s}\n", getIndentSpace(indent
));
1457 status_t
writeResourceSymbols(Bundle
* bundle
, const sp
<AaptAssets
>& assets
,
1458 const String8
& package
, bool includePrivate
)
1460 if (!bundle
->getRClassDir()) {
1464 const size_t N
= assets
->getSymbols().size();
1465 for (size_t i
=0; i
<N
; i
++) {
1466 sp
<AaptSymbols
> symbols
= assets
->getSymbols().valueAt(i
);
1467 String8
className(assets
->getSymbols().keyAt(i
));
1468 String8
dest(bundle
->getRClassDir());
1469 if (bundle
->getMakePackageDirs()) {
1470 String8
pkg(package
);
1471 const char* last
= pkg
.string();
1472 const char* s
= last
-1;
1475 if (s
> last
&& (*s
== '.' || *s
== 0)) {
1476 String8
part(last
, s
-last
);
1477 dest
.appendPath(part
);
1478 #ifdef HAVE_MS_C_RUNTIME
1479 _mkdir(dest
.string());
1481 mkdir(dest
.string(), S_IRUSR
|S_IWUSR
|S_IXUSR
|S_IRGRP
|S_IXGRP
);
1487 dest
.appendPath(className
);
1488 dest
.append(".java");
1489 FILE* fp
= fopen(dest
.string(), "w+");
1491 fprintf(stderr
, "ERROR: Unable to open class file %s: %s\n",
1492 dest
.string(), strerror(errno
));
1493 return UNKNOWN_ERROR
;
1495 if (bundle
->getVerbose()) {
1496 printf(" Writing symbols for class %s.\n", className
.string());
1500 "/* AUTO-GENERATED FILE. DO NOT MODIFY.\n"
1502 " * This class was automatically generated by the\n"
1503 " * aapt tool from the resource data it found. It\n"
1504 " * should not be modified by hand.\n"
1507 "package %s;\n\n", package
.string());
1509 status_t err
= writeSymbolClass(fp
, assets
, includePrivate
, symbols
, className
, 0);
1510 if (err
!= NO_ERROR
) {