forked from geonetwork/core-geonetwork
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Static pages / add support for mail links
- Loading branch information
Showing
4 changed files
with
120 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//============================================================================= | ||
//=== Copyright (C) 2001-2025 Food and Agriculture Organization of the | ||
//=== United Nations (FAO-UN), United Nations World Food Programme (WFP) | ||
//=== and United Nations Environment Programme (UNEP) | ||
//=== | ||
//=== This library is free software; you can redistribute it and/or | ||
//=== modify it under the terms of the GNU Lesser General Public | ||
//=== License as published by the Free Software Foundation; either | ||
//=== version 2.1 of the License, or (at your option) any later version. | ||
//=== | ||
//=== This library is distributed in the hope that it will be useful, | ||
//=== but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
//=== Lesser General Public License for more details. | ||
//=== | ||
//=== You should have received a copy of the GNU Lesser General Public | ||
//=== License along with this library; if not, write to the Free Software | ||
//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
//=== | ||
//=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, | ||
//=== Rome - Italy. email: [email protected] | ||
//============================================================================== | ||
|
||
package org.fao.geonet.utils; | ||
|
||
public class EmailUtil { | ||
private static final String OWASP_EMAIL_REGEX = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$"; | ||
private static final java.util.regex.Pattern OWASP_EMAIL_PATTERN = java.util.regex.Pattern.compile(OWASP_EMAIL_REGEX); | ||
|
||
private EmailUtil() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
/** | ||
* Checks if a string contains a valid email address format. | ||
* | ||
* @param emailAddress Value to validate. | ||
* @return true if the value contains a valid email address format, otherwise false. | ||
*/ | ||
public static boolean isValidEmailAddress(String emailAddress) { | ||
return OWASP_EMAIL_PATTERN.matcher(emailAddress).matches(); | ||
} | ||
|
||
/** | ||
* Checks if a string contains valid email link with the format: mailto:emailaddress | ||
* @param link | ||
* @return | ||
*/ | ||
public static boolean isValidEmailLink(final String link) { | ||
return link.startsWith("mailto:") && EmailUtil.isValidEmailAddress(link.replace("mailto:", "")); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
common/src/test/java/org/fao/geonet/utils/EmailUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//============================================================================= | ||
//=== Copyright (C) 2001-2025 Food and Agriculture Organization of the | ||
//=== United Nations (FAO-UN), United Nations World Food Programme (WFP) | ||
//=== and United Nations Environment Programme (UNEP) | ||
//=== | ||
//=== This library is free software; you can redistribute it and/or | ||
//=== modify it under the terms of the GNU Lesser General Public | ||
//=== License as published by the Free Software Foundation; either | ||
//=== version 2.1 of the License, or (at your option) any later version. | ||
//=== | ||
//=== This library is distributed in the hope that it will be useful, | ||
//=== but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
//=== Lesser General Public License for more details. | ||
//=== | ||
//=== You should have received a copy of the GNU Lesser General Public | ||
//=== License along with this library; if not, write to the Free Software | ||
//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
//=== | ||
//=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, | ||
//=== Rome - Italy. email: [email protected] | ||
//============================================================================== | ||
|
||
package org.fao.geonet.utils; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class EmailUtilTest { | ||
@Test | ||
public void testEmailAddress() { | ||
assertEquals(true, EmailUtil.isValidEmailAddress("[email protected]")); | ||
|
||
assertEquals(true, EmailUtil.isValidEmailAddress("[email protected]")); | ||
|
||
assertEquals(true, EmailUtil.isValidEmailAddress("[email protected]")); | ||
|
||
assertEquals(false, EmailUtil.isValidEmailAddress("test.user")); | ||
|
||
assertEquals(false, EmailUtil.isValidEmailAddress("test.user@domain")); | ||
} | ||
|
||
@Test | ||
public void testEmailLink() { | ||
assertEquals(true, EmailUtil.isValidEmailLink("mailto:[email protected]")); | ||
|
||
assertEquals(true, EmailUtil.isValidEmailLink("mailto:[email protected]")); | ||
|
||
assertEquals(true, EmailUtil.isValidEmailLink("mailto:[email protected]")); | ||
|
||
assertEquals(false, EmailUtil.isValidEmailLink("[email protected]")); | ||
|
||
assertEquals(false, EmailUtil.isValidEmailLink("mailto:test.user")); | ||
|
||
assertEquals(false, EmailUtil.isValidEmailLink("mailto:test.user@domain")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters