الخميس، 24 يوليو 2014

Language XSLT (Android)

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:string="http://www.getsymphony.com/functions"
>
  <xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes" />
  <xsl:strip-space elements="*"/>
  <xsl:param name="fname">D:\1_6_2014\Android\camera\res\layout\mainpage.xml</xsl:param>


  <xsl:template match="/*">

    <xsl:apply-templates select="Member_NamespaceDeclaration" mode="package"/>
    <xsl:text>import edu.icpmd.*;</xsl:text>
    <xsl:text>&#xa;</xsl:text>
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="Member_UsingDeclaration">
    <xsl:text>import </xsl:text>
    <xsl:value-of select="concat(@Namespace,';')"/>
    <xsl:text>&#xa;</xsl:text>
  </xsl:template>

  <xsl:template match="Member_NamespaceDeclaration" mode="package">
    <xsl:text>package </xsl:text>
    <xsl:value-of select="concat(concat('edu.icpmd.',@Name),';')"/>
    <xsl:text>&#xa;</xsl:text>
    <xsl:text>&#xa;</xsl:text>
  </xsl:template>

  <xsl:template match="Member_NamespaceDeclaration">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="token">
    <xsl:choose>
      <xsl:when test="@value ='{'">
        <xsl:choose>
          <xsl:when test="parent::Member_NamespaceDeclaration">
            <xsl:text>&#xa;</xsl:text>
          </xsl:when>

          <xsl:when test="parent::Member_TypeDeclaration and ../@ClassType='Class'">
            <xsl:text>&#xa;</xsl:text>{<xsl:text>&#xa;</xsl:text>

            <xsl:call-template name="controls_def"/>

            <xsl:text>
@Override
protected void onCreate(Bundle savedInstanceState) 
{
super.onCreate(savedInstanceState);
</xsl:text>

            <xsl:text>setContentView(R.layout.</xsl:text>
            <xsl:value-of select="concat(translate(../@Name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),')')" />

            <xsl:text>;</xsl:text>
            <xsl:call-template name="controls"/>
            <xsl:text>
}&#xa;&#xa;</xsl:text>
          </xsl:when>

          <xsl:otherwise>
            <xsl:text>&#xa;</xsl:text>{<xsl:text>&#xa;</xsl:text>


          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>

      <xsl:when test="@value ='}'">
        <xsl:choose>
          <xsl:when test="parent::Member_NamespaceDeclaration">
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>&#xa;</xsl:text>}<xsl:text>&#xa;</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>

      <xsl:when test="@value ='.'">
        <xsl:choose>
          <xsl:when test="parent::Import_MemberType">
          </xsl:when>
          <xsl:otherwise>.</xsl:otherwise>
        </xsl:choose>
      </xsl:when>

      <xsl:when test="@value =':'">
        <xsl:choose>
          <xsl:when test="parent::Member_TypeDeclaration">
            <xsl:value-of select="concat(' extends',' ')"/>
          </xsl:when>
          <xsl:otherwise>:</xsl:otherwise>
        </xsl:choose>
      </xsl:when>

      <xsl:when test="@value =';'">
        ;<xsl:text>&#xa;</xsl:text>
      </xsl:when>
      <xsl:when test="@value ='='">=</xsl:when>
      <xsl:when test="@value =','">
        <xsl:choose>
          <xsl:when xmlns:android="http://schemas.android.com/apk/res/android" test="document($fname)//@android:onClick =../@Name">
            <xsl:text>View arg0</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            ,
          </xsl:otherwise>
        </xsl:choose>

      </xsl:when>
      <xsl:when test="@value ='('">(</xsl:when>
      <xsl:when test="@value =')'">)</xsl:when>
      <xsl:otherwise></xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="Member_TypeDeclaration">
    <xsl:choose>
      <xsl:when test="@ClassType='Class'">
        <!--
<xsl:value-of select="concat(concat(concat(Modifier_CSharpModifierToken/@Modifier,' class '),@Name),concat(' extends ' , BaseType_SimpleType/@Identifier))"/>
-->
      </xsl:when>
      <xsl:otherwise></xsl:otherwise>
    </xsl:choose>


    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="TypeMember_ConstructorDeclaration">
    <!--
<xsl:value-of select="concat(concat(concat(Modifier_CSharpModifierToken/@Modifier,' '),' '), Identifier_Identifier/@Name)"/>
-->
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="TypeMember_MethodDeclaration">
    <!--
<xsl:value-of select="concat(concat(concat(Modifier_CSharpModifierToken/@Modifier,' '),' '), Identifier_Identifier/@Name)"/>
-->

    <xsl:apply-templates />

  </xsl:template>



  <xsl:template match="Modifier_CSharpModifierToken">
    <xsl:choose>
      <xsl:when xmlns:android="http://schemas.android.com/apk/res/android" test="document($fname)//@android:onClick =../@Name">
        <xsl:value-of select="translate(concat(translate(@Modifier,'Private','public'),' '),'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
      </xsl:when>
      <xsl:when xmlns:android="http://schemas.android.com/apk/res/android" test="document($fname)//@android:onClick !=../@Name">
        <xsl:value-of select="translate(concat(@Modifier,' '),'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>

      </xsl:when>
    </xsl:choose>

  </xsl:template>

  <xsl:template match="class_CSharpTokenNode">
    <xsl:value-of select="concat('class',' ')"/>
  </xsl:template>

  <xsl:template match="BaseType_SimpleType">

    <xsl:choose>
      <xsl:when test="@Identifier='PhoneApplicationPage'">
        <xsl:text>Activity</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="@Name"/>

      </xsl:otherwise>
    </xsl:choose>
    <!--<xsl:value-of select="concat(' ', @Identifier)"/>-->
  </xsl:template>

  <xsl:template match="Identifier_Identifier">
    <xsl:choose>
      <xsl:when test="parent::Member_NamespaceDeclaration">
      </xsl:when>
      <xsl:when test="@Name='Text'">
        <xsl:text>getText().toString()</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="@Name"/>

      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="Type_PrimitiveType">
    <xsl:value-of select="concat(@Keyword,' ')"/>

  </xsl:template>

  <xsl:template match="Variable_VariableInitializer">
    <xsl:value-of select="@Name"/>
  </xsl:template>
  <xsl:template match="Left_IdentifierExpression">
    <xsl:value-of select="@Identifier"/>
  </xsl:template>

  <xsl:template match="Parameter_ParameterDeclaration">
    <xsl:choose>
      <xsl:when xmlns:android="http://schemas.android.com/apk/res/android" test="document($fname)//@android:onClick =../@Name">

      </xsl:when>
      <xsl:when xmlns:android="http://schemas.android.com/apk/res/android" test="document($fname)//@android:onClick !=../@Name">
        <xsl:apply-templates/>
      </xsl:when>
    </xsl:choose>
    <!--
<xsl:choose>
<xsl:when test="$event_name=string(.)">
<xsl:variable name="fevent" select="1" />

<xsl:call-template name="controls_event">
<xsl:with-param name="event_name" select="../@Name"/>
</xsl:call-template>-->
    <!--<xsl:value-of select="$fevent"/>-->
    <!--<xsl:if test="$fevent=1">
<xsl:apply-templates/>
</xsl:if>-->
  </xsl:template>


  <xsl:template match="Right_MemberReferenceExpression">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="Statement_ExpressionStatement">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="Expression_AssignmentExpression">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="Type_SimpleType">
    <xsl:value-of select="concat(@Identifier, ' ')"/>
  </xsl:template>



  <xsl:template match="Statement_VariableDeclarationStatement">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="ICPMD_Webview_load">
    <xsl:text>&#xa;</xsl:text>
    <xsl:text>functions.webview_load(</xsl:text>
    <xsl:value-of select="mywebview"/>
    <xsl:text>, </xsl:text>
    <xsl:value-of select="url"/>
    <xsl:text>);</xsl:text>
    <xsl:text>&#xa;</xsl:text>

  </xsl:template>

  <!--
<xsl:template match="*/text()[normalize-space()]">
    <xsl:value-of select="normalize-space()"/>
</xsl:template>

<xsl:template match="*/text()[not(normalize-space())]" />-->

  <xsl:template name="controls_def">

    <xsl:for-each xmlns:android="http://schemas.android.com/apk/res/android" select="document($fname)//@android:id">
      <xsl:value-of select="concat(name(..),' ')"/>
      <xsl:value-of select="concat(substring(string(.),6),';')"/>
      <xsl:text>&#xa;</xsl:text>
    </xsl:for-each>
  </xsl:template>

  <xsl:template name="controls">
    <xsl:text>&#xa;</xsl:text>
    <xsl:for-each xmlns:android="http://schemas.android.com/apk/res/android" select="document($fname)//@android:id">

      <xsl:value-of select="concat(substring(string(.),6),' = ')"/>
      <xsl:value-of select="concat('(',name(..),') ')"/>
      <xsl:value-of select="concat('findViewById(R.id.',substring(string(.),6),')',';') "/>

      <xsl:text>&#xa;</xsl:text>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="ICPMD_Camera_app_open">
    <xsl:text>functions.camera_app_open(this,0);</xsl:text>
  </xsl:template>


  <xsl:template match="ICPMD_Camera_app_result">
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    functions.camera_app_result(this, resultCode, <xsl:value-of select="myimage"/>, data);


    }



  </xsl:template>

</xsl:stylesheet>

ليست هناك تعليقات:

إرسال تعليق