pattern

Validating Jpa Entities: In service or by lifecycle listeners

The question is where it is better (or in other words: where do you prefer) to put business validation logic of Jpa Entities. Two ideas are: In the EntityListener that before save or update would validate the entity In the service that provides access to jpa persisting methods. There are pros and cons of both. When using approach N...

PHP how to delete this from a string?

I want to delete this from a string: [QUOTE=*] * [/QUOTE] .* kan be anything Can anyone please provide a pattern that I can use? ...

XML schema pattern for validating a logical expression

I am writing a schema to validate an xml document that can contain an attribute that is a logical expression. i.e. test="@a empty and @b empty and @c is keyword" (@x are "reference ids" that refer to elements in the schema that are being tested). I'm using patterns for this and have several that work. <!-- @refid is | is not keyword --...

How to repeat a few characters a few times in bash?

In a bash script, I have to include the same file several times in a row as an argument. Like this: convert image.png image.png image.png [...] many_images.png where image.png should be repeated a few times. Is there a bash shorthand for repeating a pattern? ...

GUI layer vs Code layer vs Swing

I always coded console applications and learned some basic UML/patterns skills, using C++. Now I decided to move to Java and add GUIs to my programs. The first question is how to handle the GUI layer in the program desing. I mean, how I should separate all the GUI code (adding components, basic event handling) with the code that really...

Queued message sending with Prototype.AJAX

Hi there, is there any best-practice-pattern for implementing a queue for sending ordered requests? I know this hits the logic behind ansynchronous requests, but in special cases one needs queued sending :) Here is my first attempt: this.queue = [], this.sending = false, send: function(message) { if (this.sending) { this...

Need help with the Matcher

Hello, I have following regex (abc|def)( ?(\\d+|(?:(?!\\1)[a-z])+)?)* with matches perfectly the subject abc123 456. Now I want to get all parts abc, 123 and 456. I use following code: Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(subject); while(m.find()) { System.out.println(m.group()); } ...

ERLANG - Pattern Matching

Hi Everyone, I have a variable: Data = [[<<>>, [<<"10">>,<<"171">>], [<<"112">>,<<"Gen20267">>], [<<"52">>,<<"20100812-06:32:30.687">>]] I am trying to pattern match for two specific cases.. One where anything that resembles the outside structure - simply [] Anything inside goes I have tried [ _ ] but no go? The Second, for a ...

Django cannot find url pattern in URLConf although it is defined

I type the following url in my browser: http://localhost:8000/en/weblog/2010/aug/10/wie-baue-ich-ein-weblog/ an I get a "Page Not Found (404)" error, although the 10th entry (r'^weblog/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(P?<slug>[-\w]+)/$', 'django.views.generic.date_based.object_detail', entry_info_dict), in my URLCon...

ERLANG - Pattern Matching specifc pattern in unknown size list

Ok now I think Im getting warmer, I have to pattern match whatever comes in. So if I had say Message = = [[<<>>], [<<"10">>,<<"171">>], [<<"112">>,<<"Gen20267">>], [<<"52">>,<<"20100812-06:32:30.687">>]] And I was looking to pattern match the field <<"112">> Such as the 112 is always going to say 112, but the Gen2067 can change...

Java Regular expression

I have a string and a pattern that i want to search for in that string. Now, when i match the pattern in the string, i want to know the string that matches my pattern. String template = "<P ALIGN=\"LEFT\"><FONT FACE=\"Verdana\" SIZE=\"12\"> My Name is xyz </FONT></P>"; String pattern = "<FONT.*>"; Pattern.compile(pattern,Pattern.CASE_...

java regular expression matching

What is the regular expression that can match the following 2 strings. Hi<Dog>Hi and <Dog> in a given text. Update: What regex will match this one? If you access the web site click the link below: matches only till the first ...

Regexp pattern Optional character

I want to match a string like 19740103-0379 or 197401030379, i.e the dash is optional. How do I accomplish this with regexp? ...

Question about prototype pattern

The objective of prototype pattern is to clone an object by reducing the cost of creation. Here is an example: class Complex { int[] nums = {1,2,3,4,5}; public Complex clone() { return new Complex();//this line create a new object, so is it violate the objective of prototype ?// } } class Test2 { Comp...

C# database wrapper design

Hi, I am designing a database wrapper for C#. Below are the two options I have: Option A: class DBWrapper:IDisposable { private SqlConnection sqlConn; public DBWrapper() { sqlConn = new SqlConnection("my connection string"); sqlConn.Open(); } public DataTable RunQuery(string Sql) ...

help in parsing

Hi All, I am having a XML file as shown below, <message1> <val1>100</val1> <val2>200</val2> <val3>300</val3> <val4>400</val4> </message1> <message2> <val1>100</val1> <val2>200</val2> <val3>300</val3> <val4>400</val4> </message2> I have to parse the values (val) and i could not use XML::Simple module. The parsing should be started fr...

Is this really an example of the adapter pattern?

I have an interface -- "EventHandler" -- that declares several methods. public interface EventHandler { void handleEvent1(); void handleEvent2(); void handleEvent3(); void handleEvent4(); } I also have a class -- "EventHandlerAdapter" -- that implements EventHandler. However, it doesn't actually "implement" anything...

Master-Detail on RoR with Ajax

What is the best pattern to do a master-detail form in Ajax using RoR? My form has an order and for each order there is a lot of itens. I want to do only one form where the user can set the order details and include, exclude and update itens. When the user insert an item, I am doing an AJAX call to my controller so the user can search fo...

Why is in F# a dummy symbol literal needed between pipe and when?

Hi, I am new to F# and fiddling just around with it. What get's me is: let rec fact n = match n with | dummy when n < 2 -> 1 | _ -> n * fact (n - 1) let x = 6 printfn "%d! = %d" x (fact x) Why does F# needs this dummy placeholder between pipe and when? Dummy is even the whole time undefined and the compiler seems in some w...

when to use the observer pattern when developing websites?

Hi, i need some practical examples of cases when i could use the observer pattern when developing a website.. (using php) I have one "when a user publishes an Article (subject), the class RSS and the class EMAIL (the observers) will modify the rss and send an email to the admin", but i'm not even sure if this is a good example.. wher...