当前位置: 首页>>代码示例>>Java>>正文


Java JDOMException类代码示例

本文整理汇总了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;
}
 
开发者ID:intranda,项目名称:goobi-viewer-connector,代码行数:27,代码来源:Utils.java

示例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;
}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:31,代码来源:Utils.java

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



}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:22,代码来源:TestJdom.java

示例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);
  }
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:45,代码来源:AuthorBuilder.java

示例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);
  }
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:27,代码来源:AuthorBuilder.java

示例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;
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:20,代码来源:Institution.java

示例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;
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:17,代码来源:MyCoReConnector.java

示例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;
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:18,代码来源:ScopusConnector.java

示例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;
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:19,代码来源:ScopusConnector.java

示例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;
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:26,代码来源:ScopusConnector.java

示例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();
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:18,代码来源:MCREditorSubmission.java

示例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));
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:20,代码来源:MCREditorSubmissionTest.java

示例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);
				}
			}
		}
	}
}
 
开发者ID:PistoiaHELM,项目名称:HELM2NotationToolkit,代码行数:49,代码来源:ChangeObjects.java

示例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;
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:20,代码来源:MCRMediaThumbnailServlet.java

示例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));
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:18,代码来源:MCRSwapInsertTargetTest.java


注:本文中的org.jdom2.JDOMException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。