/*
* URIParser.java 1.0 February 2001
*
* Copyright (C) 2001, Niall Gallagher <niallg@email.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
package simple.util.parse;
import simple.util.net.Path;
import simple.util.net.URI;
import java.util.Enumeration;
import java.util.Hashtable;
/**
* This parser is used to parse uniform resource identifiers.
* The uniform resource identifier syntax is given in RFC 2396.
* This parser can parse relative and absolute URI's. The
* uniform resource identifier syntax that this parser will
* parse are based on the generic web based url similar to
* the syntax represented in RFC 2616 section 3.2.2. The syntax
* used to parse this URI is a modified version of RFC 2396
* <code><pre>
*
* URI = (absoluteURI | relativeURI)
* absoluteURI = scheme ":" ("//" netpath | relativeURI)
* relativeURI = path ["?" querypart]
* netpath = domain [":" port] relativeURI
* path = *("/" segment)
* segment = *pchar *( ";" param )
*
* </pre></code>
* This implements the <code>URI</code> interface and provides
* methods that access the various parts of the URI. The parameters
* in the path segments of the uniform resource identifier are
* stored in name value pairs. If parameter names are not unique
* across the path segments then only the deepest parameter will be
* stored from the path segment. For example if the URI represented
* was <code>http://domain/path1;x=y/path2;x=z</code> the value for
* the parameter named <code>x</code> would be <code>z</code>.
* <p>
* This will normalize the path part of the uniform resource
* identifier. A normalized path is one that contains no back
* references like "./" and "../". The normalized path will not
* contain the path parameters.
* <p>
* The <code>setPath</code> method is used to reset the path this
* uniform resource identifier has, it also resets the parameters.
* The parameters are extracted from the new path given.
*
* @author Niall Gallagher
* @version 1.0
*/
public class URIParser extends Parser implements URI {
/**
* Used to buffer the characters that form the path.
*/
private ParseBuffer path;
/**
* Used to buffer the characters that form the domain.
*/
private ParseBuffer domain;
/**
* Used to buffer the characters that form the query.
*/
private ParseBuffer query;
/**
* Used to buffer the name characters of a parameter.
*/
private ParseBuffer name;
/**
* Used to buffer the value characters of a parameter.
*/
private ParseBuffer value;
/**
* References the scheme that this URI contains.
*/
private ParseBuffer scheme;
/**
* Used to normalize the path section of the URI.
*/
private PathParser parser;
/**
* Parameters are stored so that the can be viewed.
*/
private Hashtable param;
/**
* Indicates wheather the path part has beed parsed.
*/
private boolean isParsed;
/**
* Contains the port number if it was specified.
*/
private int port;
/**
* Default constructor will create a <code>URIParser</code>
* that contains no specifics. The instance will return
* <code>null</code> for all the get methods. The parsers
* get methods are populated by using the <code>parse</code>
* method.
*/
public URIParser(){
this(32);
}
/**
* This constructor is used so that the memory used by the parser
* can be optimized. This will set the <code>ParseBuffer</code>
* lengths to be the length specified. This allows for the use of
* the <code>URIParser(String)</code> constructor to maximize
* its efficency so that a <code>ParseBuffer.expandCapacity</code>
* will not be needed if they are too short. This also helps if
* the path being parsed is small. It enables little memory to
* be used when only little memory is needed.
* <p>
* This can also be used when the <code>URIParser</code> object
* is a static or singelton instance. If the parser is used with
* <code>URIParser.parse(String)</code> many times it is best to
* keep a large length so a <code>ParseBuffer.expandCapacity</code>
* will not be needed for an arbitrary input.
*
* @param len this is used so that the <code>URIParser</code>
* can be used more efficently
*/
public URIParser(int len) {
path = new ParseBuffer(len);
parser = new PathParser();
domain = new ParseBuffer();
query = new ParseBuffer();
scheme = new ParseBuffer();
name = new ParseBuffer();
value = new ParseBuffer();
param = new Hashtable();
}
/**
* This is primarily a convineance constructor. This will parse
* the <code>String</code> given to extract the specifics. This
* could be achived by calling the default no-arg constructor
* and then using the instance to invoke the <code>parse</code>
* method on that <code>String</code> to extract the parts.
*
* @param uri a <code>String</code> containing a uri value
*/
public URIParser(String uri){
this(uri.length());
parse(uri);
}
/**
* This is used to retrive the domain of this URI. The
* domain part in the URI is an optional part, an example
* <code>http://domain/path?querypart</code>. This will
* return the value of the domain part. If there is no
* domain part then this will return null otherwise the
* domain value found in the uniform resource identifier.
*
* @return the domain part of this uniform resource
* identifier this represents
*/
public String getDomain(){
if(domain.length() == 0){
return null;
}
return domain.toString();
}
/**
* This is used to retrive the path of this URI. The path part
* is the most fundemental part of the URI. This will return
* the value of the path. If there is no path part then this
* will return <code>/</code> to indicate the root.
* <p>
* The <code>Path</code> object returned by this will contain
* no path parameters. The path parameters are available using
* the <code>URI</code> methods. The reason that this does not
* contain any of the path parameters is so that if the path is
* needed to be converted into ab OS specific path then the path
* parameters will not need to be seperately parsed out.
*
* @return the path that this URI contains, this value will not
* contain any back references such as "./" and "../" or any
* path parameters
*/
public Path getPath(){
if(path.length() == 0){
parser.parse("/");
} else if(!isParsed) {
parser.parse("" + path);
isParsed = true;
}
return parser;
}
/**
* This is used to retrive the port of the uniform resource
* identifier. The port part in this is an optional part, an
* example <code>http://host:port/path?querypart</code>. This
* will return the value of the port. If there is no port then
* this will return <code>-1</code> because this represents
* an impossible uniform resource identifier port. The port
* is an optiona
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Simple是一个异步的HTTP引擎,能够用数量有限的服务线程扩展更多负荷。在传输层运用NIO,确保响应和资源的效率。它具有充分综合的API,开发比Java Servlet的API更方便。 1.高性能的HTTP内核 Simple比流行的商业和开放源代码的Java HTTP服务器更胜一筹。就目前的基准与Jetty和AsyncWeb相比较,它拥有更高的throughput,而且在增加负荷时,它的规模要好得多。(比较结果显示) 2.异步处理 从一开始做项目的目标就是提供一个真正的异步HTTP引擎。当您需要启动一个可能耗费很长时间的应用程序进程,而用户又无需等候进程完成以便从服务器获取响应时,异步处理程序非常有用。服务器提供了允许 request completion,以推动使用internal,transparent和monitoring系统。这比目前的Servlet引擎简单了许多。 3.嵌入式框架 Simple提供一个框架,并且可以嵌入到任何现有的应用程序之中。与Spring 框架结合更完美。 4.占用内存小 尽管具有很高的扩展性,但是Simple占用的内存却很小。用最近的基准来与比其他的NIO服务器(Jetty and AsyncWeb)比较,它占用的内存空间几乎要少一半。 5.完全独立 它没有外部dependancies。除Java 5 SDK或以上,不需要任何其他的库。这样也使得内存占用少,并且确保在整合现有的应用程序时不存在任何的兼容问题。 6.开放源代码 发布基于LGPL,可完全整合或改装为商业和开放源代码的项目。
资源推荐
资源详情
资源评论
收起资源包目录
Simple 2.0 - Java HTTP 引擎 (125个子文件)
URIParser.java 33KB
Buffer.java 27KB
FilterResponse.java 24KB
FileContext.java 24KB
LoaderEngine.java 23KB
MonitoredResponse.java 22KB
FilterRequest.java 21KB
PathParser.java 21KB
Resolver.java 20KB
CookieParser.java 19KB
RequestHeader.java 17KB
DateParser.java 16KB
ResponseHeader.java 16KB
HeaderParser.java 15KB
Context.java 15KB
MonitoredRequest.java 14KB
MimeParser.java 14KB
Response.java 13KB
ChunkedInputStream.java 13KB
LoaderManager.java 12KB
ChunkedOutputStream.java 11KB
URI.java 11KB
LanguageParser.java 11KB
DefaultFormat.java 11KB
PrincipalParser.java 11KB
FileEngine.java 11KB
GenericHeader.java 10KB
LRUList.java 10KB
PlainProfile.java 10KB
Monitor.java 9KB
DefaultPoller.java 9KB
Scheduler.java 9KB
Poller.java 9KB
Registry.java 9KB
PriorityQueue.java 9KB
HeaderList.java 9KB
RequestParser.java 9KB
FixedInputStream.java 9KB
Cache.java 8KB
Request.java 8KB
BasicResource.java 8KB
RunQueue.java 8KB
Format.java 8KB
PipelineProcessor.java 8KB
PlainPoller.java 8KB
ResponseStream.java 8KB
MonitoredInputStream.java 7KB
ObjectQueue.java 7KB
Profile.java 7KB
Pipeline.java 7KB
Parser.java 7KB
Cookie.java 7KB
MonitoredOutputStream.java 7KB
ParseBuffer.java 6KB
ConnectionFactory.java 6KB
FilterPipeline.java 6KB
IndexedResource.java 6KB
Registry.java 6KB
DomainHandler.java 6KB
Processor.java 5KB
MimeType.java 5KB
FixedOutputStream.java 5KB
Path.java 5KB
SchedulerQueue.java 5KB
SizelineParser.java 5KB
BufferContent.java 5KB
ResponseChannel.java 5KB
PipelineHandlerFactory.java 5KB
PulseScheduler.java 5KB
Daemon.java 5KB
DirectoryResource.java 4KB
CachedResource.java 4KB
ChannelContent.java 4KB
FileResource.java 4KB
Processor.java 4KB
Attributes.java 4KB
SocketHandler.java 4KB
Dispatcher.java 4KB
Processor.java 4KB
ActiveService.java 4KB
SequenceEnumerator.java 4KB
Indexable.java 4KB
PollerInputStream.java 4KB
PlainLayout.java 4KB
PlainHeader.java 3KB
RequestLine.java 3KB
PollerHandler.java 3KB
StatusLine.java 3KB
Profile.java 3KB
FormatFactory.java 3KB
Enumerator.java 3KB
ResourceEngine.java 3KB
CacheCleaner.java 3KB
CacheReference.java 3KB
ByteStore.java 3KB
ChunkedMonitor.java 3KB
ProtocolHandler.java 3KB
PipelineHandler.java 3KB
Service.java 3KB
Layout.java 3KB
共 125 条
- 1
- 2
资源评论
CApp
- 粉丝: 23
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 2024年下半年软考中级网络工程师手工负载分担模式链路聚合配置实验
- java二手车销售管理系统源码(前台+后台)数据库 MySQL源码类型 WebForm
- VC++2019 访问和操作SQLite数据的例子
- 2024年下半年软考中级网络工程师lacp模式链路聚合配置实验
- 使用JS脚本实现spotfire分析弹出窗口demo,自用
- 2024年下半年软考中级网络工程师lacp配置实验
- 基于MATLAB的车牌识别实现车牌定位系统【GUI含界面】.zip
- 基于MATLAB的车牌识别实现车牌定位代码【含界面GUI】.zip
- 基于MATLAB的车牌识别实现车牌定位代码【含界面GUI】(1).zip
- 2024年下半年软考中级网络工程师小型园区组网配置实验
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功