本文整理匯總了Java中org.jdom2.JDOMException類的典型用法代碼示例。如果您正苦於以下問題:Java JDOMException類的具體用法?Java JDOMException怎麽用?Java JDOMException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JDOMException類屬於org.jdom2包,在下文中一共展示了JDOMException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDocumentFromString
import org.jdom2.JDOMException; //導入依賴的package包/類
/**
* Create a JDOM document from an XML string.
*
* @param string
* @param encoding
* @return
* @throws IOException
* @throws JDOMException
* @should build document correctly
*/
public static Document getDocumentFromString(String string, String encoding) throws JDOMException, IOException {
if (encoding == null) {
encoding = DEFAULT_ENCODING;
}
byte[] byteArray = null;
try {
byteArray = string.getBytes(encoding);
} catch (UnsupportedEncodingException e) {
}
ByteArrayInputStream baos = new ByteArrayInputStream(byteArray);
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(baos);
return document;
}
示例2: getDocumentFromString
import org.jdom2.JDOMException; //導入依賴的package包/類
/**
* Create a JDOM document from an XML string.
*
* @param string
* @return
* @throws IOException
* @throws JDOMException
* @should build document correctly
*/
public static Document getDocumentFromString(String string, String encoding) throws JDOMException, IOException {
if (string == null) {
throw new IllegalArgumentException("string may not be null");
}
if (encoding == null) {
encoding = "UTF-8";
}
byte[] byteArray = null;
try {
byteArray = string.getBytes(encoding);
} catch (UnsupportedEncodingException e) {
}
ByteArrayInputStream baos = new ByteArrayInputStream(byteArray);
// Reader reader = new StringReader(hOCRText);
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(baos);
return document;
}
示例3: parseXml
import org.jdom2.JDOMException; //導入依賴的package包/類
public void parseXml(String fileName){
SAXBuilder builder = new SAXBuilder();
File file = new File(fileName);
try {
Document document = (Document) builder.build(file);
Element rootNode = document.getRootElement();
List list = rootNode.getChildren("author");
for (int i = 0; i < list.size(); i++) {
Element node = (Element) list.get(i);
System.out.println("First Name : " + node.getChildText("firstname"));
System.out.println("Last Name : " + node.getChildText("lastname"));
}
} catch (IOException io) {
System.out.println(io.getMessage());
} catch (JDOMException jdomex) {
System.out.println(jdomex.getMessage());
}
}
示例4: retrieveAuthor
import org.jdom2.JDOMException; //導入依賴的package包/類
/**
* gets an author from the database by determining the type of the provided id. if no author is present it builds one from the id.
* @param id the author identifier
* @return the author retrieved from the database or build with the identifier
* @throws JDOMException thrown upon parsing the source response
* @throws IOException thrown upon reading profiles from disc
* @throws SAXException thrown when parsing the files from disc
*/
public PublicationAuthor retrieveAuthor(String id) throws JDOMException, IOException, SAXException {
typeOfID = determineID(id);
LOGGER.info("given ID: " + id + " is of type " + typeOfID);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("publicationAuthors");
EntityManager em = emf.createEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<PublicationAuthor> q = cb.createQuery(PublicationAuthor.class);
Root<PublicationAuthor> c = q.from(PublicationAuthor.class);
List<Predicate> predicates = new ArrayList<>();
if (typeOfID.equals("surname")) {
if (id.contains(",")) {
predicates.add(cb.equal(c.get("surname"),id.substring(0,id.indexOf(","))));
predicates.add(cb.equal(c.get("firstname"),id.substring(id.indexOf(",")+1)));
LOGGER.info("retriving surname, firstname from database for " + id);
} else if (id.contains(" ")) {
predicates.add(cb.equal(c.get("firstname"),id.substring(0,id.indexOf(" "))));
predicates.add(cb.equal(c.get("surname"),id.substring(id.indexOf(" ")+1)));
LOGGER.info("retrieving firstname surname from database for " + id);
} else {
predicates.add(cb.equal(c.get("surname"), id));
LOGGER.info("retrieving surname from database for " + id);
}
}
predicates.add(cb.equal(c.get(typeOfID), id));
q.select(c).where(cb.equal(c.get(typeOfID), id));
TypedQuery<PublicationAuthor> query = em.createQuery(q);
List<PublicationAuthor> authors = query.getResultList();
em.close();
if (authors.size() == 1) {
LOGGER.info("found author in database");
this.author = authors.get(0);
return author;
}
LOGGER.info("no match in database");
return buildAuthor(id);
}
示例5: retrieveScopusAuthorID
import org.jdom2.JDOMException; //導入依賴的package包/類
/**
* retrieves the ScopusAuthorID for an author and puts it into the <code>PublicationAuthor</code> object
* @throws HttpException thrown upon connecting to the source
* @throws JDOMException thrown upon parsing the source response
* @throws IOException thrown upon reading profiles from disc
* @throws SAXException thrown when parsing the files from disc
*/
public void retrieveScopusAuthorID() throws HttpException, JDOMException, IOException, SAXException {
ScopusConnector connection = new ScopusConnector();
Element result = connection.retrieveScopusAuthorID(author).asXML().detachRootElement().clone();
List<String> allIDs = new ArrayList<>();
for (Element child : result.getChildren()) {
if (result.getName().equals("error")) continue;
if (child.getName().equals("entry")) {
Element identifier = child.getChild("identifier",DC_NS);
String value = identifier.getValue().replace("AUTHOR_ID:", "");
allIDs.add(value);
}
}
if (allIDs.size() == 1) {
author.setScopusAuthorID(allIDs.get(0));
LOGGER.info("found ScopusID: " + author.getScopusAuthorID());
} else
author.setScopusAuthorID(toBeChecked);
}
示例6: createGeoJsonPoint
import org.jdom2.JDOMException; //導入依賴的package包/類
public JSONObject createGeoJsonPoint() throws HttpException, JDOMException, IOException, SAXException {
JSONObject geoJSONInd = new JSONObject();
JSONObject geometry = new JSONObject();
geometry.put("type", "Point");
JSONArray coordinates = new JSONArray();
coordinates.put(longitude).put(latitude);
geometry.put("coordinates", coordinates);
geoJSONInd.put("geometry", geometry);
geoJSONInd.put("type", "Feature");
JSONObject properties = new JSONObject();
properties.put("name", city);
geoJSONInd.put("properties", properties);
String description = institution;
if (!department.isEmpty())
description = description + "<br />" + department;
properties.put("popupContent", description);
return geoJSONInd;
}
示例7: getNumberOfPublications
import org.jdom2.JDOMException; //導入依賴的package包/類
private int getNumberOfPublications(String queryURL) throws JDOMException, IOException, SAXException {
//build API URL
//get response as XML-file
Document response = getResponse(queryURL).asXML();
int numberOfPublications =0;
//read and return total number of publications from XML-file
try {
numberOfPublications = Integer.parseInt(response.getRootElement().getChild("result").getAttributeValue("numFound"));
} catch (Exception e) {
LOGGER.info("found no documents in repository");
}
return numberOfPublications;
}
示例8: getPublicationsForAuthor
import org.jdom2.JDOMException; //導入依賴的package包/類
public Set<Element> getPublicationsForAuthor(PublicationAuthor author)
throws IOException, JDOMException, SAXException {
if (!author.getScopusAuthorID().isEmpty()) {
Set<Element> publications = new HashSet<>();
String queryURL = API_URL + "/author/AUTHOR_ID:" + author.getScopusAuthorID()
+ "?start=0&count=200&view=DOCUMENTS&apikey=" + API_KEY;
XPathExpression<Element> xPath = XPathFactory.instance().compile(pathToDocumentIdentifier,
Filters.element());
List<Element> identifierElements = xPath
.evaluate(getResponse(queryURL).asXML().detachRootElement().clone());
for (Element idElement : identifierElements) {
publications.add(getPublicationByID(idElement.getValue()));
}
return publications;
} else
return null;
}
示例9: getCitationInformation
import org.jdom2.JDOMException; //導入依賴的package包/類
public Element getCitationInformation(String scopusID)
throws IOException, JDOMException, SAXException {
// build API URL
String queryURL = API_URL + "/abstract/citation-count?scopus_id=" + scopusID + "&apikey=" + API_KEY
+ "&httpAccept=application%2Fxml";
XPathExpression<Element> xPathCount = XPathFactory.instance().compile(pathToCitationCount, Filters.element());
XPathExpression<Element> xPathLink = XPathFactory.instance().compile(pathToCitationLink, Filters.element());
XPathExpression<Element> xPathArticleLink = XPathFactory.instance().compile(pathToArticleLink, Filters.element());
Element response = getResponse(queryURL).asXML().detachRootElement().clone();
String citationCount = xPathCount.evaluateFirst(response).getValue();
String citationLink = xPathLink.evaluateFirst(response).getAttributeValue("href");
String articleLink = xPathArticleLink.evaluateFirst(response).getAttributeValue("href");
Element citationInformation = new Element("citationInformation");
citationInformation.addContent(new Element("count").setText(citationCount));
citationInformation.addContent(new Element("citationLink").setText(citationLink));
citationInformation.addContent(new Element("articleLink").setText(articleLink));
return citationInformation;
}
示例10: getAll
import org.jdom2.JDOMException; //導入依賴的package包/類
public List<MCRContent> getAll() throws IOException, JDOMException, SAXException {
// prepare list of results blocks
List<MCRContent> resultsSet = new ArrayList<>();
// build basic part of API URL
String baseQueryURL = API_URL + "/affiliation/AFFILIATION_ID:" + AFFIL_ID + "?apikey=" + API_KEY
+ "&view=DOCUMENTS";
// divide API request in blocks a XXX documents (in final version 200
// documents per block, number of blocks determined by total number of
// documents)
// int numberOfPublications = getNumberOfPublications(baseQueryURL);
// at the moment only testing, two blocks a 10 documents
for (int i = 0; i < 2; i++) {
int start = 10 * i;
int count = 10;
// build API URL
String queryURL = baseQueryURL + "&start=" + start + "&count=" + count + "&view=DOCUMENTS";
// add block to list of blocks
resultsSet.add(getResponse(queryURL));
}
// return API-response
return resultsSet;
}
示例11: setSubmittedValues
import org.jdom2.JDOMException; //導入依賴的package包/類
private void setSubmittedValues(MCRBinding binding, String[] values) throws JDOMException, JaxenException {
List<Object> boundNodes = binding.getBoundNodes();
while (boundNodes.size() < values.length) {
binding.cloneBoundElement(boundNodes.size() - 1);
}
for (int i = 0; i < values.length; i++) {
String value = values[i] == null ? "" : values[i].trim();
value = MCRXMLFunctions.normalizeUnicode(value);
value = MCRXMLHelper.removeIllegalChars(value);
binding.setValue(i, value);
}
removeXPaths2CheckResubmission(binding);
binding.detach();
}
示例12: testSubmitTextfields
import org.jdom2.JDOMException; //導入依賴的package包/類
@Test
public void testSubmitTextfields() throws JaxenException, JDOMException, IOException {
String template = "document[title='Titel'][author[@firstName='John'][@lastName='Doe']]";
MCREditorSession session = new MCREditorSession();
session.setEditedXML(new Document(new MCRNodeBuilder().buildElement(template, null, null)));
Map<String, String[]> submittedValues = new HashMap<>();
submittedValues.put("/document/title", new String[] { "Title" });
submittedValues.put("/document/author/@firstName", new String[] { "Jim" });
submittedValues.put("/document/author/@lastName", new String[] { "" });
session.getSubmission().setSubmittedValues(submittedValues);
session.getSubmission().emptyNotResubmittedNodes();
template = "document[title='Title'][author[@firstName='Jim'][@lastName='']]";
Document expected = new Document(new MCRNodeBuilder().buildElement(template, null, null));
Document result = session.getEditedXML();
result = MCRChangeTracker.removeChangeTracking(result);
assertTrue(MCRXMLHelper.deepEqual(expected, result));
}
示例13: replaceMonomer
import org.jdom2.JDOMException; //導入依賴的package包/類
/**
* method to replace the MonomerID with the new MonomerID for a given
* polymer type
*
* @param helm2notation
* HELM2Notation
* @param polymerType
* String of the polymer type
* @param existingMonomerID
* old MonomerID
* @param newMonomerID
* new MonomerID
* @throws NotationException
* if notation was not valid
* @throws MonomerException
* if monomer is not valid
* @throws ChemistryException
* if chemistry engine could not be initialized
* @throws CTKException
* general ChemToolKit exception passed to HELMToolKit
* @throws IOException IO error
* @throws JDOMException jdome error
*
*/
public final static void replaceMonomer(HELM2Notation helm2notation, String polymerType, String existingMonomerID,
String newMonomerID) throws NotationException, MonomerException,
ChemistryException, CTKException, IOException, JDOMException {
validateMonomerReplacement(polymerType, existingMonomerID, newMonomerID);
/*
* if(newMonomerID.length()> 1){ if( !( newMonomerID.startsWith("[") &&
* newMonomerID.endsWith("]"))){ newMonomerID = "[" + newMonomerID +
* "]"; } }
*/
for (int i = 0; i < helm2notation.getListOfPolymers().size(); i++) {
if (helm2notation.getListOfPolymers().get(i).getPolymerID().getType().equals(polymerType)) {
for (int j = 0; j < helm2notation.getListOfPolymers().get(i).getPolymerElements().getListOfElements()
.size(); j++) {
MonomerNotation monomerNotation = replaceMonomerNotation(
helm2notation.getListOfPolymers().get(i).getPolymerElements().getListOfElements().get(j),
existingMonomerID, newMonomerID);
if (monomerNotation != null) {
helm2notation.getListOfPolymers().get(i).getPolymerElements().getListOfElements().set(j,
monomerNotation);
}
}
}
}
}
示例14: getThumbnail
import org.jdom2.JDOMException; //導入依賴的package包/類
private BufferedImage getThumbnail(MCRFile thumbFile) throws IOException, JDOMException {
ImageReader reader = getImageReader();
BufferedImage level1Image = readThumb(thumbFile, reader);
final double width = level1Image.getWidth();
final double height = level1Image.getHeight();
final int newWidth = width < height ? (int) Math.ceil(thumbnailSize * width / height) : thumbnailSize;
final int newHeight = width < height ? thumbnailSize : (int) Math.ceil(thumbnailSize * height / width);
int imageType = level1Image.getType();
if (imageType == BufferedImage.TYPE_CUSTOM) {
imageType = BufferedImage.TYPE_INT_RGB;
}
final BufferedImage bicubic = new BufferedImage(newWidth, newHeight, imageType);
final Graphics2D bg = bicubic.createGraphics();
bg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
bg.scale(newWidth / width, newHeight / height);
bg.drawImage(level1Image, 0, 0, null);
bg.dispose();
return bicubic;
}
示例15: testSwapParameter
import org.jdom2.JDOMException; //導入依賴的package包/類
@Test
public void testSwapParameter() throws JaxenException, JDOMException {
Element template = new MCRNodeBuilder().buildElement("parent[name='aa'][name='ab'][name='bc'][name='ac']", null,
null);
Document doc = new Document(template);
MCRBinding root = new MCRBinding(doc);
MCRRepeatBinding repeat = new MCRRepeatBinding("parent/name[contains(text(),'a')]", root, 0, 0, "build");
assertEquals(3, repeat.getBoundNodes().size());
repeat.bindRepeatPosition();
repeat.bindRepeatPosition();
assertEquals("/parent|1|build|name[contains(text(), \"a\")]",
MCRSwapTarget.getSwapParameter(repeat, MCRSwapTarget.MOVE_UP));
assertEquals("/parent|2|build|name[contains(text(), \"a\")]",
MCRSwapTarget.getSwapParameter(repeat, MCRSwapTarget.MOVE_DOWN));
}