List of usage examples for org.dom4j DocumentHelper createElement
public static Element createElement(String name)
From source file:org.jogre.server.ServerProperties.java
License:Open Source License
/** * Add ELO element./*from w w w . j a va2 s . c om*/ * * @param gameId */ public void addELOElm(String gameId) { Element gameElm = getGameElm(gameId); if (gameElm != null) { Element eloElm = DocumentHelper.createElement(XML_ELO); eloElm.addAttribute(XML_ATT_START_RATING, "1200"); eloElm.addAttribute(XML_ATT_KFACTOR, "0-3000=24"); // Add the eloElm gameElm.add(eloElm); } }
From source file:org.jogre.server.ServerProperties.java
License:Open Source License
/** * Add a new custom row./*from w w w .j a v a 2s . com*/ * * @param curGame */ public void addNewCustomElm(String gameID) { // Create new custom element with blank type and values Element customElm = DocumentHelper.createElement(XML_CUSTOM); customElm.addAttribute(XML_ATT_TYPE, ""); customElm.addAttribute(XML_ATT_VALUE, ""); // Add as child to this particular game Element gameElm = getGameElm(gameID); if (gameElm != null) gameElm.add(customElm); }
From source file:org.jogre.server.ServerProperties.java
License:Open Source License
/** * Add a new database element./*from ww w.j a va 2 s . c o m*/ * * @param connectionID New user specified database connection ID. */ public void addDatabaseConnElm(String connectionID) { Element newDatabaseConnElement = DocumentHelper.createElement(XML_CONNECTION); newDatabaseConnElement.addAttribute(XML_ATT_ID, connectionID); newDatabaseConnElement.addAttribute(XML_ATT_DRIVER, IDatabase.DEFAULT_DRIVER); newDatabaseConnElement.addAttribute(XML_ATT_URL, IDatabase.DEFAULT_URL); newDatabaseConnElement.addAttribute(XML_ATT_USERNAME, ""); newDatabaseConnElement.addAttribute(XML_ATT_PASSWORD, ""); doc.getRootElement().element(XML_SERVER_DATA).element(XML_DATABASE).add(newDatabaseConnElement); }
From source file:org.jogre.server.ServerProperties.java
License:Open Source License
/** * Add games element./*from www.j a v a2 s . c om*/ * * @param gameID New user specified gameID. */ public void addGamesElm(String gameID) { // Create default games Elm Element newGamesElm = DocumentHelper.createElement(XML_GAME); newGamesElm.addAttribute(XML_ATT_ID, gameID); newGamesElm.addAttribute(XML_ATT_HOST, "yes"); newGamesElm.addAttribute(XML_ATT_MIN_PLAYERS, String.valueOf(DEFAULT_MIN_NUM_OF_PLAYERS)); newGamesElm.addAttribute(XML_ATT_MAX_PLAYERS, String.valueOf(DEFAULT_MAX_NUM_OF_PLAYERS)); doc.getRootElement().element(XML_SUPPORTED_GAMES).add(newGamesElm); }
From source file:org.kuali.student.ap.coursesearch.dataobject.CourseSearchItemImpl.java
License:Educational Community License
public String getScheduledTerms() { //Return only the scheduled terms CollectionListPropertyEditorHtmlListType listType = CollectionListPropertyEditorHtmlListType.DL; Element termsList = DocumentHelper.createElement(listType.getListElementName()); // dl if (scheduledTermsList != null && scheduledTermsList.size() > 0) { Element termsListItem = termsList.addElement(listType.getListItemElementName()); // dd termsListItem.addAttribute("class", "scheduled"); Element scheduledListElement = termsListItem.addElement(listType.getListElementName()); // dl List<TermInfo> scheduledTermsListIds; try {// w w w . j av a 2 s . co m scheduledTermsListIds = KsapFrameworkServiceLocator.getAcademicCalendarService().getTermsByIds( scheduledTermsList, KsapFrameworkServiceLocator.getContext().getContextInfo()); } catch (DoesNotExistException e) { throw new IllegalArgumentException("ATP lookup error", e); } catch (InvalidParameterException e) { throw new IllegalArgumentException("ATP lookup error", e); } catch (MissingParameterException e) { throw new IllegalArgumentException("ATP lookup error", e); } catch (OperationFailedException e) { throw new IllegalStateException("ATP lookup error", e); } catch (PermissionDeniedException e) { throw new IllegalStateException("ATP lookup error", e); } //sort scheduledTermsListIds List<Term> terms = new ArrayList<Term>(scheduledTermsListIds); List<Term> scheduledTermsListSorted = KsapFrameworkServiceLocator.getTermHelper() .sortTermsByStartDate(terms, true); Integer displayLimit = Integer.valueOf( ConfigContext.getCurrentContextConfig().getProperty("ks.ap.search.terms.scheduled.limit")); //list greater than 3, truncate if (scheduledTermsListSorted.size() > displayLimit) scheduledTermsListSorted = scheduledTermsListSorted.subList(0, displayLimit); for (Term scheduledTermId : scheduledTermsListSorted) { Element scheduledListItem = scheduledListElement.addElement(listType.getListItemElementName()); // dd String scheduledTerm; scheduledTerm = scheduledTermId.getName(); String termAbbreviation = scheduledTerm.substring(0, 2).toUpperCase(); scheduledListItem.addAttribute("class", termAbbreviation); String year = scheduledTerm.substring(scheduledTerm.length() - 2); scheduledListItem.setText(String.format("%s %s", termAbbreviation, year)); } } return termsList.asXML(); }
From source file:org.kuali.student.ap.coursesearch.dataobject.CourseSearchItemImpl.java
License:Educational Community License
public String getOfferedTerms() { //Return only the offered terms CollectionListPropertyEditorHtmlListType listType = CollectionListPropertyEditorHtmlListType.DL; Element termsList = DocumentHelper.createElement(listType.getListElementName()); // dl if (termInfoList != null && termInfoList.size() > 0) { Element termsListItem = termsList.addElement(listType.getListItemElementName()); // dd termsListItem.addAttribute("class", "projected"); Element termListElement = termsListItem.addElement(listType.getListElementName()); // dl for (String atpTypeKey : termInfoList) { Element scheduledListItem = termListElement.addElement(listType.getListItemElementName()); // dd String term;/*from w w w . ja v a 2 s . c om*/ try { term = KsapFrameworkServiceLocator.getTypeService() .getType(atpTypeKey, KsapFrameworkServiceLocator.getContext().getContextInfo()) .getName(); } catch (DoesNotExistException e) { throw new IllegalArgumentException("ATP lookup error", e); } catch (InvalidParameterException e) { throw new IllegalArgumentException("ATP lookup error", e); } catch (MissingParameterException e) { throw new IllegalArgumentException("ATP lookup error", e); } catch (OperationFailedException e) { throw new IllegalStateException("ATP lookup error", e); } catch (PermissionDeniedException e) { throw new IllegalStateException("ATP lookup error", e); } scheduledListItem.setText(term.substring(0, 2).toUpperCase()); } } return termsList.asXML(); }
From source file:org.kuali.student.ap.coursesearch.dataobject.CourseSearchItemImpl.java
License:Educational Community License
/** * Form a link to the course details inquiry page related to this search * item.// w ww . j a v a2s . co m * * @return A link to the course details inquiry page related to this search * item. */ protected String getInquiryLink() { Element iqlink = DocumentHelper.createElement("a"); StringBuilder url = new StringBuilder(); url.append("inquiry?methodToCall=start&viewId=CourseDetails-InquiryView&courseId="); try { url.append(URLEncoder.encode(getCourseId(), "UTF-8")); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("UTF-8 is unsupported", e); } Map<String, String> ap = getInquiryParams(); // Only send part of the session id to create session specific link for security String sid = sessionid.substring(0, sessionid.length() / 2); ap.put("sid", sid); if (ap != null) for (Entry<String, String> e : ap.entrySet()) try { url.append('&').append(URLEncoder.encode(e.getKey(), "UTF-8")).append('=') .append(URLEncoder.encode(e.getValue(), "UTF-8")); } catch (UnsupportedEncodingException ex) { throw new IllegalStateException("UTF-8 is unsupported", ex); } iqlink.addAttribute("href", url.toString()); iqlink.addAttribute("target", "_self"); iqlink.addAttribute("title", getCourseName()); iqlink.addAttribute("class", "ksap-text-ellipsis"); iqlink.setText(getCourseName()); return iqlink.asXML(); }
From source file:org.kuali.student.ap.coursesearch.dataobject.CourseSearchItemImpl.java
License:Educational Community License
/** * Get HTML content for the status column in the search results for this * item./*from w ww . j a va2 s. co m*/ * * @return HTML content for the status column in the search results for this * item. */ protected String getStatusColumn() { assert getCourseId() != null; String cid = getCourseId().replace('.', '_'); Element actionDiv = DocumentHelper.createElement("div"); actionDiv.addAttribute("class", "actions"); Element bookmarkSpan = actionDiv.addElement("span"); Element plannedSpan = actionDiv.addElement("span"); Element addBookmarkLink = bookmarkSpan.addElement("a"); Element addToPlanLink = plannedSpan.addElement("a"); //Bookmark action or status "is bookmarked" bookmarkSpan.addAttribute("id", cid + "_bookmark_status"); bookmarkSpan.addAttribute("class", "bookmark"); addBookmarkLink.addAttribute("id", cid + "_bookmark_anchor"); // addBookmarkLink.addAttribute("class", "add-bookmark-link"); addBookmarkLink.addAttribute("data-courseid", courseId); addBookmarkLink.setText(" "); if (isSaved()) { //Currently bookmarked addBookmarkLink.addAttribute("class", "ks-fontello-icon-star"); addBookmarkLink.addAttribute("onclick", "deleteBookmarkCourse('', jQuery(this).data('courseid'), event);"); addBookmarkLink.addAttribute("title", "Remove Bookmark"); } else { //Not bookmarked addBookmarkLink.addAttribute("class", "ks-fontello-icon-star-empty"); addBookmarkLink.addAttribute("onclick", "bookmarkCourse(jQuery(this).data('courseid'), event);"); addBookmarkLink.addAttribute("title", "Bookmark"); } //Add to plan action or status "is planned" plannedSpan.addAttribute("id", cid + "_planned_status"); plannedSpan.addAttribute("class", "plan"); addToPlanLink.addAttribute("id", cid + "_add_to_plan_anchor"); addToPlanLink.addAttribute("class", "add-to-plan-link"); addToPlanLink.addAttribute("data-courseid", courseId); addToPlanLink.addAttribute("data-coursexid", cid); addToPlanLink.setText(" "); if (isPlanned()) { //Currently Added to planner, somewhere addToPlanLink.addAttribute("class", "ks-fontello-icon-ok-circled"); addToPlanLink.addAttribute("title", "Planned"); } else { //Not planned anywhere addToPlanLink.addAttribute("class", "ks-fontello-icon-hollow-circled-plus"); addToPlanLink.addAttribute("onclick", "ksapOpenPlanDialog('course_add_course_page','planner','startAddCourseToPlanDialog', this, event);"); addToPlanLink.addAttribute("title", "Add to Plan"); } return actionDiv.asXML(); }
From source file:org.kuali.student.ap.coursesearch.dataobject.CourseSearchItemImpl.java
License:Educational Community License
/** * Creates a formatted string for the display of the general education requirements in the results table. * * @return formatted general education output *//*from w ww .j av a 2s. c o m*/ private String getGenEduReqForUI() { List<String> genEdReqCodes = this.getGenEduReqs(); if (genEdReqCodes == null || genEdReqCodes.isEmpty()) { return EMPTY_RESULT_VALUE_KEY; } Element genEdContainer = DocumentHelper.createElement("div"); for (String genEd : genEdReqCodes) { /* Doing this to fix a bug in IE8 which is trimming off the I&S as I */ if (genEd.contains("&")) { genEd = genEd.replace("&", "&"); } if (!genEdContainer.elements().isEmpty()) { genEdContainer.addElement("br"); } Element newGenEd = genEdContainer.addElement("abbr"); newGenEd.setText(genEd); String genEdTitle = KsapFrameworkServiceLocator.getCourseSearchStrategy().getGenEdMap().get(genEd); newGenEd.addAttribute("title", genEdTitle); } return genEdContainer.asXML(); }
From source file:org.mitre.ace2004.callisto.ExportAPF5_0_2.java
License:Open Source License
private void addRelation(Element doc, AWBDocument awbDoc, HasSubordinates aceRelation) { String id = toString(aceRelation.getAttributeValue("ace_id")); String type = toString(aceRelation.getAttributeValue("type")); String subtype = toString(aceRelation.getAttributeValue("subtype")); String modality = toString(aceRelation.getAttributeValue("modality")); String tense = toString(aceRelation.getAttributeValue("tense")); // Case by case fixes for legacy errors: if ("Other".equals(subtype)) subtype = null;/*w w w . j a v a 2s.c om*/ if (DEBUG > 0) System.err.println(" relation: " + aceRelation.getId() + ": " + id); Element relation = doc.addElement("relation").addAttribute("ID", id).addAttribute("TYPE", type) .addAttribute("SUBTYPE", subtype).addAttribute("MODALITY", modality).addAttribute("TENSE", tense); // add arg-1 and arg-2 as argument elements AWBAnnotation arg1 = (AWBAnnotation) aceRelation.getAttributeValue("arg1"); addArgument(relation, "relation_argument", "Arg-1", arg1); AWBAnnotation arg2 = (AWBAnnotation) aceRelation.getAttributeValue("arg2"); addArgument(relation, "relation_argument", "Arg-2", arg2); // Promote relation_mention_arguments to the relation_arguments, while // creating the relation_mentions. Add these relation_mentions to the // relation after, so that relation_arguments appear first in XML // collect relation_mentions for later addition Vector mentions = new Vector(); // collect relation_arguments so they are unique LinkedHashMap parentArgs = new LinkedHashMap(); AWBAnnotation[] aceMentions = aceRelation.getSubordinates(ACE2004Utils.RELATION_MENTION_TYPE); // Loop over mentions: create standalone, adding structure, but promoting // it's arguments to the relation before adding the mentions to the // relation for (int i = 0; i < aceMentions.length; i++) { HasSubordinates aceMention = (HasSubordinates) aceMentions[i]; String mentionID = toString(aceMention.getAttributeValue("ace_id")); String condition = toString(aceMention.getAttributeValue("lexicalcondition")); if (DEBUG > 0) System.err.println(" relation-mention: " + aceMention.getId() + ": " + mentionID); // Create standalone mention, and add to relation /after/ arguments Element mention = DocumentHelper.createElement("relation_mention").addAttribute("ID", mentionID) .addAttribute("LEXICALCONDITION", condition); mentions.add(mention); // add arg-1 and arg-2 as argument elements AWBAnnotation mentionArg1 = (AWBAnnotation) aceMention.getAttributeValue("arg1"); addArgument(mention, "relation_mention_argument", "Arg-1", mentionArg1); AWBAnnotation mentionArg2 = (AWBAnnotation) aceMention.getAttributeValue("arg2"); addArgument(mention, "relation_mention_argument", "Arg-2", mentionArg2); // add mention_arguments and promote to relation_arguments ATLASElementSet aceArguments = aceMention.getRegion() .getSubordinateSet(ACE2004Utils.ARGUMENT_MENTION_TYPE); addArgumentList(relation, mention, parentArgs, "relation", aceArguments); } // for (...mention-relation...) // add the collected (unique) relation_arguments Iterator argIter = parentArgs.keySet().iterator(); while (argIter.hasNext()) { String role = (String) argIter.next(); // there can be more than one value for a role, but no duplicate values // for the same role LinkedHashSet roleValues = (LinkedHashSet) parentArgs.get(role); Iterator valueIter = roleValues.iterator(); while (valueIter.hasNext()) { AWBAnnotation value = (AWBAnnotation) valueIter.next(); addArgument(relation, "relation_argument", role, value); } } // finally add the relation_mentions to the relation Iterator mentionIter = mentions.iterator(); while (mentionIter.hasNext()) { relation.add((Element) mentionIter.next()); } }