Commit 66c4141a authored by Yann Dago's avatar Yann Dago Committed by Commit Bot

Add a presentation section in the generated appconfig.xml file

Bug: 1128264
Change-Id: I87382bc3acfcde44a0695994088d7b550dc837cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2559258Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Commit-Queue: Yann Dago <ydago@chromium.org>
Cr-Commit-Position: refs/heads/master@{#831091}
parent b1d6a66b
......@@ -19,6 +19,39 @@ class IOSAppConfigWriter(xml_formatted_writer.XMLFormattedWriter):
'''Simple writer that writes app_config.xml files.
'''
def _WritePolicyPresentation(self, policy, field_group):
element_type = self.policy_type_to_input_type[policy['type']]
if element_type:
attributes = {'type': element_type, 'keyName': policy['name']}
field = self.AddElement(field_group, 'field', attributes)
self._AddLocalizedElement(field, 'label', policy['caption'])
self._AddLocalizedElement(field, 'description', policy['desc'])
def _AddLocalizedElement(self,
parent,
element_type,
text,
localization={'value': 'en-US'}):
item = self.AddElement(parent, element_type, {})
localized = self.AddElement(item, 'language', localization)
self.AddText(localized, text)
def _WritePresentation(self, policy_list):
groups = [policy for policy in policy_list if policy['type'] == 'group']
policies_without_group = [
policy for policy in policy_list if policy['type'] != 'group'
]
for policy in groups:
child_policies = self._GetPoliciesForWriter(policy)
if child_policies:
field_group = self.AddElement(self._presentation, 'fieldGroup', {})
self._AddLocalizedElement(field_group, 'name', policy['caption'])
for child_policy in child_policies:
self._WritePolicyPresentation(child_policy, field_group)
for policy in self._GetPoliciesForWriter(
{'policies': policies_without_group}):
self._WritePolicyPresentation(policy, self._presentation)
def IsFuturePolicySupported(self, policy):
# For now, include all future policies in appconfig.xml.
return True
......@@ -28,6 +61,18 @@ class IOSAppConfigWriter(xml_formatted_writer.XMLFormattedWriter):
return dom_impl.createDocument('http://www.w3.org/2001/XMLSchema-instance',
'managedAppConfiguration', None)
def WriteTemplate(self, template):
self.messages = template['messages']
self.Init()
template['policy_definitions'] = \
self.PreprocessPolicies(template['policy_definitions'])
self.BeginTemplate()
self.WritePolicies(template['policy_definitions'])
self._WritePresentation(template['policy_definitions'])
self.EndTemplate()
return self.GetTemplateText()
def BeginTemplate(self):
self._app_config.attributes[
'xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance'
......@@ -41,6 +86,8 @@ class IOSAppConfigWriter(xml_formatted_writer.XMLFormattedWriter):
bundle_id = self.AddElement(self._app_config, 'bundleId', {})
self.AddText(bundle_id, self.config['bundle_id'])
self._policies = self.AddElement(self._app_config, 'dict', {})
self._presentation = self.AddElement(self._app_config, 'presentation',
{'defaultLocale': 'en-US'})
def WritePolicy(self, policy):
element_type = self.policy_type_to_xml_tag[policy['type']]
......@@ -66,6 +113,16 @@ class IOSAppConfigWriter(xml_formatted_writer.XMLFormattedWriter):
'list': 'stringArray',
'dict': 'string',
}
self.policy_type_to_input_type = {
'string': 'input',
'int': 'input',
'int-enum': 'select',
'string-enum': 'select',
'string-enum-list': 'multiselect',
'main': 'checkbox',
'list': 'list',
'dict': 'input'
}
def GetTemplateText(self):
return self.ToPrettyXml(self._doc)
......@@ -262,7 +262,35 @@ class TemplateWriter(object):
template['policy_definitions'] = \
self.PreprocessPolicies(template['policy_definitions'])
self.BeginTemplate()
for policy in template['policy_definitions']:
self.WritePolicies(template['policy_definitions'])
self.EndTemplate()
return self.GetTemplateText()
def PreprocessPolicies(self, policy_list):
'''Preprocesses a list of policies according to a given writer's needs.
Preprocessing steps include sorting policies and stripping unneeded
information such as groups (for writers that ignore them).
Subclasses are encouraged to override this method, overriding
implementations may call one of the provided specialized implementations.
The default behaviour is to use SortPoliciesGroupsFirst().
Args:
policy_list: A list containing the policies to sort.
Returns:
The sorted policy list.
'''
return self.SortPoliciesGroupsFirst(policy_list)
def WritePolicies(self, policy_list):
'''Appends the template text corresponding to all the policies into the
internal buffer.
Args:
policy_list: A list containing the policies to write.
'''
for policy in policy_list:
if policy['type'] == 'group':
child_policies = self._GetPoliciesForWriter(policy)
child_recommended_policies = filter(self.CanBeRecommended,
......@@ -283,25 +311,6 @@ class TemplateWriter(object):
self.WritePolicy(policy)
if self.CanBeRecommended(policy):
self.WriteRecommendedPolicy(policy)
self.EndTemplate()
return self.GetTemplateText()
def PreprocessPolicies(self, policy_list):
'''Preprocesses a list of policies according to a given writer's needs.
Preprocessing steps include sorting policies and stripping unneeded
information such as groups (for writers that ignore them).
Subclasses are encouraged to override this method, overriding
implementations may call one of the provided specialized implementations.
The default behaviour is to use SortPoliciesGroupsFirst().
Args:
policy_list: A list containing the policies to sort.
Returns:
The sorted policy list.
'''
return self.SortPoliciesGroupsFirst(policy_list)
def WritePolicy(self, policy):
'''Appends the template text corresponding to a policy into the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment