package org.jivesoftware.util;
import org.dom4j.*;
import org.dom4j.io.OutputFormat;
import org.dom4j.tree.NamespaceStack;
import org.xml.sax.*;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.XMLFilterImpl;
import java.io.*;
import java.util.*;
/**
* Replacement class of the original XMLWriter.java (version: 1.77) since the original is still
* using StringBuffer which is not fast.
*/
public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
private static final String PAD_TEXT = " ";
protected static final String[] LEXICAL_HANDLER_NAMES = {
"http://xml.org/sax/properties/lexical-handler",
"http://xml.org/sax/handlers/LexicalHandler"
};
protected static final OutputFormat DEFAULT_FORMAT = new OutputFormat();
/** Should entityRefs by resolved when writing ? */
private boolean resolveEntityRefs = true;
/** Stores the last type of node written so algorithms can refer to the
* previous node type */
protected int lastOutputNodeType;
/** Stores the xml:space attribute value of preserve for whitespace flag */
protected boolean preserve=false;
/** The Writer used to output to */
protected Writer writer;
/** The Stack of namespaceStack written so far */
private NamespaceStack namespaceStack = new NamespaceStack();
/** The format used by this writer */
private OutputFormat format;
/** whether we should escape text */
private boolean escapeText = true;
/** The initial number of indentations (so you can print a whole
document indented, if you like) **/
private int indentLevel = 0;
/** buffer used when escaping strings */
private StringBuilder buffer = new StringBuilder();
/** whether we have added characters before from the same chunk of characters */
private boolean charactersAdded = false;
private char lastChar;
/** Whether a flush should occur after writing a document */
private boolean autoFlush;
/** Lexical handler we should delegate to */
private LexicalHandler lexicalHandler;
/** Whether comments should appear inside DTD declarations - defaults to false */
private boolean showCommentsInDTDs;
/** Is the writer curerntly inside a DTD definition? */
private boolean inDTD;
/** The namespaces used for the current element when consuming SAX events */
private Map namespacesMap;
/**
* what is the maximum allowed character code
* such as 127 in US-ASCII (7 bit) or 255 in ISO-* (8 bit)
* or -1 to not escape any characters (other than the special XML characters like < > &)
*/
private int maximumAllowedCharacter;
public XMLWriter(Writer writer) {
this( writer, DEFAULT_FORMAT );
}
public XMLWriter(Writer writer, OutputFormat format) {
this.writer = writer;
this.format = format;
namespaceStack.push(Namespace.NO_NAMESPACE);
}
public XMLWriter() throws UnsupportedEncodingException {
this.format = DEFAULT_FORMAT;
this.writer = new BufferedWriter( new OutputStreamWriter( System.out, "UTF-8" ) );
this.autoFlush = true;
namespaceStack.push(Namespace.NO_NAMESPACE);
}
public XMLWriter(OutputStream out) throws UnsupportedEncodingException {
this.format = DEFAULT_FORMAT;
this.writer = createWriter(out, format.getEncoding());
this.autoFlush = true;
namespaceStack.push(Namespace.NO_NAMESPACE);
}
public XMLWriter(OutputStream out, OutputFormat format) throws UnsupportedEncodingException {
this.format = format;
this.writer = createWriter(out, format.getEncoding());
this.autoFlush = true;
namespaceStack.push(Namespace.NO_NAMESPACE);
}
public XMLWriter(OutputFormat format) throws UnsupportedEncodingException {
this.format = format;
this.writer = createWriter( System.out, format.getEncoding() );
this.autoFlush = true;
namespaceStack.push(Namespace.NO_NAMESPACE);
}
public void setWriter(Writer writer) {
this.writer = writer;
this.autoFlush = false;
}
public void setOutputStream(OutputStream out) throws UnsupportedEncodingException {
this.writer = createWriter(out, format.getEncoding());
this.autoFlush = true;
}
/**
* @return true if text thats output should be escaped.
* This is enabled by default. It could be disabled if
* the output format is textual, like in XSLT where we can have
* xml, html or text output.
*/
public boolean isEscapeText() {
return escapeText;
}
/**
* Sets whether text output should be escaped or not.
* This is enabled by default. It could be disabled if
* the output format is textual, like in XSLT where we can have
* xml, html or text output.
*/
public void setEscapeText(boolean escapeText) {
this.escapeText = escapeText;
}
/** Set the initial indentation level. This can be used to output
* a document (or, more likely, an element) starting at a given
* indent level, so it's not always flush against the left margin.
* Default: 0
*
* @param indentLevel the number of indents to start with
*/
public void setIndentLevel(int indentLevel) {
this.indentLevel = indentLevel;
}
/**
* Returns the maximum allowed character code that should be allowed
* unescaped which defaults to 127 in US-ASCII (7 bit) or
* 255 in ISO-* (8 bit).
*/
public int getMaximumAllowedCharacter() {
if (maximumAllowedCharacter == 0) {
maximumAllowedCharacter = defaultMaximumAllowedCharacter();
}
return maximumAllowedCharacter;
}
/**
* Sets the maximum allowed character code that should be allowed
* unescaped
* such as 127 in US-ASCII (7 bit) or 255 in ISO-* (8 bit)
* or -1 to not escape any characters (other than the special XML characters like < > &)
*
* If this is not explicitly set then it is defaulted from the encoding.
*
* @param maximumAllowedCharacter The maximumAllowedCharacter to set
*/
public void setMaximumAllowedCharacter(int maximumAllowedCharacter) {
this.maximumAllowedCharacter = maximumAllowedCharacter;
}
/** Flushes the underlying Writer */
public void flush() throws IOException {
writer.flush();
}
/** Closes the underlying Writer */
public void close() throws IOException {
writer.close();
}
/** Writes the new line text to the underlying Writer */
public void println() throws IOException {
writer.write( format.getLineSeparator() );
}
/** Writes the given {@link org.dom4j.Attribute}.
*
* @param attribute <code>Attribute</code> to output.
*/
public void write(Attribute attribute) throws IOException {
writeAttribute(attribute);
if ( autoFlush ) {
flush();
}
}
/** <p>This will print the <code>Document</code> to the current Writer.</p>
*
* <p> Warning: using your own Writer may cause the writer's
* preferred character encoding to be ignored. If you use
* encodings other than UTF8, we recommend using the method that
* takes an OutputStream instead. </p>
*
* <p>Note: as with all Writers, you may need to flush() yours
* after this method returns.</p>
*
* @param doc <code>Document</code> to format.
* @throws IOException - if there's any problem writing.
**/
public void write(Document doc) throws IOException {
writeDeclaration();
if (doc.getDocType() != null) {
indent();
writeDocType(doc.getDocType());
}
for ( int i = 0, size = doc.nodeCount(); i < size; i++ ) {
Node node = doc.node(i);
writeNode( node );
}
writePrintln();
if ( au
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 -------- 下载后请首先打开README.md文件(如有),仅供学习参考。
资源推荐
资源详情
资源评论
收起资源包目录
我的毕业设计《Android平台校园消息推送服务的设计与实现》.zip (355个子文件)
.mymetadata.bak 287B
XMLWriter.class 25KB
StanzaHandler.class 10KB
Connection.class 9KB
XMPPPacketReader.class 9KB
IQJoinGroupHandler.class 8KB
IQRouter.class 7KB
XMLLightweightParser.class 6KB
ClientSession.class 6KB
IQSendMessage4GroupHandler.class 6KB
IQNotificationList4Group.class 6KB
IQUserGroupListHandler.class 6KB
SessionManager.class 6KB
Session.class 5KB
XmppIoHandler.class 5KB
IQUserLoginHandler.class 5KB
IQAuthHandler.class 5KB
IQHandleGroupRequestHandler.class 5KB
IQGroupRequestListHandler.class 5KB
SSLConfig.class 5KB
IQRegisterHandler.class 5KB
IQUserRegisterHandler.class 5KB
MXParser.class 4KB
IQGoupMemberListHandler.class 4KB
NotificationManager.class 4KB
TotalNotificationServiceImpl.class 4KB
IQChangePushable4GroupHandler.class 4KB
IQCreateGroupHandler.class 4KB
XmppServer.class 4KB
AuthManager.class 4KB
IQOutMember4GroupHandler.class 4KB
IQSearchGroupHandler.class 4KB
UserApiController.class 3KB
SessionController.class 3KB
PresenceUpdateHandler.class 3KB
TotalNotificationDaoHibernate.class 3KB
ErrorCode.class 3KB
GroupMemberDaoHibernate.class 3KB
IQDeliverConfirmHandler.class 3KB
ApnUser.class 3KB
TotalNotification.class 3KB
ApnUserDaoHibernate.class 3KB
PropertyEventDispatcher.class 3KB
PresenceRouter.class 3KB
NotificationApiController.class 3KB
Config.class 3KB
SSLKeyManagerFactory.class 3KB
ApnUserServiceImpl.class 3KB
UserGroupServiceImpl.class 3KB
IQHandler.class 2KB
SSLTrustManagerFactory.class 2KB
NotificationController.class 2KB
GroupMember.class 2KB
GroupRequestDaoHibernate.class 2KB
ServiceLocator.class 2KB
UserDaoHibernate.class 2KB
UserGroupDaoHibernate.class 2KB
UserGroup.class 2KB
UserController.class 2KB
GroupRequest.class 2KB
ConfigManager.class 2KB
GroupMemberServiceImpl.class 2KB
UserServiceImpl.class 2KB
User.class 2KB
PacketDeliverer.class 2KB
XMLLightweightParser$PropertyListener.class 2KB
NotificationHistory.class 2KB
GroupRequestServiceImpl.class 2KB
UnconfirmedNotification.class 2KB
SessionVO.class 2KB
PacketRouter.class 2KB
SessionManager$ClientSessionListener.class 1KB
PresenceManager.class 1KB
XmppDecoder.class 1KB
PropertyEventDispatcher$EventType.class 1KB
Connection$ClientAuth.class 1KB
Connection$TLSPolicy.class 1KB
XmppCodecFactory.class 1KB
IoBufferWriter.class 1KB
XmppServer$ShutdownHookThread.class 1KB
TotalNotificationService.class 1KB
AuthToken.class 1000B
DemoAndroidpn.class 992B
XmppServer$ShutdownThread.class 916B
XmppEncoder.class 912B
ServiceManager.class 892B
ApnUserNotFoundException.class 874B
TotalNotificationDao.class 871B
ApnUserExistsException.class 868B
Connection$ThreadLocalEncoder.class 853B
UnauthenticatedException.class 848B
UnauthorizedException.class 839B
PacketException.class 828B
ApnUserDao.class 823B
IQRosterHandler.class 785B
ApnUserService.class 739B
GroupMemberService.class 629B
UserGroupService.class 625B
GroupMemberDao.class 618B
MessageRouter.class 580B
共 355 条
- 1
- 2
- 3
- 4
资源评论
程皮
- 粉丝: 256
- 资源: 2485
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功