Created
March 23, 2012 13:04
-
-
Save THUFIR/2170467 to your computer and use it in GitHub Desktop.
apache commons nntp
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
thufir@dur:~$ | |
thufir@dur:~$ java -jar NetBeansProjects/Gwene/dist/Gwene.jar | |
Gwene... | |
Settings... | |
initialize.. | |
200 Leafnode NNTP Daemon, version 1.11.8 running at localhost (my fqdn: dur.bounceme.net) | |
GROUP comp.lang.java.help | |
211 37 3 39 comp.lang.java.help group selected | |
XOVER 1-9 | |
224 Overview information for postings 3-9: | |
..initialize | |
subjects... | |
Re: Is there any specific book for learning java projects for beginners? | |
Validating form inputs? | |
Re: Validating form inputs? | |
Re: Validating form inputs? | |
Re: Validating form inputs? | |
Re: Validating form inputs? | |
Re: Validating form inputs? | |
...Gwene | |
thufir@dur:~$ | |
thufir@dur:~$ cat NetBeansProjects/Gwene/src/gwene/NNTPUtils.java | |
/* | |
* Licensed to the Apache Software Foundation (ASF) under one or more | |
* contributor license agreements. See the NOTICE file distributed with | |
* this work for additional information regarding copyright ownership. | |
* The ASF licenses this file to You under the Apache License, Version 2.0 | |
* (the "License"); you may not use this file except in compliance with | |
* the License. You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package gwene; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
import static java.lang.System.out; | |
import java.net.SocketException; | |
import java.util.logging.Logger; | |
import org.apache.commons.net.PrintCommandListener; | |
import org.apache.commons.net.nntp.Article; | |
import org.apache.commons.net.nntp.NNTPClient; | |
import org.apache.commons.net.nntp.Threader; | |
/** | |
* | |
* Some convenience methods for NNTP example classes. | |
* | |
* @author Rory Winston <rwinston@checkfree.com> | |
*/ | |
public class NNTPUtils { | |
private static NNTPClient client = null; | |
//private static List<Article> articles = null; | |
private static final Logger logger = Logger.getLogger(NNTPUtils.class.getName()); | |
private static final Settings settings = null; | |
private static Iterable<Article> articles = null; | |
public static void initialize(Settings settings) throws SocketException, IOException { | |
out.println("initialize.."); | |
client = new NNTPClient(); | |
client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true)); | |
client.connect(settings.getServer()); | |
client.group(settings.getGroup()); | |
articles = client.iterateArticleInfo(settings.getLowArticleNumber(), settings.getHightArticleNumber()); | |
out.println("..initialize"); | |
} | |
public static void Thread() throws IOException { | |
System.out.println("Building message thread tree..."); | |
Threader threader = new Threader(); | |
Article root = (Article) threader.thread(articles); | |
Article.printThread(root, 0); | |
} | |
public static void subjects() { | |
out.println("subjects..."); | |
for (Article article : articles) { | |
if (article.isDummy()) { // Subject will contain raw response | |
System.out.println("Could not parse: " + article.getSubject()); | |
} else { | |
System.out.println(article.getSubject()); | |
} | |
} | |
} | |
} | |
thufir@dur:~$ | |
thufir@dur:~$ | |
thufir@dur:~$ telnet localhost nntp | |
Trying 127.0.0.1... | |
Connected to localhost. | |
Escape character is '^]'. | |
200 Leafnode NNTP Daemon, version 1.11.8 running at localhost (my fqdn: dur.bounceme.net) | |
group comp.lang.java.help | |
211 37 3 39 comp.lang.java.help group selected | |
next | |
223 4 <ed7f31e9-8a19-46c7-9a7c-ad8aabfb9599@x10g2000pbi.googlegroups.com> article retrieved | |
body | |
222 4 <ed7f31e9-8a19-46c7-9a7c-ad8aabfb9599@x10g2000pbi.googlegroups.com> article retrieved - body follows | |
I have been thinking about the way I have been validating form inputs | |
in the servelet and wonder if I would be much better off using class | |
methods to verify these inputs? | |
Consider that I am almost always gathering the inputs to instantiate | |
one or more objects, but I gather and validate -- and then | |
instantiate. Maybe I should instantiate an empty object and then use | |
class methods to validate the inputs? | |
Thanks | |
. | |
next | |
223 5 <uA4ar.13560$fj7.13111@newsfe20.iad> article retrieved | |
body | |
222 5 <uA4ar.13560$fj7.13111@newsfe20.iad> article retrieved - body follows | |
On 3/20/12 11:16 AM, Davej wrote: | |
> I have been thinking about the way I have been validating form inputs | |
> in the servelet and wonder if I would be much better off using class | |
> methods to verify these inputs? | |
> | |
> Consider that I am almost always gathering the inputs to instantiate | |
> one or more objects, but I gather and validate -- and then | |
> instantiate. Maybe I should instantiate an empty object and then use | |
> class methods to validate the inputs? | |
> | |
> Thanks | |
There are a few frameworks that do this in several phases actually. Its | |
called binding and validating. | |
In the binding phase, values are parsed into appropriate data types, and | |
stored in the model (Form object as it is sometimes called). If the | |
data can not be parsed, or the model rejects the value immediately, it | |
is a binding error. | |
In the validation phase, the values are checked for correctness. This is | |
often a secondary phase because some values are interdependent. | |
If, after validation, you want to have an immutable object, then you | |
could treat your Form object more as a Builder object, and have it | |
construct the Real object, which is fully populated and validated. | |
Alternatively, you could use the Form object as a "Parameter" object for | |
a different Builder class, to keep the concerns of the Form object more | |
pure. | |
I suggest looking into different frameworks, rather than trying to | |
roll-your-own. There are a lot of gotchas that can be avoided, and | |
boilerplate code you can rid yourself of. I've had moderate luck with | |
Spring Binding. If you have typical use-cases it works well. If you | |
have more complicated forms, for instance complex dynamic items, then | |
there is some shoehorning needed to make it work correctly. | |
Hope this helps, | |
Daniel. | |
. | |
quit | |
205 Always happy to serve! | |
Connection closed by foreign host. | |
thufir@dur:~$ | |
thufir@dur:~$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment