File: /var/www/html/unitime/Documentation/Interfaces/Examples/exampleScripts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE scripts PUBLIC "-//UniTime//UniTime Scrip DTD/EN" "http://www.unitime.org/interface/Script.dtd">
<!--
* Licensed to The Apereo Foundation under one or more contributor license
* agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*
* The Apereo Foundation licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
-->
<scripts created="Mon Mar 23 18:28:22 CET 2015">
<script name="Example Script (JavaScript)" permission="Scripts" engine="ECMAScript" created="Mon Mar 23 18:28:22 CET 2015">
<description><![CDATA[This scripts shows a few perks that are available.]]></description>
<parameter name="greeting" label="Select greeting" type="enum(Ahoj,Hello,Hola,Bonjour,Guten Tag)" default="Hello"/>
<parameter name="subjects" label="Subject area(s)" type="subjects"/>
<parameter name="file" label="Input file" type="file"/>
<parameter name="name" label="Enter your name" type="string"/>
<parameter name="dept" label="Department" type="department"/>
<parameter name="type" label="Room type" type="reference(RoomType)"/>
<body><![CDATA[// Logging
if (name != null) {
log.info(greeting + ' ' + name + '!');
} else {
log.info(greeting + '!');
log.warn('No name was given.');
}
// Reading an input (text) file
if (file != null) {
var lines = file.getString('utf-8').split('\n');
for (var i = 0; i < lines.length; i++) {
log.debug((1 + i) + ': ' + lines[i]);
}
} else {
log.error('No file to read.', null);
}
// Writing an output file
var file = log.createOutput('test', 'txt');
var out = new java.io.PrintWriter(new java.io.FileWriter(file));
out.println('This is a test.');
out.println('Žlutoucký kun úpel dábelské ódy.');
out.flush(); out.close();
// Special parameters
log.info('Current academic session: ' + session.getLabel());
if (dept != null) {
log.info('Selected department: ' + dept.getDeptCode() + ' - ' + dept.getLabel());
}
if (subjects != null) {
log.info('Selected subject areas:');
for (var i = 0; i < subjects.size(); i++) {
var subject = subjects.get(i);
log.info(' ' + subject.getSubjectAreaAbbreviation() + ' - ' + subject.getTitle());
}
}
if (type != null) {
var t = hibSession.createQuery('from RoomType where reference = :reference').setParameter('reference', type).uniqueResult();
log.info('Room type: ' + t.getLabel() + ' (' + t.countRooms(session.getUniqueId()) + ' rooms in ' + session.getLabel() + ')');
}
// Progress
log.setStatus('Counting to ten. Slowly.', 10);
for (var i = 0; i < 9; i++) {
java.lang.Thread.sleep(i * 1000);
log.incProgress();
log.debug('-- ' + (1 + i));
}]]></body>
</script>
<script name="Example Script (Python)" permission="Scripts" engine="python">
<description><![CDATA[This scripts shows a few perks that are available.]]></description>
<parameter name="greeting" label="Select greeting" type="enum(Ahoj,Hello,Hola,Bonjour,Guten Tag)" default="Hello"/>
<parameter name="subjects" label="Subject area(s)" type="subjects"/>
<parameter name="file" label="Input file" type="file"/>
<parameter name="name" label="Enter your name" type="string"/>
<parameter name="dept" label="Department" type="department"/>
<parameter name="type" label="Room type" type="reference(RoomType)"/>
<body><![CDATA[# Logging
if name:
print '%s %s!' % (greeting, name)
else:
print '%s!' % greeting
log.warn('No name was given.')
# Reading an input (text) file
if file:
i = 1
for line in file.getString('utf-8').split('\n'):
log.debug('%d: %s' % (i, line))
i = i + 1
else:
log.error('No file to read.', None)
# Writing an output file
f = open(log.createOutput('test','txt').getAbsolutePath(), 'w')
f.write('This is a test.\n')
f.close()
# Special parameters
print 'Current academic session: %s' % session.getLabel()
if dept:
print 'Selected department: %s - %s' % (dept.getDeptCode(), dept.getLabel())
if subjects:
for subject in subjects:
print ' %s - %s' % (subject.getSubjectAreaAbbreviation(), subject.getTitle())
if type:
t = hibSession.createQuery('from RoomType where reference = :reference').setParameter('reference', type).uniqueResult()
print 'Room type: %s (%d rooms in %s)' % (t.getLabel(), t.countRooms(session.getUniqueId()), session.getLabel())
# Progress
log.setStatus('Counting to ten. Slowly.', 10)
from java.lang import Thread
for i in range(10):
Thread.sleep(i * 1000)
log.incProgress()
log.debug('-- %d' % (1 + i))]]></body>
</script>
</scripts>