<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Jaggery - Delicious Javascript</title>
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
    <!--[if lt IE 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    <!-- Le styles -->
    <link href="../css/bootstrap.css" rel="stylesheet">
    <style type="text/css">
        body {
            padding-top: 60px;
        }
    </style>
    <link href="../css/prettify.css" rel="stylesheet">
    <!-- Le fav and touch icons -->
    <link rel="shortcut icon" href="../images/favicon.ico">
    <link rel="apple-touch-icon" href="../images/apple-touch-icon.png">
    <link rel="apple-touch-icon" sizes="72x72"
          href="../images/apple-touch-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="114x114"
          href="../images/apple-touch-icon-114x114.png">
</head>

<body>

<%
include('/includes/topnavi.jag');
%>

<div class="container-fluid" style="width: 960px; margin: auto;">
    <div class="row">
        <div class="span16">
            <div class="page-header">
                <h1>
                    Documentation
                    <small>API documentation for Jaggery.js</small>
                </h1>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="span4">
            <div class="well">
<%
include('/includes/navi.jag');
%>
            </div>

        </div>
        <div class="span12">
            <div class="content" id="print" name="print">
                <h3>module.xml</h3>

                <p>modules.xml is used to configure the modules that need to be loaded when the server is started up.
                   A module can be a set of JavaScript objects and functions defined either via
                   <a href="http://wso2.org/library/tutorials/writing-custom-hostobject" target="_blank">Rhino Hostobjects</a> or
                   just as *.js files which reside in &lt;JAGGERY_HOME&gt;/modules directory. </p>

                <p>The structure of module.xml is shown below.</p>

<pre class="prettyprint">
&lt;module name=&quot;module_name&quot; namespace=&quot;ns&quot; expose=&quot;true&quot; xmlns=&quot;http://wso2.org/projects/jaggery/module.xml&quot;&gt;
    &lt;!-- Hostobjects --&gt;
    &lt;hostObject readOnly=&quot;true&quot;&gt;
        &lt;className&gt;org.jaggeryjs.hostobjects.xhr.XMLHttpRequest&lt;/className&gt;
        &lt;name&gt;XMLHttpRequest&lt;/name&gt;
    &lt;/hostObject&gt;
    .............

    &lt;!-- methods --&gt;
    &lt;method readOnly=&quot;true&quot;&gt;
        &lt;className&gt;org.wso2.carbon.jaggery.core.manager.CommonManager&lt;/className&gt;
        &lt;name&gt;print&lt;/name&gt;
    &lt;/method&gt;
    .............

    &lt;!-- scripts --&gt;
    &lt;script&gt;
        &lt;name&gt;media-connect&lt;/name&gt;
        &lt;path&gt;scripts/media_connect.js&lt;/path&gt;
    &lt;/script&gt;
    .............
&lt;/module&gt;
</pre>

                <p>The module.xml need to have a top level <code>&lt;module/&gt;</code> element. The <code>&lt;module/&gt;</code> element should consist of a
                    name attribute and optional <code>namespace</code>, <code>expose</code> attributes. <code>name</code> corresponds to the module
                    name and <code>expose</code> specify whether you need to expose the module by default. i.e. If exposed is set to <code>true</code> and
                    <code>namespace</code> attribute is also specified, then, framework will automatically create a variable which points to the module.
                </p>
                <p>
                    i.e. assuming <code>foo</code> is specified as the value of namespace attribute, you can use objects/methods in the module as below.
                </p>
                <pre class="codettyprint linenums">var xhr = new foo.XMLHttpRequest();</pre>
                <p>If the <code>namespace</code> attribute is ommited, but <code>expose</code> is set as <code>true</code>,
                    then module objects and methods will be imported globally.</p>
                <ul>
                    <li>
                        <p>The <code>&lt;module/&gt;</code> element can contain any number of <code>&lt;hostObject/&gt;</code>,
                    <code>&lt;method/&gt;</code> and <code>&lt;script/&gt;</code> elements. A <code>&lt;hostObject/&gt;</code>
                    element should consist of two child elements named <code>&lt;className/&gt;</code> and
                    <code>&lt;name/&gt;</code> which corresponds to the fully qualified class name of the hostObject
                    Java class and the name of the hostObject.</p>
                        </li>
                <li>
                <p>A <code>&lt;method/&gt;</code> element should consist of two child elements named
                <code>&lt;className/&gt;</code> and <code>&lt;name/&gt;</code> which corresponds to the fully qualified class name of the
                    Java class which contains the method implementation and the name of the method.</p>
                 </li>
                <li>
                <p>A <code>&lt;script/&gt;</code> element should consist of two child elements named
                <code>&lt;path/&gt;</code> and <code>&lt;name/&gt;</code> which corresponds to the script path relative to
                the &lt;JAGGERY_HOME&gt;/jaggery directory and a name for the script.
                </p>
                </li>
                    <li>
                        <p>The attribute <code>&lt;readOnly/&gt;</code> is optionl. If its set, then no
                            one will be able to overwrite the method/hostobject/script from their jaggery files.
                        </p>
                    </li>
                    <li> <p><span class="label important">Important !</span> Each module should be put in a directory with the module name and should have a module.xml.
                            Within that module.xml the mothods/hostobjects/scripts need to be defined.</p>
                        <p>All hostobject jars should be copied into carbon/repository/components/lib(Non-OSGI jars)
                        or carbon/repository/components/dropins(OSGI jars).</p>
                        <p>Sample modules can also be found in {JAGGERY_HOME}/modules directory</p>
                    </li>
                    </ul>
            </div>

            <!-- /print div -->
            <br/>
            <br/>
        </div>

    </div>
<%
include('/includes/footer.jag');
%>

</div>

<!-- /container -->
<%
include('/includes/scripts.jag')
%>

<script>$(function () {
    prettyPrint();
});
$(document).ready(function () {
    $('#require').toggleClass('active')
    $('#docs').addClass('active')
})
</script>
</body>
</html>
