當前位置: 首頁>>代碼示例>>Java>>正文


Java Document類代碼示例

本文整理匯總了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;
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:31,代碼來源:RSS10Parser.java

示例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));
	}
}
 
開發者ID:amritbhat786,項目名稱:DocIT,代碼行數:17,代碼來源:Cut.java

示例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;
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:22,代碼來源:RSS090Parser.java

示例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;
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:25,代碼來源:GoogleAccountsServiceFactory.java

示例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);
}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:14,代碼來源:LyricsService.java

示例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;
}
 
開發者ID:GateNLP,項目名稱:gate-core,代碼行數:14,代碼來源:Plugin.java

示例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());
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:23,代碼來源:TleJnlpDownloadServlet.java

示例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;
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:23,代碼來源:AbstractSamlObjectBuilder.java

示例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);
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:35,代碼來源:GoogleAccountsService.java

示例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;
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:18,代碼來源:AbstractSamlObjectBuilder.java

示例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;
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:28,代碼來源:AbstractSamlObjectBuilder.java

示例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);
            }
        });
    }

}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:35,代碼來源:H2Fetcher.java

示例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);
}
 
開發者ID:luotuo,項目名稱:cas4.0.x-server-wechat,代碼行數:26,代碼來源:GoogleAccountsService.java

示例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;
    }
}
 
開發者ID:luotuo,項目名稱:cas4.0.x-server-wechat,代碼行數:16,代碼來源:SamlUtils.java

示例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);
  }
}
 
開發者ID:GateNLP,項目名稱:gate-core,代碼行數:24,代碼來源:CreoleRegisterImpl.java


注:本文中的org.jdom.Document類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。