Section 5. If the plaintiff has lived in this commonwealth for one year last preceding the commencement of the action if the cause occurred without the commonwealth, or if the plaintiff is domiciled within the commonwealth at the time of the commencement of the action and the cause occurred within the commonwealth, a divorce may be adjudged for any cause allowed by law, unless it appears that the plaintiff has removed into this commonwealth for the purpose of obtaining a divorce.