<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Rule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Rule_Axmedis.xsd">
  <Header>
    <Rule_Name>resizing_image</Rule_Name>
    <AXRID>1A1bcde</AXRID>
    <Rule_Version>1.0</Rule_Version>
    <Rule_Type>AXCP</Rule_Type>
    <Software_Name>AXMEDIS RULE EDITOR</Software_Name>
    <Version_of_software>1.0</Version_of_software>
    <Date_of_production>2006-01-16</Date_of_production>
    <Author>Ivan Bruno</Author>
    <Affiliation>DISIT</Affiliation>
    <URL>www.dsi.unifi.it</URL>
    <Comment>Example of AXCP Rule for testing JSClasses and functionalities.
The rule generates an AXMEDIS Object with an image and a text resource. The image is resized to the height x width size and the converted into JPEG format.
</Comment>
    <Last_Modifications>2006-05-31</Last_Modifications>
    <Terminal_ID></Terminal_ID>
    <Cost></Cost>
    <Work_Item_ID></Work_Item_ID>
  </Header>
  <Schedule>
    <Run>
      <Date>2006-02-05</Date>
      <Time>11:12:40</Time>
      <Periodicity Unit="Day">0</Periodicity>
      <Expiration_Date>2006-11-18</Expiration_Date>
      <Expiration_Time>16:00:31</Expiration_Time>
    </Run>
    <Status>Active</Status>
  </Schedule>
  <Definition>
    <AXCP_Rule>
      <Arguments>
        <Parameter Name="resourcePath" Type="String">C:\axexamples\ruleditor\resources\</Parameter>
        <Parameter Name="height" Type="Integer">800</Parameter>
        <Parameter Name="width" Type="Integer">600</Parameter>
        <Parameter Name="outputPath" Type="String">C:\axexamples\ruleditor\resources\</Parameter>
        <Parameter Name="mimeType" Type="String">image/jpeg</Parameter>
        <Parameter Name="res1" Type="String">axmedis_logo.png</Parameter>
        <Parameter Name="res2" Type="String">README-Rule-Editor.txt</Parameter>
        <Parameter Name="res3" Type="String">User Guide for AXMEDIS Content Processing Area.pdf</Parameter>
      
      </Arguments>
      <Rule_Body>
        <JS_Script name="JSScript"><![CDATA[/***************************************************************************/
// AXMEDIS JSScript
// This script is provided merely as demonstration tools and provide 
// limited functionalities and robustness with respect to the full tools, 
// and as such should be considered. 
// AXMEDIS declines any responsibility on the use made with the script 
// hereby installed.
// The intellectual property of this script belongs to AXMEDIS, and 
// any total or partial reproduction of it is prohibited 
// without written authorization of AXMEDIS Consortium. 
// AXMEDIS Copyright 2006.

// Please verify the resourcePath value before running the script
// Fix it to the right path (double clicking on the item to open
// the editing dialog
/**************************************************************************/


// Function for creating the Dublin Core information
function createDC(obj)
{
    dc = obj.getDublinCore();
    dc.addDCElement("author","AXCP Rule Editor");
    dc.addDCElement("title",title);
    dc.addDCElement("type","collection");
    dc.addDCElement("description","Testing JSScript with resized and converted image and txt");
}

// Function for creating the Axmedis Object by composing and converting resources
function test()
{

  var  newObj = new AxmedisObject();
  
  // array of resources filename
  var resArray = new Array();
  resArray[0]=res1;
  resArray[1]=res2;
  resArray[2]=res3;
  
  title = "Example";
  createDC(newObj);
  
  print("Embedding resources into Axmedis Object");  
  for(j=0; j<resArray.length; j++)
  {
      var resource = new AxResource()
      resource.load(resourcePath+resArray[j]);
      newObj.addContent(resource);
  }
  
  print("Creating adapted image");   
  var h =  new Array(1);
  var w =  new Array(1);
  h[0]=0;
  w[0]=0;
  res = newObj.getContent();
  for (i=0; i<res.length; i++)
  {
    val = res[i].mimeType.search("image");
	if(val==0)
    {
        ImageProcessing.GetInfo(res[i],h,w);
        print("Original resource size is "+h+"x"+w);
        print("Resizing the resource at "+height+"x"+width);
        ImageProcessing.Resize(res[i],height,width,false,res[i]);
        
        ImageProcessing.GetInfo(res[i],h,w);
        print("New resource size is "+h+"x"+w);
        
        print("Converting the resource in "+mimeType);
        ImageProcessing.Conversion(res[i],mimeType,res[i]);
    }
  }

   print("Storing Object on disk");
       newObj.save(outputPath+title+".axm");
  return true;
  
}

//Entry point of the script
test();]]>
        </JS_Script>
      </Rule_Body>
      <Dependencies>
        <Dependency>
          <Plug_In_name>ImageProcessing</Plug_In_name>
          <Version>1.001</Version>
        </Dependency>
      </Dependencies>
    </AXCP_Rule>
  </Definition>
</Rule>

