xweber pisze:

Grzegorz Kossakowski-3 wrote:
xweber pisze:
[..]
is there a possibility to check for existence of a file in filestructure
[..]
Yes, you can use ResourceExistsSelector:
http://cocoon.apache.org/2.1/userdocs/resourceexists-selector.html (it
will work in C2.2)
[..]


I did some tests with different kind and combinations of selector
"resource-exists".It seems I got a bug  when using servlet:xxxx to get the
file from a different block.

What is working
==========
(sitemap from myBlock1 - the myBlock2 is a bean id):
      <map:match pattern="filename.txt">
        <map:select type="resource-exists">
          <map:when test="resource/external/filename.txt">
            <map:read src="resource/external/filename.txt"/>
          </map:when>
          <map:otherwise>
            <map:read
src="servlet:myBlock2:/resource/external/filename.txt"/>
          </map:otherwise>
        </map:select>
      </map:match>

and I can get the correct filename.txt. What is *NOT* working ===============
(sitemap from myBlock1-the filename.txt exist at
resource/external/filename.txt - the myBlock2 is a bean id - myBlock3 id
does not exist or the file does not exists in myBlock3):
      <map:match pattern="filename.txt">
        <map:select type="resource-exists">
          <map:when test="servlet:myBlock3:resource/external/filename.txt">
            <map:read
src="servlet:myBlock3:resource/external/filename.txt"/>
          </map:when>
          <map:otherwise>
            <map:read
src="servlet:myBlock2:/resource/external/filename.txt"/>
          </map:otherwise>
        </map:select>
      </map:match>

Since myBlock3 does not exist, i am expecting that "test=" returns false and
map:otherwise is used. But unfortunately it _always_ returns true. It is
acting as if the "servlet:myBlock3:" part is completely ignored.

Maybe it is a syntax problem (found no documentation how it should look like
in 2.2), but i thought because of the working of the syntax inside map:read
it must be ok.

Alex, I've just checked sources of servlet: protocl (source) that it looks[1] 
like this:

        /**
         * Returns true always.
         *
         * @see org.apache.excalibur.source.Source#exists()
         */
        public boolean exists() {
                return true;
        }

I'm not sure why it always returns true but I think it was just a prototype and should be implemented differently. File an issue in JIRA, and submit a patch preferably. I think that implementing this method will not be that hard and I can give you an advice whenever you need. If you are going to implement it, we should move the discussion to dev list.

As starting point, I'll say that you need implement to make a request (using ServletConnection) inside exists method. You should use HTTP HEAD method for request because we are only interested in response's status code (e.g. if it's a 200 or 404).

--
Grzegorz Kossakowski
http://reflectingonthevicissitudes.wordpress.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to