本文整理汇总了Java中org.jdom.Document类的典型用法代码示例。如果您正苦于以下问题:Java Document类的具体用法?Java Document怎么用?Java Document使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Document类属于org.jdom包,在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isMyType
import org.jdom.Document; //导入依赖的package包/类
/**
* Indicates if a JDom document is an RSS instance that can be parsed with the parser.
* <p/>
* It checks for RDF ("http://www.w3.org/1999/02/22-rdf-syntax-ns#") and
* RSS ("http://purl.org/rss/1.0/") namespaces being defined in the root element.
*
* @param document document to check if it can be parsed with this parser implementation.
* @return <b>true</b> if the document is RSS1., <b>false</b> otherwise.
*/
public boolean isMyType(Document document) {
boolean ok = false;
Element rssRoot = document.getRootElement();
Namespace defaultNS = rssRoot.getNamespace();
List additionalNSs = rssRoot.getAdditionalNamespaces();
ok = defaultNS!=null && defaultNS.equals(getRDFNamespace());
if (ok) {
if (additionalNSs==null) {
ok = false;
}
else {
ok = false;
for (int i=0;!ok && i<additionalNSs.size();i++) {
ok = getRSSNamespace().equals(additionalNSs.get(i));
}
}
}
return ok;
}
示例2: cut
import org.jdom.Document; //导入依赖的package包/类
public static void cut(Document doc) {
// Iterate over all salary elements
Iterator<?> iterator = doc.getDescendants(new ElementFilter("salary"));
// Snapshot these elements before modification
List<Element> elems = new LinkedList<Element>();
while (iterator.hasNext())
elems.add((Element)iterator.next());
// Iterate over salary elements and cut salaries
for (Element elem : elems) {
Double salary = Double.valueOf(elem.getText());
elem.setText(Double.toString(salary/2));
}
}
示例3: isMyType
import org.jdom.Document; //导入依赖的package包/类
public boolean isMyType(Document document) {
boolean ok = false;
Element rssRoot = document.getRootElement();
Namespace defaultNS = rssRoot.getNamespace();
List additionalNSs = rssRoot.getAdditionalNamespaces();
ok = defaultNS!=null && defaultNS.equals(getRDFNamespace());
if (ok) {
if (additionalNSs==null) {
ok = false;
}
else {
ok = false;
for (int i=0;!ok && i<additionalNSs.size();i++) {
ok = getRSSNamespace().equals(additionalNSs.get(i));
}
}
}
return ok;
}
示例4: createService
import org.jdom.Document; //导入依赖的package包/类
@Override
public GoogleAccountsService createService(final HttpServletRequest request) {
final String relayState = request.getParameter(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE);
final String xmlRequest = this.googleSaml20ObjectBuilder.decodeSamlAuthnRequest(
request.getParameter(SamlProtocolConstants.PARAMETER_SAML_REQUEST));
if (StringUtils.isBlank(xmlRequest)) {
LOGGER.trace("SAML AuthN request not found in the request");
return null;
}
final Document document = this.googleSaml20ObjectBuilder.constructDocumentFromXml(xmlRequest);
if (document == null) {
return null;
}
final Element root = document.getRootElement();
final String assertionConsumerServiceUrl = root.getAttributeValue("AssertionConsumerServiceURL");
final String requestId = root.getAttributeValue("ID");
final GoogleAccountsService s = new GoogleAccountsService(assertionConsumerServiceUrl, relayState, requestId);
s.setLoggedOutAlready(true);
return s;
}
示例5: parseSearchResult
import org.jdom.Document; //导入依赖的package包/类
private LyricsInfo parseSearchResult(String xml) throws Exception {
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(new StringReader(xml));
Element root = document.getRootElement();
Namespace ns = root.getNamespace();
String lyric = StringUtils.trimToNull(root.getChildText("Lyric", ns));
String song = root.getChildText("LyricSong", ns);
String artist = root.getChildText("LyricArtist", ns);
return new LyricsInfo(lyric, artist, song);
}
示例6: getCreoleXML
import org.jdom.Document; //导入依赖的package包/类
@Override
public Document getCreoleXML() throws Exception, JDOMException {
Document doc = new Document();
Element element;
doc.addContent(element = new Element("CREOLE-DIRECTORY"));
element.addContent(element = new Element("CREOLE"));
element.addContent(element = new Element("RESOURCE"));
Element classElement = new Element("CLASS");
classElement.setText(resourceClass.getName());
element.addContent(classElement);
return doc;
}
示例7: doGet
import org.jdom.Document; //导入依赖的package包/类
@SuppressWarnings("nls")
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
resp.setContentType("application/x-java-jnlp-file");
resp.setHeader("Cache-Control", "private, max-age=5, must-revalidate");
Document locJnlpDocument = (Document) this.jnlpDocument.clone();
Element jnlpElem = locJnlpDocument.getRootElement();
String instUrl = institutionService.getInstitutionUrl().toString();
jnlpElem.setAttribute("codebase", instUrl);
Element resources = jnlpElem.getChild("resources");
String token = userService.getGeneratedToken(Constants.APPLET_SECRET_ID, CurrentUser.getUsername());
String tokenEncoded = Base64.encodeBase64String(token.getBytes("UTF-8")).replace("\r", "").replace("\n", "");
resources.addContent(createJar(resourcesService.getUrl("com.tle.web.adminconsole", "adminconsole.jar")));
resources.addContent(createProperty(Bootstrap.TOKEN_PARAMETER, tokenEncoded));
resources.addContent(createProperty(Bootstrap.ENDPOINT_PARAMETER, instUrl));
resources.addContent(createProperty(Bootstrap.LOCALE_PARAMETER, CurrentLocale.getLocale().toString()));
resources.addContent(createProperty(Bootstrap.INSTITUTION_NAME_PARAMETER, CurrentInstitution.get().getName()));
xmlOut.output(locJnlpDocument, resp.getWriter());
}
示例8: toDom
import org.jdom.Document; //导入依赖的package包/类
/**
* Convert the received jdom doc to a Document element.
*
* @param doc the doc
* @return the org.w3c.dom. document
*/
private org.w3c.dom.Document toDom(final Document doc) {
try {
final XMLOutputter xmlOutputter = new XMLOutputter();
final StringWriter elemStrWriter = new StringWriter();
xmlOutputter.output(doc, elemStrWriter);
final byte[] xmlBytes = elemStrWriter.toString().getBytes(Charset.defaultCharset());
final DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
dbf.setNamespaceAware(true);
return dbf.newDocumentBuilder().parse(
new ByteArrayInputStream(xmlBytes));
} catch (final Exception e) {
logger.trace(e.getMessage(), e);
return null;
}
}
示例9: createServiceFrom
import org.jdom.Document; //导入依赖的package包/类
/**
* Creates the service from request.
*
* @param request the request
* @param privateKey the private key
* @param publicKey the public key
* @param servicesManager the services manager
* @return the google accounts service
*/
public static GoogleAccountsService createServiceFrom(
final HttpServletRequest request, final PrivateKey privateKey,
final PublicKey publicKey, final ServicesManager servicesManager) {
final String relayState = request.getParameter(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE);
final String xmlRequest = BUILDER.decodeSamlAuthnRequest(
request.getParameter(SamlProtocolConstants.PARAMETER_SAML_REQUEST));
if (!StringUtils.hasText(xmlRequest)) {
return null;
}
final Document document = AbstractSaml20ObjectBuilder.constructDocumentFromXml(xmlRequest);
if (document == null) {
return null;
}
final Element root = document.getRootElement();
final String assertionConsumerServiceUrl = root.getAttributeValue("AssertionConsumerServiceURL");
final String requestId = root.getAttributeValue("ID");
return new GoogleAccountsService(assertionConsumerServiceUrl,
relayState, requestId, privateKey, publicKey, servicesManager);
}
示例10: constructDocumentFromXml
import org.jdom.Document; //导入依赖的package包/类
/**
* Construct document from xml string.
*
* @param xmlString the xml string
* @return the document
*/
public static Document constructDocumentFromXml(final String xmlString) {
try {
final SAXBuilder builder = new SAXBuilder();
builder.setFeature("http://xml.org/sax/features/external-general-entities", false);
builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
return builder
.build(new ByteArrayInputStream(xmlString.getBytes(Charset.defaultCharset())));
} catch (final Exception e) {
return null;
}
}
示例11: toDom
import org.jdom.Document; //导入依赖的package包/类
/**
* Convert the received jdom doc to a Document element.
*
* @param doc the doc
* @return the org.w3c.dom. document
*/
private static org.w3c.dom.Document toDom(final Document doc) {
try {
final XMLOutputter xmlOutputter = new XMLOutputter();
final StringWriter elemStrWriter = new StringWriter();
xmlOutputter.output(doc, elemStrWriter);
final byte[] xmlBytes = elemStrWriter.toString().getBytes(Charset.defaultCharset());
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setFeature("http://apache.org/xml/features/validation/schema/normalized-value", false);
dbf.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
return dbf.newDocumentBuilder().parse(new ByteArrayInputStream(xmlBytes));
} catch (final Exception e) {
LOGGER.trace(e.getMessage(), e);
return null;
}
}
示例12: addImagePlanning
import org.jdom.Document; //导入依赖的package包/类
public static void addImagePlanning(String dbname, File planningFile) throws Exception {
// create xml reader
SAXBuilder builder = new SAXBuilder();
Document doc;
doc = builder.build(planningFile);
Element atts = doc.getRootElement();
// check format first
if (atts.getName().equalsIgnoreCase("imageplanning")) {
// connect to database
Connection conn = DriverManager.getConnection("jdbc:h2:~/.sumo/" + dbname + ";AUTO_SERVER=TRUE", "sa", "");
Statement stat = conn.createStatement();
String sql = "create table if not exists IMAGEPLAN (IMAGE VARCHAR(255), URL VARCHAR(1024), STARTDATE VARCHAR(255), ENDDATE VARCHAR(255), AREA VARCHAR(1024), ACTION VARCHAR(2048))";
stat.execute(sql);
// clear table before filling it in
stat.execute("DELETE FROM IMAGEPLAN");
// scan through images
for (Object o : atts.getChildren("Image")) {
Element element = (Element) o;
// create sql statement
sql = "INSERT INTO IMAGEPLAN VALUES('" + element.getChildText("name") + "', '" + element.getChildText("url") + "', '" + element.getChildText("startDate") + "', '" + element.getChildText("endDate") + "', '" + element.getChildText("area") + "', '" + element.getChildText("action") + "');";
stat.execute(sql);
}
stat.close();
conn.close();
} else {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog(null, "Format not supported", "Error", JOptionPane.ERROR_MESSAGE);
}
});
}
}
示例13: createServiceFrom
import org.jdom.Document; //导入依赖的package包/类
public static GoogleAccountsService createServiceFrom(
final HttpServletRequest request, final PrivateKey privateKey,
final PublicKey publicKey, final String alternateUserName) {
final String relayState = request.getParameter(CONST_RELAY_STATE);
final String xmlRequest = decodeAuthnRequestXML(request
.getParameter(CONST_PARAM_SERVICE));
if (!StringUtils.hasText(xmlRequest)) {
return null;
}
final Document document = SamlUtils
.constructDocumentFromXmlString(xmlRequest);
if (document == null) {
return null;
}
final String assertionConsumerServiceUrl = document.getRootElement().getAttributeValue("AssertionConsumerServiceURL");
final String requestId = document.getRootElement().getAttributeValue("ID");
return new GoogleAccountsService(assertionConsumerServiceUrl,
relayState, requestId, privateKey, publicKey, alternateUserName);
}
示例14: toDom
import org.jdom.Document; //导入依赖的package包/类
private static org.w3c.dom.Document toDom(final Document doc) {
try {
final XMLOutputter xmlOutputter = new XMLOutputter();
final StringWriter elemStrWriter = new StringWriter();
xmlOutputter.output(doc, elemStrWriter);
final byte[] xmlBytes = elemStrWriter.toString().getBytes();
final DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
dbf.setNamespaceAware(true);
return dbf.newDocumentBuilder().parse(
new ByteArrayInputStream(xmlBytes));
} catch (final Exception e) {
return null;
}
}
示例15: processFullCreoleXmlTree
import org.jdom.Document; //导入依赖的package包/类
private void processFullCreoleXmlTree(Plugin plugin,
Document jdomDoc, CreoleAnnotationHandler annotationHandler)
throws GateException, IOException, JDOMException {
// now we can process any annotations on the new classes
// and augment the XML definition
annotationHandler.processAnnotations(jdomDoc);
// debugging
if(DEBUG) {
XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
xmlOut.output(jdomDoc, System.out);
}
// finally, parse the augmented definition with the normal parser
DefaultHandler handler =
new CreoleXmlHandler(this, plugin);
SAXOutputter outputter =
new SAXOutputter(handler, handler, handler, handler);
outputter.output(jdomDoc);
if(DEBUG) {
Out.prln("done parsing " + plugin);
}
}