Java 类org.dom4j.tree.DefaultAttribute 实例源码

项目:jspider    文件:XmlParser.java   
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+"].");
}
项目:bygle-ldp    文件:RelationsService.java   
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();
    }
}
项目:bygle-ldp    文件:RelationsService.java   
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();
    }
}
项目:bygle-ldp    文件:RelationsService.java   
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();
    }
}
项目:jaxen    文件:DOM4JXPathTest.java   
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() );
}
项目:olat    文件:CPManifest.java   
/**
 * @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);

}
项目:olat    文件:CPManifest.java   
/**
 * @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);

}
项目:Openfire    文件:IQRosterPayloadProcessor.java   
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);
    }
项目:openfire    文件:IQRosterPayloadProcessor.java   
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);
    }
项目:openfire-bespoke    文件:SendRosterProcessor.java   
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);
}
项目:bygle-ldp    文件:RelationsService.java   
public void addRelations(Records records){
    try {
        XMLReader xmlReader = new XMLReader(records.getRdf());
        List<?> nodeList = xmlReader.getNodeList("/rdf:RDF/*/*/@rdf:resource[not(ancestor::rdf:type)]");
        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();
    }
}
项目:jeveassets    文件:Update.java   
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);
    }
}
项目:taskerbox    文件:TaskerboxFactory.java   
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;
}
项目:jaxen    文件:DOM4JXPathTest.java   
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() );

}
项目:libraries    文件:ObjectToDomConverterUtilities.java   
public static Attribute createAttribute(final String attributeName, final String value) {
  return new DefaultAttribute(attributeName, value);
}
项目:taskerbox    文件:TaskerboxFactory.java   
@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;
}