<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF 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.
-->
<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "http://forrest.apache.org/dtd/document-v20.dtd">
<document>
  <header>
    <title>Developing with Apache Droids in your spring based project.</title>
  </header>
  <body>
    <section>
      <title>Develope small specialised components!</title>
      <p>Following the UNIX philosophy for automated task processing in java enable us to 
        re-use the maximum code from other projects. As a reminder a pipe in unix starts 
        with an invoking component (which produces a stream)
        and then chain as much other components that interact on the stream that are needed.
        The modification of each component will be passed to the next component in the chain.
      </p>
      <p>For example the following command in a unix box will lance a subversion command to
        check for the status on the local svn checkout (svn st). The next command will filter
        the files that are not under svn control (grep ?). The next command will modify the
        stream to create a command to add this files to the repository (awk ...). The last step
        will cause the invocation of the command by sending it to the shell (sh).</p>
      <p><code>svn st | grep ? | awk '{print "svn add "$2}' | sh</code></p>
      <p>In droids your are piping/processing your tasks with small specialist components
        that combined are resolving your task. </p>
    </section>
    <section id="how">
      <title>How can I use Apache Droids in my application?</title>
      <p>Once you have created the droids.jar, place it in your classpath and you are ready to
        develope your own components and robots. Droids is completly Spring driven, if you
        never have seen Spring at all you need to check out their
        <a href="ext:spring/docu">documentation</a> otherwise you will be lost.</p>
      <p>We will develope a
        <strong>SIMPLE</strong> robot that will crawl a web page and send the data to an
        Apache Solr server (poor man's approach of Apache Nutch crawling) and will call it
        <code>"indexer"</code>. </p>
      <p>The resulting classes can be found in
        <code>$DROIDS_HOME/src/example/java</code> and can be compiled with
        <code>ant droids.compile-example</code>. This target compiles the examples,
        creates a jar and copy the resulting jar into the lib directory.</p>
    </section>
    <section id="extend">
      <title>Extend the default spring configuration.</title>
      <p>
        In your principal spring configuration you need to import the default spring configuration
        files from droids. A typical file would look something like the following.
      </p>
      <source><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
    "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
  <import resource="classpath:/org/apache/droids/droids-core-factories-context.xml"/>
  <import resource="classpath:/org/apache/droids/droids-core-context.xml"/>
<!-- ... -->
</beans>]]></source>
      <p>Then we need to configure the org.apache.droids.helper.factories.DroidFactory
        bean to add our new droid.</p>
      <source><![CDATA[<bean id="org.apache.droids.helper.factories.DroidFactory"
  class="org.apache.droids.helper.factories.DroidFactory">
  <property name="map">
    <map>
      <entry key="indexer" value-ref="indexer"/>
      <!-- Referencing as well the Hello crawler 
         that is configured by the Droids core -->
      <entry key="hello" value-ref="hello"/>
    </map>
  </property>
</bean>]]></source>
      <p>Then we need to configure our <code>indexer</code>.</p>
      <source><![CDATA[<!-- Indexer -->
<bean id="indexer" class="org.apache.droids.examples.IndexerCrawler">
  <property name="core" ref="org.apache.droids.Core"/>
  <property name="queue" ref="org.apache.droids.queue.Simple"/>
  <property name="maxThreads" value="@droids.maxThreads@"/>
  <property name="url" value="@droids.initial.url@"/>
  <property name="updateUrl" value="http://localhost:8983/solr/update"/>
</bean>]]></source>
      <p>The variables within @@ are replaced while building the jar with ant. The actual
        value is defiened either by the properties in your build.properties or the
        default.properties.</p>
      <p>Now we need to wrap up our droid in defining our new handler.</p>
      <source><![CDATA[<bean id="org.apache.droids.helper.factories.HandlerFactory"
  class="org.apache.droids.helper.factories.HandlerFactory">
  <property name="map">
    <map>
      <entry key="solr" value-ref="org.apache.droids.handle.Solr"/>
    </map>
  </property>
</bean>

<!-- Handler -->
<bean id="org.apache.droids.handle.Solr" class="org.apache.droids.handle.Solr">
  <property name="updateUrl" value="http://localhost:8983/solr/update"/>
</bean>]]></source>
    </section>
  </body>
</document>
