📄 emailcontenthandler.java
字号:
/*
* WebLogic Server Unleashed
*
*/
package com.wlsunleashed.xml.sax;
import com.wlsunleashed.xml.sax.email.EMail;
import com.wlsunleashed.xml.sax.email.EMailAddress;
import com.wlsunleashed.xml.sax.email.EMailOptions;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
/**
* This class provides a simple content handler implementation for
* the email client.
*
* @version 1.0
*/
public class EMailContentHandler implements ContentHandler {
/** The e-mail object */
private EMail eMail = null;
/** Provides information about the parsing process. */
private Locator documentLocator = null;
/** A temporary string buffer to hold the contents of elements */
private StringBuffer contentString = null;
/**
* @see org.xml.sax.ContentHandler#setDocumentLocator(Locator)
*/
public void setDocumentLocator(Locator locator) {
documentLocator = locator;
}
/**
* Returns the eMail.
*
* @return EMail
*/
public EMail getEMail() {
return eMail;
}
/**
* @see org.xml.sax.ContentHandler#characters(char[], int, int)
*/
public void characters(char[] chars, int start, int end)
throws SAXException {
contentString.append(chars, start, end);
}
/**
* @see org.xml.sax.ContentHandler#endDocument()
*/
public void endDocument()
throws SAXException {
System.out.println("Processing has ended!");
}
/**
* @see org.xml.sax.ContentHandler#endElement(String, String, String)
*/
public void endElement(String namespaceURI, String localName, String qName)
throws SAXException {
if (localName.equals("subject")) {
eMail.setSubject(contentString.toString());
contentString = new StringBuffer();
return;
}
if (localName.equals("body")) {
eMail.setBody(contentString.toString());
contentString = new StringBuffer();
return;
}
}
/**
* @see org.xml.sax.ContentHandler#endPrefixMapping(String)
*/
public void endPrefixMapping(String prefix)
throws SAXException {
}
/**
* @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
*/
public void ignorableWhitespace(char[] chars, int start, int end)
throws SAXException {
System.out.println("ignorableWhiteSpace "
+ documentLocator.getLineNumber() + " - "
+ documentLocator.getColumnNumber() + " - " + start
+ " - " + end);
}
/**
* @see org.xml.sax.ContentHandler#processingInstruction(String, String)
*/
public void processingInstruction(String target, String data)
throws SAXException {
}
/**
* @see org.xml.sax.ContentHandler#skippedEntity(String)
*/
public void skippedEntity(String entityName)
throws SAXException {
}
/**
* @see org.xml.sax.ContentHandler#startDocument()
*/
public void startDocument()
throws SAXException {
System.out.println("Processing begins ... ");
eMail = new EMail();
}
/**
* @see org.xml.sax.ContentHandler#startElement(String, String, String,
* Attributes)
*/
public void startElement(String namespaceURI, String localName,
String qName, Attributes attributes)
throws SAXException {
if (localName.equals("from")) {
eMail.setFromAddress(
new EMailAddress(attributes.getValue(0),
attributes.getValue(1)));
return;
}
if (localName.equals("to")) {
eMail.addToAddress(
new EMailAddress(attributes.getValue(0),
attributes.getValue(1)));
return;
}
if (localName.equals("cc")) {
eMail.addCcAddress(
new EMailAddress(attributes.getValue(0),
attributes.getValue(1)));
return;
}
if (localName.equals("options")) {
eMail.setOptions(new EMailOptions());
return;
}
if (localName.equals("read_receipt")) {
eMail.getOptions().setReadReceipt(true);
return;
}
if (localName.equals("priority")) {
eMail.getOptions().setImportance(attributes.getValue(0));
return;
}
if (localName.equals("subject") || localName.equals("body")) {
contentString = new StringBuffer();
return;
}
}
/**
* @see org.xml.sax.ContentHandler#startPrefixMapping(String, String)
*/
public void startPrefixMapping(String prefix, String URI)
throws SAXException {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -