Phil Powell

Greenhorn
+ Follow
since Jul 13, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Phil Powell

/common is one of the context roots.

I figured out that it's possible now to do forwarding from within the same web module, however, we are unable to forward to another web module.

I need to be able to forward from /main/register.jsp (/main is one context root) to /common/error_page.jsp (/common is another context root), but that constantly fails.

We were completely able to forward between web modules until a couple of weeks ago when a server reboot took place and then suddenly that ability was gone; we constantly get java.io.FileNotFoundException errors thrown every time we try to forward from one web module to another

We're using WebSphere 6.0 if that helps any.
9 years ago

Originally posted by Piet Verdriet:
: p

Okay, you never gave an exact example in AND ouput, so I might be wrong, but if I understand you crrectly, you want to replace sub strings like this:

<c: param name="AAA" value="<%= aaa %>" />

into:

<c: param name="AAA" value="aaa" />

correct?

If so, you don't need to create any Matcher: replaceAll(...) on a String is sufficient.

Try this:



>> please explain ".*?" and ".+?", that sounds contradictory inasmuch as that sounds like "0 or more characters and 0 or 1 character" along with "1 or more characters and 0 or 1 character"; that does not make sense to me.

>> Thanks for the explanation on ?s and ?m


The (?s) and (?m) flags in front of the regex, tell replaceAll(...) to let the DOT match any character and matches can span over multiple lines.

[ August 27, 2008: Message edited by: Piet Verdriet ]

9 years ago
Please break this down to a simpler level; I can't follow anything you posted whatsoever, sorry

Originally posted by Mark Vedder:
{Note: I was typing up my reply as Steve posted his and therefore did not see it until I was done. So there's a little bit of redundancy. Great minds think alike and all that... }



That has nothing to do with using an escaping a character in the replacement string. That has to do with the regex itself. If you put a logging statement in, you will see that the find method is only finding the last line. You need to
indicate your pattern is multiline:



That will at least find each pattern that occurs on a separate line. But it will still identify this line:



all as a single match and not two matches.

As such

  • $1 = <c:param name="myName" value="<%= myValue %>" /> <c:param name="foo" value="
  • $2 = bar <-- with a trailing space
  • $3 = " />


  • So the end of the first desired match and the start of the second desired match is matching the regex for the first capturing group, namely the .+

    If we change that to a [^>]+ then we will only capture the desired start, but we'll also need to modify the third capturing group:

  • $1 = <c:param name="myName" value="
  • $2 = myValue <-- with a trailing space
  • $3 = " /> <c:param name="foo" value="<%= bar %>" />


  • Now, the .* in the third group is capturing the second desired match. So we can change that to ("[^>]+> ;) and everything will work. Also, the [ \t]* should probably be changed to [\s]* since a carriage return in the middle of an XML element is legal as well as a space or tab.

    Also, the regex does not take into account single quoted attribute values. (value = 'myValue'). So we want to change teh " to an option of ' or ".

    So adding all our changes together we get:


    That will do more along the lines of what you want. May not be perfect, I'd do some unit testing on it to check for other missed options.

    There's a great tool available to help with writing regular expressions. It's called RegexBuddy. It does a lot. One of the nicest features is the ability to highlight not only the match, but what a capturing group is matching. It's a commercial product, but well worth the cost as it will save you hours of work.

    [ August 25, 2008: Message edited by: Mark Vedder ]


    [ August 27, 2008: Message edited by: Phil Powell ]
    [edit]Disable Smilies. CR[/edit]
    [ September 02, 2008: Message edited by: Campbell Ritchie ]
    9 years ago
    http://www.mydomain.com/common/handler.jsp:



    This throws a java.io.FileNotFoundException:



    However, I can go to http://www.mydomain.com/common/error_page.jsp and verify that it does indeed exist.

    Why would it throw a FileNotFoundException if not only does the forwarding page exist but exists within the exact same web module?

    I checked ibm-web-ext.xml for the "common" web module to notice that fileServingEnabled="true".

    Any ideas why this is happening?
    9 years ago
    Yes I am.

    I found that the code I gave you doesn't consistently work across all instances of the <c:param> JSTL tag with the given pattern, but this one works and I have no idea why:



    Difference is the pattern has to apparently be WRONG for Java for it to work combined with searching in the wrong direction via replaceFirst() within a find() while loop.

    [edit]Disable Smilies. CR[/edit]
    [ August 25, 2008: Message edited by: Campbell Ritchie ]
    9 years ago
    Thanks, it works now but very poorly.



    Your suggestion about the backslashes only partially works in Java. It works only on the very last instance of the pattern found, even if I use replaceAll(). Put it in a continuous loop and it will clean up every instance, backwards, from the last to the first.

    [edit]Disable smilies. I don't know whether I have deleted the correct spaces. CR[/edit]
    [ August 25, 2008: Message edited by: Campbell Ritchie ]
    9 years ago
    I thought of that and tried escaping the "$", to no avail. Still couldn't replace!
    9 years ago

    This code works to find the JSTL tag pattern:




    But no pattern substitution takes place. I do not understand why this
    fails to replace the pattern but successfully finds the pattern. Any
    ideas why? Is this more proof that Java can't handle regular
    expressions?

    [edit]Disable Smilies. Don't know whether I have removed the spaces correctly. CR[/edit]
    [ August 25, 2008: Message edited by: Campbell Ritchie ]
    9 years ago
    GOT IT!



    Phil
    11 years ago

    Originally posted by Craig Wood:
    Is image cropping even possible in Java?
    Yes.
    About the exception ClassCastException: sun.awt.image.ToolkitImage cannot be cast to
    java.awt.image.BufferedImage
    :
    You probably loaded your source image with one of the older Toolkit getImage or
    createImage methods. These return type Image which cannot be cast to BufferedImage.



    Actually, I loaded the source image using ImageIO.read(URL) so I have no idea where TookitImage comes from except that I am using createImage() to create the image, at least thinking it would be java.awt.Image


    To obtain a BufferedImage with an Image you can create a new BufferedImage and draw the
    Image into it:

    Or, you could use a newer image–loading method that returns a BufferedImage:

    About the exception RasterFormatException: (x + width) is outside of Raster:
    This exception is thrown by the getSubimage method as stated in the BufferedImage
    api. You have to be very careful/precise in using this method to avoid trouble. Another
    problem with using it to obtain smaller images is that the two images are not independent.
    Making changes to one image automatically changes the other. Sometimes this can cause
    trouble. You can always copy the subimage into a new BufferedImage.
    Another option for obtaining a clipped image is to create a new BufferedImage the size of
    your clipping Rectangle, translate its graphics context by clipX, clipY and draw the src
    image as above. It takes a little playing–around with to see how it works.

    11 years ago
    Not sure if this might help but here are the numbers that spawned the RasterFormatException:

    X = 218
    Y = 399
    width = 418
    height = 403
    11 years ago
    I tried two different techniques, and both of them failed:

    I thought I got it and again, I failed.





    This constantly throws the following exception:





    I was under the impression that I'm using java.awt.Image, where did sun.awt.image.ToolkitImage come from? I can't figure out how to cast this correctly either, what do I do?

    -------------------------------------------------------

    Second approach:




    And now I get this exception:




    Is image cropping even possible in Java?
    11 years ago
    I understand what "final" means, but I don't understand why I am allowed to put "final" within the parameter; I've never seen syntax like that before!
    and it did, thank you! But how on earth was I allowed to do that one?


    This code fails to compile producing the error message:



    Bluntly put, how do I fix this?

    Thanks
    Phil