如何在wirecloud运算符上包含javascript库

时间:2014-10-21 07:57:04

标签: fiware-wirecloud

我正在尝试开发一个wirecloud运算符,但我不知道如何在config.xml上包含一个javascript库(即jquery),除了main.js文件。我尝试在config.xml中包含jquery库,就像main.js一样,使用不同的wire:index,但它不起作用。

有没有办法包含第二个JS库?

2 个答案:

答案 0 :(得分:1)

是的,您可以在运营商中拥有多个javascript文件。我认为您的问题与RDF语法有关,这有点奇怪。无论如何,以下代码片段是如何使用RDF / XML包含jquery和main.js文件的示例:

<usdl:utilizedResource>
  <usdl:Resource rdf:about="js/jquery.min.js">
    <wire:index>0</wire:index>
  </usdl:Resource>
</usdl:utilizedResource>
<usdl:utilizedResource>
  <usdl:Resource rdf:about="js/main.js">
    <wire:index>1</wire:index>
  </usdl:Resource>
</usdl:utilizedResource>

或者,如果您在FIWARE Lab使用Mashup门户,则可以使用将在WireCloud 0.7.0上可用的新XML格式(目前Mashup门户正在运行该版本的候选版本)。这是新格式的一个示例:

<?xml version='1.0' encoding='UTF-8'?>
<operator xmlns="http://wirecloud.conwet.fi.upm.es/ns/macdescription/1" vendor="CoNWeT" name="ngsi-source" version="3.0">
    <details>
        <title>NGSI source</title>
        <homepage>https://github.com/wirecloud-fiware/ngsi-source</homepage>
        <authors>Álvaro Arranz García &lt;aarranz@conwet.com&gt;</authors>
        <email>aarranz@conwet.com</email>
        <image>images/catalogue.png</image>
        <description>Retrieve Orion Context Broker entities and their updates in real time.</description>
        <longdescription>DESCRIPTION.md</longdescription>
        <license>AGPLv3+ w/linking exception</license>
        <licenseurl>http://www.gnu.org/licenses/agpl-3.0.html</licenseurl>
        <doc>doc/userguide.md</doc>
        <changelog>doc/changelog.md</changelog>
    </details>
    <requirements>
        <feature name="NGSI"/>
    </requirements>
    <preferences>
        <preference name="ngsi_server" type="text" label="NGSI server URL" description="URL of the Orion Context Broker to use for retrieving entity information" default="http://orion.lab.fi-ware.org:10026/"/>
        <preference name="ngsi_proxy" type="text" label="NGSI proxy URL" description="URL of the Orion Context Broker proxy to use for receiving notifications about changes" default="http://mashup.lab.fi-ware.org:3000/"/>
        <preference name="ngsi_entities" type="text" label="NGSI entity types" description="A comma separated list of entity types to use for filtering entities from the Orion Context broker. Thies field cannot be empty." default="Node, AMMS, Regulator"/>
        <preference name="ngsi_id_filter" type="text" label="Id pattern" description="Id pattern for filtering entities. This preference can be empty, in that case, entities won't be filtered by id." default=""/>
        <preference name="ngsi_update_attributes" type="text" label="Monitored NGSI Attributes" description="Attributes to monitor for updates. Currently, the Orion Context Broker requires a list of attributes to monitor for changes, so this field cannot be empty." default="Latitud, Longitud, presence, batteryCharge, illuminance, ActivePower, ReactivePower, electricPotential, electricalCurrent"/>
    </preferences>
    <wiring>
        <outputendpoint name="entityOutput" type="text" label="Provide entity" description="Every change over each entity fires an event" friendcode="entity"/>
    </wiring>
    <scripts>
        <script src="js/other.dependency.js"/>
        <script src="js/main.js"/>
    </scripts>

</operator>

您可以在此link找到有关此新格式的更多文档。

答案 1 :(得分:1)

最后,我在wirecloud运算符上使用RDF / XML包含其他JS文件。首先,我在config.xml文件中使用以下代码:

<usdl-core:utilizedResource rdf:about="js/jquery-1.10.2.min.js">
    <wire:index>0</wire:index>
</usdl-core:utilizedResource>

<usdl-core:utilizedResource rdf:about="js/main.js">
    <wire:index>1</wire:index>
</usdl-core:utilizedResource>                                            

此外,包含的JS文件必须声明如下:

<wire:Operator rdf:about="http://wirecloud.conwet.fi.upm.es/ns/widget#Operator">
    ...
    <usdl-core:utilizedResource rdf:resource="js/jquery-1.10.2.min.js"/>
    <usdl-core:utilizedResource rdf:resource="js/main.js"/>
    ....
</wire:Operator>