本文整理汇总了Java中org.dom4j.tree.DefaultAttribute类的典型用法代码示例。如果您正苦于以下问题:Java DefaultAttribute类的具体用法?Java DefaultAttribute怎么用?Java DefaultAttribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultAttribute类属于org.dom4j.tree包,在下文中一共展示了DefaultAttribute类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getXmlValueText
import org.dom4j.tree.DefaultAttribute; //导入依赖的package包/类
private Object getXmlValueText(List nodes) {
if (nodes == null || nodes.isEmpty()) {
return null;
}
Object node = nodes.get(0);
if (node instanceof DefaultText) {
return StringUtils.trim(((DefaultText) node).getText());
}
if (node instanceof DefaultAttribute) {
return StringUtils.trim(((DefaultAttribute) node).getText());
}
if (node instanceof DefaultElement) {
return StringUtils.trim(((DefaultElement) node).getText());
}
throw new IllegalArgumentException("unsupported node type ["+node+"].");
}
示例2: addRelations
import org.dom4j.tree.DefaultAttribute; //导入依赖的package包/类
public void addRelations(List<RelationsContainer> relationsContainerList){
try {
for (int i = 0; i < relationsContainerList.size(); i++) {
RelationsContainer relationsContainer = relationsContainerList.get(i);
List<?> nodeList = relationsContainer.getNodeList();
Records records = (Records)bygleService.getObject(Records.class,relationsContainer.getIdRecord());
for (Iterator<?> iterator = nodeList.iterator(); iterator.hasNext();) {
DefaultAttribute defaultAttribute = (DefaultAttribute)iterator.next();
Records relatedRecord = getRecords(defaultAttribute.getStringValue());
if(relatedRecord!=null){
addRelation(records, relatedRecord, defaultAttribute);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: addRelation
import org.dom4j.tree.DefaultAttribute; //导入依赖的package包/类
private void addRelation(Records records,Records relatedRecord,DefaultAttribute defaultAttribute){
try {
RelationTypes relationTypes = getRelationTypes(defaultAttribute.getParent().getNamespace().getPrefix()+":"+defaultAttribute.getParent().getName());
DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Relations.class);
detachedCriteria.add(Restrictions.eq("relationTypes",relationTypes));
detachedCriteria.add(Restrictions.disjunction().add(Restrictions.eq("recordsByRefIdRecord1", records)).add(Restrictions.eq("recordsByRefIdRecord2", relatedRecord)));
detachedCriteria.add(Restrictions.disjunction().add(Restrictions.eq("recordsByRefIdRecord1",relatedRecord)).add(Restrictions.eq("recordsByRefIdRecord2", records)));
List<?> relationList = bygleService.getList(detachedCriteria);
if(relationList.size()==0){
RelationsId relationsId = new RelationsId(records.getIdRecord(), relatedRecord.getIdRecord(), relationTypes.getIdRelationType());
Relations relations = new Relations(relationsId, records, relatedRecord, relationTypes);
bygleService.add(relations);
}
}catch (HibernateException e) {
e.printStackTrace();
}
}
示例4: removeRelation
import org.dom4j.tree.DefaultAttribute; //导入依赖的package包/类
private void removeRelation(Records records,Records relatedRecord,DefaultAttribute defaultAttribute){
try {
RelationTypes relationTypes = getRelationTypes(defaultAttribute.getParent().getNamespace().getPrefix()+":"+defaultAttribute.getParent().getName());
DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Relations.class);
detachedCriteria.add(Restrictions.eq("relationTypes",relationTypes));
detachedCriteria.add(Restrictions.disjunction().add(Restrictions.eq("recordsByRefIdRecord1",records)).add(Restrictions.eq("recordsByRefIdRecord2", relatedRecord)));
detachedCriteria.add(Restrictions.disjunction().add(Restrictions.eq("recordsByRefIdRecord1",relatedRecord)).add(Restrictions.eq("recordsByRefIdRecord2", records)));
List<?> relationList = bygleService.getList(detachedCriteria);
if(relationList.size()!=0){
Relations relations = (Relations)relationList.get(0);
bygleService.remove(relations);
}
}catch (HibernateException e) {
e.printStackTrace();
}
}
示例5: testNamespaceNodesAreInherited
import org.dom4j.tree.DefaultAttribute; //导入依赖的package包/类
public void testNamespaceNodesAreInherited() throws JaxenException
{
Namespace ns0 = Namespace.get("p0", "www.acme0.org");
Namespace ns1 = Namespace.get("p1", "www.acme1.org");
Namespace ns2 = Namespace.get("p2", "www.acme2.org");
Element element = new DefaultElement("test", ns1);
Attribute attribute = new DefaultAttribute("pre:foo", "bar", ns2);
element.add(attribute);
Element root = new DefaultElement("root", ns0);
root.add(element);
Document doc = new DefaultDocument(root);
XPath xpath = new Dom4jXPath( "/*/*/namespace::node()" );
List results = xpath.selectNodes( doc );
assertEquals( 4,
results.size() );
}
示例6: buildDocument
import org.dom4j.tree.DefaultAttribute; //导入依赖的package包/类
/**
* @param doc
*/
public void buildDocument(final DefaultDocument doc) {
// Manifest is the root-node of the document, therefore we need to pass the
// "doc"
final DefaultElement manifestElement = new DefaultElement(CPCore.MANIFEST);
manifestElement.add(new DefaultAttribute(CPCore.IDENTIFIER, this.identifier));
manifestElement.add(new DefaultAttribute(CPCore.SCHEMALOCATION, this.schemaLocation));
// manifestElement.setNamespace(this.getNamespace()); //FIXME: namespace
doc.add(manifestElement);
if (metadata != null) {
metadata.buildDocument(manifestElement);
}
organizations.buildDocument(manifestElement);
resources.buildDocument(manifestElement);
}
示例7: sendRosterToComponent
import org.dom4j.tree.DefaultAttribute; //导入依赖的package包/类
private void sendRosterToComponent(IQ requestPacket, Collection<RosterItem> items, String subdomain) {
IQ response = IQ.createResultIQ(requestPacket);
response.setTo(subdomain);
Element query = new DefaultElement( QName.get("query","jabber:iq:roster"));
for (RosterItem i : items) {
String jid = i.getJid().toString();
if (!jid.equals(subdomain) && jid.contains(subdomain)) {
Log.debug("Roster exchange for external component " + subdomain + ". Sending user " + i.getJid().toString());
Element item = new DefaultElement("item", null);
item.add(new DefaultAttribute("jid", i.getJid().toString()));
item.add(new DefaultAttribute("name", i.getNickname()));
item.add(new DefaultAttribute("subscription", "both"));
for (String s : i.getGroups()) {
Element group = new DefaultElement("group");
group.setText(s);
item.add(group);
}
query.add(item);
}
}
response.setChildElement(query);
dispatchPacket(response);
}
示例8: sendRosterToComponent
import org.dom4j.tree.DefaultAttribute; //导入依赖的package包/类
private void sendRosterToComponent(IQ requestPacket, Collection<RosterItem> items, String subdomain) {
IQ response = IQ.createResultIQ(requestPacket);
response.setTo(subdomain);
Element query = new DefaultElement("query");
for (RosterItem i : items) {
String jid = i.getJid().toString();
if (!jid.equals(subdomain) && jid.contains(subdomain)) {
Log.debug("Roster exchange for external component " + subdomain + ". Sending user " + i.getJid().toString());
Element item = new DefaultElement("item", null);
item.add(new DefaultAttribute("jid", i.getJid().toString()));
item.add(new DefaultAttribute("name", i.getNickname()));
item.add(new DefaultAttribute("subscription", "both"));
for (String s : i.getGroups()) {
Element group = new DefaultElement("group");
group.setText(s);
item.add(group);
}
query.add(item);
}
}
query.addNamespace("", "jabber:iq:roster");
response.setChildElement(query);
dispatchPacket(response);
}
示例9: sendRosterToComponent
import org.dom4j.tree.DefaultAttribute; //导入依赖的package包/类
private void sendRosterToComponent(IQ requestPacket, Collection<RosterItem> items) {
Log.debug("Sending contacts from user " + requestPacket.getFrom().toString() + " to external Component");
IQ response = IQ.createResultIQ(requestPacket);
response.setTo(_componentName);
Element query = new DefaultElement("query");
for (RosterItem i : items) {
if (i.getJid().toString().contains(_componentName)) {
Log.debug("Roster exchange for external component " + _componentName + ". Sending user "
+ i.getJid().toString());
Element item = new DefaultElement("item", null);
item.add(new DefaultAttribute("jid", i.getJid().toString()));
item.add(new DefaultAttribute("name", i.getNickname()));
item.add(new DefaultAttribute("subscription", "both"));
for (String s : i.getGroups()) {
Element group = new DefaultElement("group");
group.setText(s);
item.add(group);
}
query.add(item);
}
}
query.addNamespace("", "jabber:iq:roster");
response.setChildElement(query);
dispatchPacket(response);
}
示例10: setVersion
import org.dom4j.tree.DefaultAttribute; //导入依赖的package包/类
void setVersion(final File xml, final int newVersion) throws DocumentException {
SAXReader xmlReader = new SAXReader();
Document doc = xmlReader.read(xml);
XPath xpathSelector = DocumentHelper.createXPath("/settings");
List<?> results = xpathSelector.selectNodes(doc);
for (Iterator<?> iter = results.iterator(); iter.hasNext();) {
Element element = (Element) iter.next();
Attribute attr = element.attribute("version");
if (attr == null) {
element.add(new DefaultAttribute("version", String.valueOf(newVersion)));
} else {
attr.setText(String.valueOf(newVersion));
}
}
try {
FileOutputStream fos = new FileOutputStream(xml);
OutputFormat outformat = OutputFormat.createPrettyPrint();
outformat.setEncoding("UTF-16");
XMLWriter writer = new XMLWriter(fos, outformat);
writer.write(doc);
writer.flush();
} catch (IOException ioe) {
LOG.error("Failed to update the serttings.xml version number", ioe);
throw new RuntimeException(ioe);
}
}
示例11: createElementInstance
import org.dom4j.tree.DefaultAttribute; //导入依赖的package包/类
public static <I> I createElementInstance(Class<? extends I> clazz, Element el)
throws InstantiationException, IllegalAccessException {
I instance = clazz.newInstance();
for (Object attrObj : el.attributes()) {
DefaultAttribute attrib = (DefaultAttribute) attrObj;
setObjectFieldValue(instance, attrib.getName(), attrib.getValue());
}
return instance;
}
示例12: testJaxen20AttributeNamespaceNodes
import org.dom4j.tree.DefaultAttribute; //导入依赖的package包/类
public void testJaxen20AttributeNamespaceNodes() throws JaxenException
{
Namespace ns1 = Namespace.get("p1", "www.acme1.org");
Namespace ns2 = Namespace.get("p2", "www.acme2.org");
Element element = new DefaultElement("test", ns1);
Attribute attribute = new DefaultAttribute("pre:foo", "bar", ns2);
element.add(attribute);
Document doc = new DefaultDocument(element);
XPath xpath = new Dom4jXPath( "//namespace::node()" );
List results = xpath.selectNodes( doc );
assertEquals( 3, results.size() );
}
示例13: createAttribute
import org.dom4j.tree.DefaultAttribute; //导入依赖的package包/类
public static Attribute createAttribute(final String attributeName, final String value) {
return new DefaultAttribute(attributeName, value);
}
示例14: buildChannel
import org.dom4j.tree.DefaultAttribute; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
public static TaskerboxChannel<?> buildChannel(Element xmlChannel) throws Exception {
log.info("Building channel with Class " + xmlChannel.getName());
Class<TaskerboxChannel> channelClass =
(Class<TaskerboxChannel>) Class.forName(xmlChannel.getName());
final TaskerboxChannel channel = channelClass.newInstance();
for (Object attrObj : xmlChannel.attributes()) {
DefaultAttribute attrib = (DefaultAttribute) attrObj;
setObjectFieldValue(channel, attrib.getName(), attrib.getValue());
log.debug("Adding Property in bag: " + attrib.getName() + " = " + attrib.getValue());
channel.addProperty(attrib.getName(), attrib.getValue());
}
List<ITaskerboxAction> actions = new ArrayList<>();
for (Element channelChildren : (List<Element>) xmlChannel.elements()) {
Class<? extends ITaskerboxAction> actionClass =
(Class<? extends ITaskerboxAction>) Class.forName(channelChildren.getName());
ITaskerboxAction action =
TaskerboxFactory.createElementInstance(actionClass, channelChildren);
try {
log.info("Validando Action " + action.getClass());
TaskerboxValidationUtils.validate(action);
} catch (IllegalArgumentException e) {
e.printStackTrace();
log.error("Erro ao validar action", e);
continue;
}
action.setChannel(channel);
if (action.getId() == null) {
action.setId(channel.getId() + "Action");
}
action.setup();
actions.add(action);
}
if (actions == null || actions.isEmpty()) {
throw new IllegalArgumentException("Not defined actions for channel " + channel.getId());
}
channel.setActions(actions);
TaskerboxValidationUtils.validate(channel);
return channel;
}