You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Niclas Hedhman <ni...@hedhman.org> on 2004/10/06 13:05:55 UTC

Setting up Selectors...

Gang,

I can't find how to set up Selectors. Any pointers?

Case;

Cocoon Block.

ImageOpReader can be stacked with a set of ImageOperations, each defined as a 
separate component, with its own configuration.

ImageOpReader is supposed to look up a ImageOperationSelector, which will be 
selected by name.

I did;
  <role name="org.apache.cocoon.reading.imageop.ImageOperationSelector"
        shorthand="image-operation"
        default-class="org.apache.cocoon.components.ExtendedComponentSelector" 
  >
    <hint shorthand="scale" 
class="org.apache.cocoon.reading.imageop.ScaleOperation"/>
    <hint shorthand="convolve" 
class="org.apache.cocoon.reading.imageop.ConvolveOperation"/>
  </role>  

in a .xroles file, and then have a 
m_OperationSelector = (ComponentSelector) man.lookup( ImageOperation.ROLE + 
"Selector" );

and later the 
ImageOperation op = (ImageOperation) m_OperationSelector.select( type );

But I get the message 
"UnnamedSelector: ComponentSelector could not find the component for hint 
[scale] (key [scale])"
and a very 'inconclusive' stack trace.


What am I missing?


Cheers
Niclas


What else is there to it?
-- 
   +------//-------------------+
  / http://www.bali.ac        /
 / http://niclas.hedhman.org / 
+------//-------------------+


Re: Setting up Selectors...

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Niclas Hedhman wrote:
> Thanks, so in the Block scenario I declare the above in a imageop.xconf file? 
> Or is that for something else?

Take a look at src/blocks/apples/conf/apples-processor.xconf, this is a patch 
file for cocoon.xconf, yours will be similar.

Vadim

Re: Setting up Selectors...

Posted by Niclas Hedhman <ni...@hedhman.org>.
On Wednesday 06 October 2004 19:56, Vadim Gritsenko wrote:

> IIRC, roles file entries are just a convinience, you can do without them
> completely; components are declared in the cocoon.xconf file:
>
>    <image-operation>
>      <scale/>
>      <convolve/>
>    </image-operation>
>
> Or without roles file:
>
>    <component
> role="org.apache.cocoon.reading.imageop.ImageOperationSelector"
> class="org.apache.cocoon.components.ExtendedComponentSelector"
> <component-instance name="scale"
>        class="org.apache.cocoon.reading.imageop.ScaleOperation"/>
>      etc
>    </component>

Thanks, so in the Block scenario I declare the above in a imageop.xconf file? 
Or is that for something else?

Cheers
Niclas
-- 
   +------//-------------------+
  / http://www.bali.ac        /
 / http://niclas.hedhman.org / 
+------//-------------------+


Re: Setting up Selectors...

Posted by Niclas Hedhman <ni...@hedhman.org>.
On Friday 08 October 2004 20:59, Vadim Gritsenko wrote:
> Niclas Hedhman wrote:
> > On Thursday 07 October 2004 20:21, Vadim Gritsenko wrote:
> >>Where image-operations is selector. See <input-modules/> as example - you
> >>need something similar, AFAIU.
> >
> > YES!  Finally got it.
> >
> > Now only need to create the remaining ImageOperations and you will have a
> > funky image processing tool in your toolbox as well.
>
> Only if samples are included! ;-)

Will do ! 

During the weekend I hope to cover;
 - Scale (%)
 - Scale to size (absolute)
 - Color manipulations (as in ImageReader).
 - GrayScale (as in ImageReader)
 - Rotate
 - Mirror
 - Generic Convolve
 - Generic AffinTransform
 
Cheers
Niclas
-- 
   +------//-------------------+
  / http://www.bali.ac        /
 / http://niclas.hedhman.org / 
+------//-------------------+


Re: Setting up Selectors...

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Niclas Hedhman wrote:
> On Thursday 07 October 2004 20:21, Vadim Gritsenko wrote:
> 
> 
>>Where image-operations is selector. See <input-modules/> as example - you
>>need something similar, AFAIU.
> 
> 
> YES!  Finally got it.
> 
> Now only need to create the remaining ImageOperations and you will have a 
> funky image processing tool in your toolbox as well.

Only if samples are included! ;-)

Re: Setting up Selectors...

Posted by Niclas Hedhman <ni...@hedhman.org>.
On Thursday 07 October 2004 20:21, Vadim Gritsenko wrote:

> Where image-operations is selector. See <input-modules/> as example - you
> need something similar, AFAIU.

YES!  Finally got it.

Now only need to create the remaining ImageOperations and you will have a 
funky image processing tool in your toolbox as well.

Cheers
Niclas
-- 
   +------//-------------------+
  / http://www.bali.ac        /
 / http://niclas.hedhman.org / 
+------//-------------------+


Re: Setting up Selectors...

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Niclas Hedhman wrote:
> On Thursday 07 October 2004 18:19, Vadim Gritsenko wrote:
> 
> 
>>I don't think ecm supports nested selectors. image-operations is a
>>selector, right? And you are nesting another one? Are you sure you need
>>this?
> 
> 
> I apparently don't know what I am doing. Here are the relevant pieces of code 
> (which is accurate);
> 
> public void compose( ComponentManager man )
>     throws ComponentException
> {
>     m_OperationSelector = (ComponentSelector) man.lookup( 
> "org.apache.cocoon.reading.imageop.ImageOperationSelector" );
> }
> 
> 
> private void configureEffects( Configuration conf )
>     throws ConfigurationException, ComponentException
> {
>     m_EffectsStack = new ArrayList();
>         
>     Configuration[] ops = conf.getChildren( "op" );
>     for( int i=0 ; i < ops.length ; i++ )
>     {
>         String type = ops[i].getAttribute( "type" );
>         String prefix = ops[i].getAttribute( "prefix", type + "-" );
>         ImageOperation op = (ImageOperation) m_OperationSelector.select( type 
> );
>         op.setPrefix( prefix );
>         m_EffectsStack.add( op );
>     }
> }
> 
> Both are in the ImageOpReader.
> configureEffects called from configure(), with the "<effects>" child as an 
> argument (all that verified working earlier).
> 
> I just need a way to lookup the ImageOperations that are defined.
> 
> Should be dirt simple.... if I had some more experience with Cocoon/ECM. :o(

It is simple, if you ask me ;-)
This should work:
   <image-operations>
     <component-instance class="o.a.c.FooOperation" name="foo"/>
   </image-operations>

Where image-operations is selector. See <input-modules/> as example - you need 
something similar, AFAIU.

Vadim

Re: Setting up Selectors...

Posted by Niclas Hedhman <ni...@hedhman.org>.
On Thursday 07 October 2004 18:19, Vadim Gritsenko wrote:

> I don't think ecm supports nested selectors. image-operations is a
> selector, right? And you are nesting another one? Are you sure you need
> this?

I apparently don't know what I am doing. Here are the relevant pieces of code 
(which is accurate);

public void compose( ComponentManager man )
    throws ComponentException
{
    m_OperationSelector = (ComponentSelector) man.lookup( 
"org.apache.cocoon.reading.imageop.ImageOperationSelector" );
}


private void configureEffects( Configuration conf )
    throws ConfigurationException, ComponentException
{
    m_EffectsStack = new ArrayList();
        
    Configuration[] ops = conf.getChildren( "op" );
    for( int i=0 ; i < ops.length ; i++ )
    {
        String type = ops[i].getAttribute( "type" );
        String prefix = ops[i].getAttribute( "prefix", type + "-" );
        ImageOperation op = (ImageOperation) m_OperationSelector.select( type 
);
        op.setPrefix( prefix );
        m_EffectsStack.add( op );
    }
}

Both are in the ImageOpReader.
configureEffects called from configure(), with the "<effects>" child as an 
argument (all that verified working earlier).

I just need a way to lookup the ImageOperations that are defined.

Should be dirt simple.... if I had some more experience with Cocoon/ECM. :o(


Cheers
Niclas
-- 
   +------//-------------------+
  / http://www.bali.ac        /
 / http://niclas.hedhman.org / 
+------//-------------------+


Re: Setting up Selectors...

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Niclas Hedhman wrote:
> Sorry for being so dense, and thanks for your patience.
> 
> On Wednesday 06 October 2004 19:56, Vadim Gritsenko wrote:
> 
> 
>>Or without roles file:
>>
>>   <component
>>role="org.apache.cocoon.reading.imageop.ImageOperationSelector"
>>class="org.apache.cocoon.components.ExtendedComponentSelector"
>><component-instance name="scale"
>>       class="org.apache.cocoon.reading.imageop.ScaleOperation"/>
>>     etc
>>   </component>
> 
> 
> After the above, it doesn't find the Selector either (which was the case 
> earlier).
> The Exception occurs in the lookup() of ImageOpReader.compose();
> 
>     public void compose( ComponentManager man )
>         throws ComponentException
>     {
>         m_OperationSelector = (ComponentSelector) man.lookup( 
> "org.apache.cocoon.reading.imageop.ImageOperationSelector" );
>     }
> 
> and says
>     
> Could not find component (key 
> [org.apache.cocoon.reading.imageop.ImageOperationSelector])
> 
> 
> The cocoon.xconf now contains;
> <!--..... Start configuration from 'imageop' -->
>    <!-- =============== Image Operations ==================== -->
>     <image-operations>
>       <component 
> class="org.apache.cocoon.components.ExtendedComponentSelector" 
> role="org.apache.cocoon.reading.imageop.ImageOperationSelector">

I don't think ecm supports nested selectors. image-operations is a selector, 
right? And you are nesting another one? Are you sure you need this?

Vadim


>         <component-instance 
> class="org.apache.cocoon.reading.imageop.ScaleOperation" name="scale"/>
> 
>         <component-instance 
> class="org.apache.cocoon.reading.imageop.ConvolveOperation" name="convolve"/>
>       </component>
>     </image-operations>
> <!--..... End configuration from 'imageop' -->
...
> Wish I can get this done and out of the door into the Cocoon repo. :o)
> Perhaps I should send along the entire block?
> 
> Well, meanwhile I guess I add some more funky operations.
> 
> Cheers
> Niclas

Re: Setting up Selectors...

Posted by Niclas Hedhman <ni...@hedhman.org>.
Sorry for being so dense, and thanks for your patience.

On Wednesday 06 October 2004 19:56, Vadim Gritsenko wrote:

> Or without roles file:
>
>    <component
> role="org.apache.cocoon.reading.imageop.ImageOperationSelector"
> class="org.apache.cocoon.components.ExtendedComponentSelector"
> <component-instance name="scale"
>        class="org.apache.cocoon.reading.imageop.ScaleOperation"/>
>      etc
>    </component>

After the above, it doesn't find the Selector either (which was the case 
earlier).
The Exception occurs in the lookup() of ImageOpReader.compose();

    public void compose( ComponentManager man )
        throws ComponentException
    {
        m_OperationSelector = (ComponentSelector) man.lookup( 
"org.apache.cocoon.reading.imageop.ImageOperationSelector" );
    }

and says
    
Could not find component (key 
[org.apache.cocoon.reading.imageop.ImageOperationSelector])


The cocoon.xconf now contains;
<!--..... Start configuration from 'imageop' -->
   <!-- =============== Image Operations ==================== -->
    <image-operations>
      <component 
class="org.apache.cocoon.components.ExtendedComponentSelector" 
role="org.apache.cocoon.reading.imageop.ImageOperationSelector">
             
        <component-instance 
class="org.apache.cocoon.reading.imageop.ScaleOperation" name="scale"/>

        <component-instance 
class="org.apache.cocoon.reading.imageop.ConvolveOperation" name="convolve"/>
      </component>
    </image-operations>
<!--..... End configuration from 'imageop' -->

And the root sitemap has the following readers defined;

    <map:reader logger="sitemap.reader.image" name="image-op-scale" 
src="org.apache.cocoon.reading.imageop.ImageOpReader">
      <effects>
        <op prefix="scale-" type="scale"/>
      </effects>
    </map:reader>
  
    <map:reader logger="sitemap.reader.image" name="image-op-sharpen" 
src="org.apache.cocoon.reading.imageop.ImageOpReader">
      <effects>
        <op prefix="convolve-" type="convolve"/>
      </effects>
      <map:parameter name="convolve-height" value="3"/>
      <map:parameter name="convolve-width" value="3"/>
      <map:parameter name="convolve-data" value="0.0, -1.0, 0.0, -1.0, 5.0, 
-1.0, 0.0, -1.0, 0.0"/>
    </map:reader>


Wish I can get this done and out of the door into the Cocoon repo. :o)
Perhaps I should send along the entire block?

Well, meanwhile I guess I add some more funky operations.

Cheers
Niclas
-- 
   +------//-------------------+
  / http://www.bali.ac        /
 / http://niclas.hedhman.org / 
+------//-------------------+


Re: Setting up Selectors...

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Niclas Hedhman wrote:
> 
> I did;
>   <role name="org.apache.cocoon.reading.imageop.ImageOperationSelector"
>         shorthand="image-operation"
>         default-class="org.apache.cocoon.components.ExtendedComponentSelector" 
>   >
>     <hint shorthand="scale" 
> class="org.apache.cocoon.reading.imageop.ScaleOperation"/>
>     <hint shorthand="convolve" 
> class="org.apache.cocoon.reading.imageop.ConvolveOperation"/>
>   </role>  
...
> But I get the message 
> "UnnamedSelector: ComponentSelector could not find the component for hint 
> [scale] (key [scale])"
> and a very 'inconclusive' stack trace.

IIRC, roles file entries are just a convinience, you can do without them 
completely; components are declared in the cocoon.xconf file:

   <image-operation>
     <scale/>
     <convolve/>
   </image-operation>

Or without roles file:

   <component role="org.apache.cocoon.reading.imageop.ImageOperationSelector"
              class="org.apache.cocoon.components.ExtendedComponentSelector"
     <component-instance name="scale"
       class="org.apache.cocoon.reading.imageop.ScaleOperation"/>
     etc
   </component>


Vadim