List of usage examples for org.jdom2 Element addContent
@Override public Element addContent(final Collection<? extends Content> newContent)
From source file:com.khodev.oradiff.io.XmlSchemaWriter.java
License:Open Source License
private static <T extends DBObject> Element convertToXml(String containerTagName, String tagName, Collection<T> dbObjects) { Element elementList = new Element(containerTagName); for (DBObject object : dbObjects) { elementList.addContent(getXml(tagName, object)); }/*from w w w . j a va 2 s . c o m*/ return elementList; }
From source file:com.khodev.oradiff.io.XmlSchemaWriter.java
License:Open Source License
private static Element getXml(String tagName, DBObject object) { Element element = new Element(tagName); element.setAttribute("name", object.getName()); if (object instanceof Constraint) { Constraint constraint = (Constraint) object; element.setAttribute("constraintType", constraint.getConstraintType()); element.setAttribute("deferrable", constraint.getDeferrable()); element.setAttribute("deferred", constraint.getDeferred()); element.setAttribute("deleteRule", constraint.getDeleteRule()); element.setAttribute("generated", constraint.getGenerated()); element.setAttribute("refConstraintName", constraint.getRefConstraintName()); element.setAttribute("refUserName", constraint.getRefUserName()); element.setAttribute("searchCondition", constraint.getSearchCondition()); element.setAttribute("status", constraint.getStatus()); element.setAttribute("validated", constraint.getValidated()); Element xmlColumns = new Element("columns"); for (IndexColumn column : constraint.getColumns()) xmlColumns.addContent(getXml("column", column)); element.addContent(xmlColumns);// w ww . j a va 2 s .c om } if (object instanceof TablespaceObject) { element.setAttribute("tablespace", ((TablespaceObject) object).getTablespace()); } if (object instanceof Source) { Source source = (Source) object; Element xmlBody = new Element("body"); String bodyStr = ""; for (String line : source.getBody()) bodyStr += line; xmlBody.setText(bodyStr); element.addContent(xmlBody); } if (object instanceof DBPackage) { DBPackage pkg = (DBPackage) object; Element xmlDeclaration = new Element("declaration"); String bodyStr = ""; for (String line : pkg.getDeclaration()) bodyStr += line; xmlDeclaration.setText(bodyStr); element.addContent(xmlDeclaration); } if (object instanceof Sequence) { Sequence sequence = (Sequence) object; element.setAttribute("cacheSize", Integer.toString(sequence.getCacheSize())); element.setAttribute("cycleFlag", Boolean.toString(sequence.isCycleFlag())); element.setAttribute("incrementBy", sequence.getIncrementBy()); element.setAttribute("lastNumber", sequence.getLastNumber()); element.setAttribute("maxValue", sequence.getMaxValue()); element.setAttribute("minValue", sequence.getMinValue()); element.setAttribute("orderFlag", Boolean.toString(sequence.isOrderFlag())); } if (object instanceof Table) { Table table = (Table) object; element.setAttribute("comments", table.getComments()); element.addContent(XmlSchemaWriter.convertToXml("columns", "column", table.getColumns())); element.addContent(XmlSchemaWriter.convertToXml("indexes", "index", table.getIndexes())); element.addContent(XmlSchemaWriter.convertToXml("constraints", "constraint", table.getConstraints())); element.addContent(XmlSchemaWriter.convertToXml("grants", "grant", table.getGrants())); element.addContent( XmlSchemaWriter.convertToXml("publicSynonyms", "publicSynonym", table.getPublicSynonyms())); return element; } if (object instanceof Trigger) { Trigger trigger = (Trigger) object; element.setAttribute("description", trigger.getDescription()); element.setAttribute("event", trigger.getEvent()); element.setAttribute("status", trigger.getStatus()); element.setAttribute("table", trigger.getTable()); element.setAttribute("type", trigger.getType()); element.addContent(new Element("when").setText(trigger.getWhen())); element.addContent(new Element("body").setText(trigger.getBody())); } if (object instanceof View) { View view = (View) object; Element xmlColumns = new Element("columns"); for (String column : view.getColumns()) xmlColumns.addContent(new Element("column").setAttribute("name", column)); element.addContent(xmlColumns); element.addContent(new Element("source").setText(view.getSource())); } if (object instanceof Column) { Column column = (Column) object; element.setAttribute("id", Integer.toString(column.getId())); element.setAttribute("type", column.getType()); element.setAttribute("length", Integer.toString(column.getLength())); element.setAttribute("precision", Integer.toString(column.getPrecision())); element.setAttribute("scale", Integer.toString(column.getScale())); element.setAttribute("nullable", Boolean.toString(column.isNullable())); element.setAttribute("comments", column.getComment()); element.setAttribute("defaultValue", column.getDefaultValue()); } if (object instanceof Index) { Index index = (Index) object; element.setAttribute("type", index.getType()); element.setAttribute("isUnique", Boolean.toString(index.isUnique())); element.setAttribute("compression", index.getCompression()); Element xmlColumns = new Element("columns"); for (IndexColumn column : index.getColumns()) xmlColumns.addContent(getXml("column", column)); element.addContent(xmlColumns); } if (object instanceof Grant) { Grant grant = (Grant) object; element.setAttribute("selectPriv", Boolean.toString(grant.isSelectPriv())); element.setAttribute("insertPriv", Boolean.toString(grant.isInsertPriv())); element.setAttribute("deletePriv", Boolean.toString(grant.isDeletePriv())); element.setAttribute("updatePriv", Boolean.toString(grant.isUpdatePriv())); element.setAttribute("referencesPriv", Boolean.toString(grant.isReferencesPriv())); element.setAttribute("alterPriv", Boolean.toString(grant.isAlterPriv())); element.setAttribute("indexPriv", Boolean.toString(grant.isIndexPriv())); } if (object instanceof IndexColumn) { IndexColumn indexColumn = (IndexColumn) object; element.setAttribute("position", Integer.toString(indexColumn.getPosition())); } return element; }
From source file:com.khodev.oradiff.io.XmlSchemaWriter.java
License:Open Source License
private Element getXml(Schema schema) throws IOException { Element database = new Element("database"); database.addContent(convertToXml("tables", "table", schema.getDbTables())); database.addContent(convertToXml("packages", "package", schema.getDbPackages())); database.addContent(convertToXml("functions", "function", schema.getDbFunctions())); database.addContent(convertToXml("procedures", "procedure", schema.getDbProcedures())); database.addContent(convertToXml("views", "view", schema.getDbViews())); database.addContent(convertToXml("sequences", "sequence", schema.getDbSequences())); database.addContent(convertToXml("triggers", "trigger", schema.getDbTriggers())); return database; }
From source file:com.khodev.sc2.quiz.Quiz.java
License:Open Source License
private void writeUserData(OutputStream s) throws IOException { Element root = new Element("Catalog"); Document d = new Document(root); Element user = new Element("CUser").setAttribute("id", "QuizDictionary"); root.addContent(user); user.addContent(new Element("Fields").setAttribute("EditorColumn", "1").setAttribute("Id", "Level") .setAttribute("Type", "Int")); user.addContent(new Element("Fields").setAttribute("EditorColumn", "2").setAttribute("Id", "Question") .setAttribute("Type", "Text")); user.addContent(new Element("Fields").setAttribute("EditorColumn", "3").setAttribute("Id", "Answer") .setAttribute("Type", "Text")); user.addContent(new Element("Instances").setAttribute("Id", "[Default]")); int i = 0;//from w ww . j a v a2s .c o m for (Question question : questions) { i++; Element instance = new Element("Instances").setAttribute("Id", "" + i); user.addContent(instance); Element q = new Element("Text").setAttribute("Text", "UserData/QuizDictionary/" + i + "_Question"); instance.addContent(q); q.addContent(new Element("Field").setAttribute("Id", "Question")); Element r = new Element("Text").setAttribute("Text", "UserData/QuizDictionary/" + i + "_Answer"); instance.addContent(r); r.addContent(new Element("Field").setAttribute("Id", "Answer")); } XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(d, s); }
From source file:com.kixeye.kixmpp.client.module.chat.MessageKixmppClientModule.java
License:Apache License
/** * Sends a private message./* w w w.j a v a 2s . c o m*/ * * @param toJid * @param body */ public void sendMessage(KixmppJid toJid, String body) { Element messageElement = new Element("message"); messageElement.setAttribute("type", "chat"); messageElement.setAttribute("from", client.getJid().getFullJid()); messageElement.setAttribute("to", toJid.getBaseJid()); Element bodyElement = new Element("body"); bodyElement.setText(body); messageElement.addContent(bodyElement); client.sendStanza(messageElement); }
From source file:com.kixeye.kixmpp.client.module.muc.MucKixmppClientModule.java
License:Apache License
/** * Joins a room.//from w w w . j a v a2 s. c om * * @param roomJid * @param nickname */ public void joinRoom(KixmppJid roomJid, String nickname, Integer maxStanzas, Integer maxChars, Integer seconds, DateTime since) { Element presence = new Element("presence"); presence.setAttribute("from", client.getJid().getFullJid()); presence.setAttribute("to", roomJid + "/" + nickname); Element x = new Element("x", "http://jabber.org/protocol/muc"); presence.addContent(x); Element history = new Element("history", "http://jabber.org/protocol/muc"); if (maxStanzas != null) { history.setAttribute("maxstanzas", maxStanzas.toString()); } if (maxChars != null) { history.setAttribute("maxchars", maxChars.toString()); } if (seconds != null) { history.setAttribute("seconds", seconds.toString()); } if (since != null) { history.setAttribute("since", XmppDateUtils.format(since)); } x.addContent(history); client.sendStanza(presence); }
From source file:com.kixeye.kixmpp.client.module.muc.MucKixmppClientModule.java
License:Apache License
/** * Sends a room message to a room./* w w w . j a va 2 s . co m*/ * * @param roomJid * @param roomMessage */ public void sendRoomMessage(KixmppJid roomJid, String roomMessage, String nickname) { Element message = new Element("message"); message.setAttribute("from", client.getJid().toString()); message.setAttribute("to", roomJid.toString()); message.setAttribute("type", "groupchat"); Element bodyElement = new Element("body", message.getNamespace()); bodyElement.setText(roomMessage); message.addContent(bodyElement); client.sendStanza(message); }
From source file:com.kixeye.kixmpp.client.module.presence.PresenceKixmppClientModule.java
License:Apache License
/** * Updates the current user's presence./*from w w w . j a va 2 s . c om*/ * * @param presence */ public void updatePresence(Presence presence) { Element presenceElement = new Element("presence"); if (presence.getType() != null) { presenceElement.setAttribute("type", presence.getType()); } if (presence.getStatus() != null) { Element statusElement = new Element("status"); statusElement.setText(presence.getStatus()); presenceElement.addContent(statusElement); } if (presence.getShow() != null) { Element showElement = new Element("show"); showElement.setText(presence.getShow()); presenceElement.addContent(showElement); } client.sendStanza(presenceElement); }
From source file:com.kixeye.kixmpp.server.cluster.message.PrivateChatTask.java
License:Apache License
/** * @see org.fusesource.hawtdispatch.Task#run() *//* w ww .ja va 2s .com*/ public void run() { KixmppJid fromJid = KixmppJid.fromRawJid(this.fromJid); KixmppJid toJid = KixmppJid.fromRawJid(this.toJid); KixmppServer server = getKixmppServer(); // broadcast message stanza to all channels of the recipient for (Channel toChannel : server.getChannels(toJid.getNode())) { Element messageElement = new Element("message"); messageElement.setAttribute("type", "chat"); messageElement.setAttribute("from", fromJid.getFullJid()); messageElement.setAttribute("to", toJid.getFullJid()); Element bodyElement = new Element("body"); bodyElement.setText(body); messageElement.addContent(bodyElement); toChannel.writeAndFlush(messageElement); } // broadcast message stanza to all channels of the sender // except for the channel it was sent from for (Channel fromChannel : server.getChannels(fromJid.getNode())) { // skip the channel message was sent from if (fromChannel.attr(BindKixmppServerModule.JID).get().toString() .equalsIgnoreCase(fromJid.toString())) { continue; } Element messageElement = new Element("message"); messageElement.setAttribute("type", "chat"); messageElement.setAttribute("from", fromJid.getFullJid()); messageElement.setAttribute("to", toJid.getFullJid()); Element bodyElement = new Element("body"); bodyElement.setText(body); messageElement.addContent(bodyElement); fromChannel.writeAndFlush(messageElement); } }
From source file:com.kixeye.kixmpp.server.module.auth.SaslKixmppServerModule.java
License:Apache License
/** * @see com.kixeye.kixmpp.server.module.KixmppServerModule#getFeatures(io.netty.channel.Channel) *///w w w . j a v a 2 s . c o m public List<Element> getFeatures(Channel channel) { List<Element> features = new LinkedList<>(); Boolean isAuthed = channel.attr(IS_AUTHENTICATED).get(); if (isAuthed == null || isAuthed == false) { Element mechanisms = new Element("mechanisms", null, "urn:ietf:params:xml:ns:xmpp-sasl"); Element plainMechanism = new Element("mechanism", "urn:ietf:params:xml:ns:xmpp-sasl"); plainMechanism.setText("PLAIN"); mechanisms.addContent(plainMechanism); features.add(mechanisms); } return features; }