From: <abo...@us...> - 2009-11-05 06:45:32
|
Revision: 3852 http://synce.svn.sourceforge.net/synce/?rev=3852&view=rev Author: abompard Date: 2009-11-05 06:45:15 +0000 (Thu, 05 Nov 2009) Log Message: ----------- Port some task conversion functions to XSL Modified Paths: -------------- trunk/sync-engine/SyncEngine/formats/conversions.py trunk/sync-engine/SyncEngine/formats/task-from-airsync.xsl trunk/sync-engine/SyncEngine/formats/task-to-airsync.xsl trunk/sync-engine/tests/testdata/os2air/airsync_task_complete1.xml Modified: trunk/sync-engine/SyncEngine/formats/conversions.py =================================================================== --- trunk/sync-engine/SyncEngine/formats/conversions.py 2009-11-04 07:13:26 UTC (rev 3851) +++ trunk/sync-engine/SyncEngine/formats/conversions.py 2009-11-05 06:45:15 UTC (rev 3852) @@ -519,93 +519,6 @@ dst_node.newChild(None,"Content",result) return "" -def task_classification_to_airsync(ctx): - parser_ctx, transform_ctx = xml2util.ExtractContexts(ctx) - s = xml2util.GetNodeValue(transform_ctx.current()) - if s == "PRIVATE": - return "2" - elif s == "CONFIDENTIAL": - return "3" - else: - return "0" # 'PUBLIC' is our default value - -def task_classification_from_airsync(ctx): - parser_ctx, transform_ctx = xml2util.ExtractContexts(ctx) - s = xml2util.GetNodeValue(transform_ctx.current()) - if s == "2": - return "PRIVATE" - elif s == "3": - return "CONFIDENTIAL" - else: - return "0" # 'PUBLIC' is our default value - - # We only sync the 'COMPLETED' state here. Evo2 maintains a number of - # different status values for various states of a job except COMPLETED - # and we don't want to clobber these. AirStink seems only to maintain - # the two states: Not Completed and Completed. However, we force - # the PercentComplete field to 100 if the task is marked as completed - -def task_status_from_airsync(ctx): - parser_ctx, transform_ctx = xml2util.ExtractContexts(ctx) - src_node = transform_ctx.current() - s=xml2util.GetNodeValue(transform_ctx.current()) - if s == "1": - base_node = transform_ctx.insertNode() - stat_node = base_node.newChild(None, "Status", None) - stat_node.newChild(None, "Content", "COMPLETED") - pcnt_node = base_node.newChild(None, "PercentComplete", None) - pcnt_node.newChild(None, "Content", "100") - return "" - -def task_status_to_airsync(ctx): - parser_ctx, transform_ctx = xml2util.ExtractContexts(ctx) - curnode = transform_ctx.current() - s=xml2util.GetNodeValue(curnode) - if s == "COMPLETED": - return "1" - else: - # check that PercentComplete == 100% - mark it completed if - # this is the case. - up = xml2util.FindChildNode(curnode.parent,"PercentComplete") - if up != None: - ct = xml2util.FindChildNode(up,"Content") - if ct != None: - if xml2util.GetNodeValue(ct) == "100": - return "1" - return "0" - -# Here. let us not destroy the 'unspecified' priority when going -# _to_ airsync. We can't really help reassigning this as 'low' -# in the other direction. -# - -def task_prio_to_airsync(ctx): - parser_ctx, transform_ctx = xml2util.ExtractContexts(ctx) - d = "0" - s=xml2util.GetNodeValue(transform_ctx.current()) - if s > "0": - if s == "7": - d = "0" - elif s == "5": - d = "1" - elif s == "3": - d = "2" - else: - d = "0" - return d - -def task_prio_from_airsync(ctx): - parser_ctx, transform_ctx = xml2util.ExtractContexts(ctx) - s=xml2util.GetNodeValue(transform_ctx.current()) - if s == "0": - return "7" - elif s == "1": - return "5" - elif s == "2": - return "3" - else: - return "0" # We can use the unspecced one here if we get such an one from Airsync - def all_description_from_airsync(ctx): parser_ctx, transform_ctx = xml2util.ExtractContexts(ctx) src_node = transform_ctx.current() @@ -654,12 +567,6 @@ libxslt.registerExtModuleFunction("task_due_date_to_airsync", "http://synce.org/convert", task_due_date_to_airsync) libxslt.registerExtModuleFunction("task_start_date_from_airsync", "http://synce.org/convert", task_start_date_from_airsync) libxslt.registerExtModuleFunction("task_due_date_from_airsync", "http://synce.org/convert", task_due_date_from_airsync) - libxslt.registerExtModuleFunction("task_classification_from_airsync", "http://synce.org/convert", task_classification_from_airsync) - libxslt.registerExtModuleFunction("task_classification_to_airsync", "http://synce.org/convert", task_classification_to_airsync) - libxslt.registerExtModuleFunction("task_status_from_airsync", "http://synce.org/convert", task_status_from_airsync) - libxslt.registerExtModuleFunction("task_status_to_airsync", "http://synce.org/convert", task_status_to_airsync) - libxslt.registerExtModuleFunction("task_prio_to_airsync", "http://synce.org/convert", task_prio_to_airsync) - libxslt.registerExtModuleFunction("task_prio_from_airsync", "http://synce.org/convert", task_prio_from_airsync) libxslt.registerExtModuleFunction("all_description_to_airsync", "http://synce.org/convert", all_description_to_airsync) libxslt.registerExtModuleFunction("all_description_from_airsync", "http://synce.org/convert", all_description_from_airsync) libxslt.registerExtModuleFunction("all_upper_case", "http://synce.org/convert", all_upper_case) Modified: trunk/sync-engine/SyncEngine/formats/task-from-airsync.xsl =================================================================== --- trunk/sync-engine/SyncEngine/formats/task-from-airsync.xsl 2009-11-04 07:13:26 UTC (rev 3851) +++ trunk/sync-engine/SyncEngine/formats/task-from-airsync.xsl 2009-11-05 06:45:15 UTC (rev 3852) @@ -71,13 +71,39 @@ </xsl:template> <xsl:template match="T:Complete"> - <xsl:value-of select="convert:task_status_from_airsync()"/> + <!-- + We only sync the 'COMPLETED' state here. Evo2 maintains a number of + different status values for various states of a job except COMPLETED + and we don't want to clobber these. AirStink seems only to maintain + the two states: Not Completed and Completed. However, we force + the PercentComplete field to 100 if the task is marked as completed + --> + <xsl:if test="string(.) = '1'"> + <Status><Content>COMPLETED</Content></Status> + <PercentComplete><Content>100</Content></PercentComplete> + </xsl:if> </xsl:template> <xsl:template match="T:Importance"> - <Priority><Content><xsl:value-of select="convert:task_prio_from_airsync()"/></Content></Priority> + <Priority><Content> + <xsl:choose> + <xsl:when test="string(.) = '0'"> + <xsl:text>7</xsl:text> + </xsl:when> + <xsl:when test="string(.) = '1'"> + <xsl:text>5</xsl:text> + </xsl:when> + <xsl:when test="string(.) = '2'"> + <xsl:text>3</xsl:text> + </xsl:when> + <xsl:otherwise> + <!-- We can use the unspecced one here if we get such an one from Airsync --> + <xsl:text>0</xsl:text> + </xsl:otherwise> + </xsl:choose> + </Content></Priority> </xsl:template> - + <xsl:template match="T:Rtf"> <Description><Content><xsl:value-of select="convert:all_description_from_airsync()"/></Content></Description> </xsl:template> Modified: trunk/sync-engine/SyncEngine/formats/task-to-airsync.xsl =================================================================== --- trunk/sync-engine/SyncEngine/formats/task-to-airsync.xsl 2009-11-04 07:13:26 UTC (rev 3851) +++ trunk/sync-engine/SyncEngine/formats/task-to-airsync.xsl 2009-11-05 06:45:15 UTC (rev 3852) @@ -23,11 +23,17 @@ </xsl:template> <xsl:template match="Status"> - <T:Complete><xsl:value-of select="convert:task_status_to_airsync()"/></T:Complete> + <xsl:if test="not(../PercentComplete) and Content = 'COMPLETED'"> + <T:Complete>1</T:Complete> + </xsl:if> </xsl:template> <xsl:template match="PercentComplete"> - <xsl:if test="not(../Status) and Content = '100'"> + <!-- + When in conflict, PercentComplete wins over Status. + That's an arbitrary decision, it can change if a good reason is found + --> + <xsl:if test="Content = '100'"> <T:Complete>1</T:Complete> </xsl:if> </xsl:template> @@ -37,7 +43,27 @@ </xsl:template> <xsl:template match="Priority"> - <T:Importance><xsl:value-of select="convert:task_prio_to_airsync()"/></T:Importance> + <T:Importance> + <!-- + Here. let us not destroy the 'unspecified' priority when going + _to_ airsync. We can't really help reassigning this as 'low' + in the other direction. + --> + <xsl:choose> + <xsl:when test="string(Content) = '7'"> + <xsl:text>0</xsl:text> + </xsl:when> + <xsl:when test="string(Content) = '5'"> + <xsl:text>1</xsl:text> + </xsl:when> + <xsl:when test="string(Content) = '3'"> + <xsl:text>2</xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:text>0</xsl:text> + </xsl:otherwise> + </xsl:choose> + </T:Importance> </xsl:template> <xsl:template match="RecurrenceRule"> Modified: trunk/sync-engine/tests/testdata/os2air/airsync_task_complete1.xml =================================================================== --- trunk/sync-engine/tests/testdata/os2air/airsync_task_complete1.xml 2009-11-04 07:13:26 UTC (rev 3851) +++ trunk/sync-engine/tests/testdata/os2air/airsync_task_complete1.xml 2009-11-05 06:45:15 UTC (rev 3852) @@ -1,4 +1,3 @@ <AS:ApplicationData xmlns:AS="http://synce.org/formats/airsync_wm5/airsync" xmlns:T="http://synce.org/formats/airsync_wm5/tasks"> <T:Subject>Completeness</T:Subject> - <T:Complete>0</T:Complete> </AS:ApplicationData> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |