org.dom4j.Node Java Examples

The following examples show how to use org.dom4j.Node. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RadioButtonsTagTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void withoutItemsEnumBindTargetWithExplicitLabelsAndValues() throws Exception {
	BeanWithEnum testBean = new BeanWithEnum();
	testBean.setTestEnum(TestEnum.VALUE_2);
	getPageContext().getRequest().setAttribute("testBean", testBean);

	this.tag.setPath("testEnum");
	this.tag.setItemLabel("enumLabel");
	this.tag.setItemValue("enumValue");
	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = "<div>" + getOutput() + "</div>";
	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element rootElement = document.getRootElement();

	assertEquals(2, rootElement.elements().size());
	Node value1 = rootElement.selectSingleNode("//input[@value = 'Value: VALUE_1']");
	Node value2 = rootElement.selectSingleNode("//input[@value = 'Value: VALUE_2']");
	assertEquals("Label: VALUE_1", rootElement.selectSingleNode("//label[@for = '" + value1.valueOf("@id") + "']").getText());
	assertEquals("Label: VALUE_2", rootElement.selectSingleNode("//label[@for = '" + value2.valueOf("@id") + "']").getText());
	assertEquals(value2, rootElement.selectSingleNode("//input[@checked]"));
}
 
Example #2
Source File: TestSummaryCreatorTask.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the value of the specified attribute of the node determined by the given xpath.
 * 
 * @param doc      The XML document
 * @param xpath    The xpath selecting the node whose attribute we want
 * @param attrName The name of the attribute
 * @return The attribute value
 */
private String getAttrValue(Document doc, String xpath, String attrName)
{
	Node node = doc.selectSingleNode(xpath);

	if (node instanceof Attribute)
	{
		// we ignore the attribute name then
		return ((Attribute)node).getValue();
	}
	else if (node != null)
	{
		return node.valueOf("@" + attrName);
	}
    else
    {
        return null;
    }
}
 
Example #3
Source File: LikeHandler.java    From zealot with Apache License 2.0 6 votes vote down vote up
/**
 * 构建等值查询的动态条件sql.
 * @param source 构建所需的资源对象
 * @return 返回SqlInfo对象
 */
@Override
public SqlInfo buildSqlInfo(BuildSource source) {
    /* 获取拼接的参数 */
    SqlInfo sqlInfo = source.getSqlInfo();
    Node node = source.getNode();

    /* 判断必填的参数是否为空 */
    String fieldText = XmlNodeHelper.getAndCheckNodeText(node, ZealotConst.ATTR_FIELD);
    String valueText = XmlNodeHelper.getNodeAttrText(node, ZealotConst.ATTR_VALUE);
    String patternText = XmlNodeHelper.getNodeAttrText(node, ZealotConst.ATTR_PATTERN);

    /* 如果匹配中'match'属性没有值,则认为是必然生成项 */
    String matchText = XmlNodeHelper.getNodeAttrText(node, ZealotConst.ATTR_MATCH);
    if (StringHelper.isBlank(matchText)) {
        sqlInfo = XmlSqlInfoBuilder.newInstace(source).buildLikeSql(fieldText, valueText, patternText);
    } else {
        /* 如果match匹配成功,则生成数据库sql条件和参数 */
        Boolean isTrue = (Boolean) ParseHelper.parseExpressWithException(matchText, source.getParamObj());
        if (isTrue) {
            sqlInfo = XmlSqlInfoBuilder.newInstace(source).buildLikeSql(fieldText, valueText, patternText);
        }
    }

    return sqlInfo;
}
 
Example #4
Source File: InHandler.java    From zealot with Apache License 2.0 6 votes vote down vote up
/**
 * 构建in查询的动态条件sql.
 * @param source 构建所需的资源对象
 * @return 返回SqlInfo对象
 */
@Override
public SqlInfo buildSqlInfo(BuildSource source) {
    /* 获取拼接的参数 */
    SqlInfo sqlInfo = source.getSqlInfo();
    Node node = source.getNode();

    /* 判断必填的参数是否为空 */
    String fieldText = XmlNodeHelper.getAndCheckNodeText(node, ZealotConst.ATTR_FIELD);
    String valueText = XmlNodeHelper.getAndCheckNodeText(node, ZealotConst.ATTR_VALUE);

    /* 如果匹配中字符没有,则认为是必然生成项 */
    Node matchNode = node.selectSingleNode(ZealotConst.ATTR_MATCH);
    String matchText = XmlNodeHelper.getNodeText(matchNode);
    if (StringHelper.isBlank(matchText)) {
        sqlInfo = XmlSqlInfoBuilder.newInstace(source).buildInSql(fieldText, valueText);
    } else {
        /* 如果match匹配成功,则生成数据库sql条件和参数 */
        Boolean isTrue = (Boolean) ParseHelper.parseExpressWithException(matchText, source.getParamObj());
        if (isTrue) {
            sqlInfo = XmlSqlInfoBuilder.newInstace(source).buildInSql(fieldText, valueText);
        }
    }

    return sqlInfo;
}
 
Example #5
Source File: PictureDom4jDbTemplate.java    From egdownloader with GNU General Public License v2.0 6 votes vote down vote up
public List<Picture> query(String name, String value) {
	@SuppressWarnings("unchecked")
	List<Node> nodes = dom.selectNodes("/pictures/picture[@" + name + "='" + value + "']");
	List<Picture> pics = null;
	if(nodes != null && nodes.size() > 0){
		pics = new ArrayList<Picture>();
		for (Node node : nodes) {
			pics.add(node2Picture(node));
		}
		//排序
		Collections.sort(pics, new Comparator<Picture>() {
			public int compare(Picture o1, Picture o2) {
				return o1.getNum().compareTo(o2.getNum());
			}
		});
	}
	return pics;
}
 
Example #6
Source File: TestSummaryCreatorTask.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the value of the specified attribute of the node determined by the given xpath.
 * 
 * @param doc      The XML document
 * @param xpath    The xpath selecting the node whose attribute we want
 * @param attrName The name of the attribute
 * @return The attribute value
 */
private String getAttrValue(Document doc, String xpath, String attrName)
{
	Node node = doc.selectSingleNode(xpath);

	if (node instanceof Attribute)
	{
		// we ignore the attribute name then
		return ((Attribute)node).getValue();
	}
	else if (node != null)
	{
		return node.valueOf("@" + attrName);
	}
    else
    {
        return null;
    }
}
 
Example #7
Source File: XmlNodeHelper.java    From zealot with Apache License 2.0 6 votes vote down vote up
/**
 * 根据xml文件的路径判断该xml文件是否是zealot xml文件(简单判断是否有'zealots'根节点即可),如果是则返回nameSpace.
 * @param xmlPath xml路径
 * @return 该xml文件的zealot命名空间nameSpace
 */
public static String getZealotXmlNameSpace(String xmlPath) {
    Document doc;
    try {
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(xmlPath);
        doc = new SAXReader().read(is);
    } catch (Exception expected) {
        // 由于只是判断该文件是否能被正确解析,并不进行正式的解析,所有这里就不抛出和记录异常了.
        log.warn("解析路径为:'" + xmlPath + "'的xml文件出错,请检查其正确性");
        return null;
    }

    // 获取XML文件的根节点,判断其根节点是否为'zealots',如果是则获取其属性nameSpace的值.
    Node root = doc.getRootElement();
    if (root != null && ROOT_NAME.equals(root.getName())) {
        String nameSpace = getNodeText(root.selectSingleNode(ZealotConst.ATTR_NAMESPACE));
        if (StringHelper.isBlank(nameSpace)) {
            log.warn("zealot xml文件:'" + xmlPath + "'的根节点nameSpace命名空间属性为配置,请配置,否则将被忽略!");
            return null;
        }
        return nameSpace;
    }

    return null;
}
 
Example #8
Source File: UnittypeXML.java    From freeacs with MIT License 6 votes vote down vote up
public void load(Node node, Enums enums) throws Exception {
  name = getAttr(node, "name");
  Node attributes = node.selectSingleNode("attributes");
  protocol = getAttr(attributes, "protocol");
  deviceflags = getAttr(attributes, "deviceflags");
  addflags = getAttr(attributes, "addflags");
  type = getAttr(attributes, "type");
  maxlength = getAttr(attributes, "maxlength");
  default_value = getAttr(attributes, "default_value");
  helptext = getNodeText(node, "helptext");
  if (type.contains("enum")) {
    String[] parts = type.split("\\(|\\)");
    String enum_name = parts[1];
    enum_ = enums.find(enum_name);
  }
}
 
Example #9
Source File: Parser.java    From ParsePDM with Apache License 2.0 6 votes vote down vote up
public PDM pdmParser(String pdmFileName) throws Exception {
    SAXReader reader = new SAXReader();
    Document doc = reader.read(pdmFileName);
          
    Node model = doc.selectSingleNode("//c:Children/o:Model");

    pdm.setId(((Element) model).attributeValue("Id"));
    pdm.setName(model.selectSingleNode("a:Name").getText());
    pdm.setCode(model.selectSingleNode("a:Code").getText());

    Node dbms = model.selectSingleNode("//o:Shortcut");
    pdm.setDBMSCode(dbms.selectSingleNode("a:Code").getText());
    pdm.setDBMSName(dbms.selectSingleNode("a:Name").getText());

    System.out.println("解析PDM为:" + pdm.getCode() + "(" + pdm.getName() + ")  DBMS为:" + pdm.getDBMSCode() + "(" + pdm.getDBMSName() + ")");

    pdm.setUsers(pdmUserParser(model));
    pdm.setTables(pdmTableParser(model));
    pdm.setPhysicalDiagrams(pdmPhysicalDiagramParser(model));
    pdm.setReferences(pdmReferenceParser(model));

    return pdm;
}
 
Example #10
Source File: AlipaySubmit.java    From xmu-2016-MrCode with GNU General Public License v2.0 6 votes vote down vote up
/**
    * 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数
    * 注意:远程解析XML出错,与服务器是否支持SSL等配置有关
    * @return 时间戳字符串
    * @throws IOException
    * @throws DocumentException
    * @throws MalformedURLException
    */
public static String query_timestamp() throws MalformedURLException,
                                                       DocumentException, IOException {

       //构造访问query_timestamp接口的URL串
       String strUrl = ALIPAY_GATEWAY_NEW + "service=query_timestamp&partner=" + AlipayConfig.partner + "&_input_charset" +AlipayConfig.input_charset;
       StringBuffer result = new StringBuffer();

       SAXReader reader = new SAXReader();
       Document doc = reader.read(new URL(strUrl).openStream());

       List<Node> nodeList = doc.selectNodes("//alipay/*");

       for (Node node : nodeList) {
           // 截取部分不需要解析的信息
           if (node.getName().equals("is_success") && node.getText().equals("T")) {
               // 判断是否有成功标示
               List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*");
               for (Node node1 : nodeList1) {
                   result.append(node1.getText());
               }
           }
       }

       return result.toString();
   }
 
Example #11
Source File: AlipaySubmit.java    From shopping with Apache License 2.0 6 votes vote down vote up
/**
    * 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数
    * 注意:远程解析XML出错,与服务器是否支持SSL等配置有关
    * @return 时间戳字符串
    * @throws IOException
    * @throws DocumentException
    * @throws MalformedURLException
    */
@SuppressWarnings("unchecked")
public static String query_timestamp() throws MalformedURLException,
                                                       DocumentException, IOException {
       //构造访问query_timestamp接口的URL串
       String strUrl = ALIPAY_GATEWAY_NEW + "service=query_timestamp&partner=" + AlipayConfig.partner + "&_input_charset" +AlipayConfig.input_charset;
       StringBuffer result = new StringBuffer();
       SAXReader reader = new SAXReader();
       Document doc = reader.read(new URL(strUrl).openStream());
       List<Node> nodeList = doc.selectNodes("//alipay/*");
       for (Node node : nodeList) {
           // 截取部分不需要解析的信息
           if (node.getName().equals("is_success") && node.getText().equals("T")) {
               // 判断是否有成功标示
               List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*");
               for (Node node1 : nodeList1) {
                   result.append(node1.getText());
               }
           }
       }
       return result.toString();
   }
 
Example #12
Source File: ManifestFileUtils.java    From atlas with Apache License 2.0 6 votes vote down vote up
private static void singleProcess(Document document, String applicationId) {
        List<Node> nodes = document.getRootElement().selectNodes("//provider");
    for (Node node : nodes) {
        Element element = (Element)node;
        String value = element.attributeValue("name");
        if (value.equals(INSTANT_RUN_CONTENTPROVIDER)){
            element.addAttribute("name",ALI_INSTANT_RUN_CONTENTPROVIDER);
            element.addAttribute("authorities",applicationId+"."+ALI_INSTANT_RUN_CONTENTPROVIDER);
            Attribute attribute = element.attribute("multiprocess");
            if (attribute!= null) {
                attribute.setValue("false");
                logger.warn("singleProcess  com.android.tools.ir.server.InstantRunContentProvider.......");
            }

        }

    }

}
 
Example #13
Source File: XmlUtils.java    From nbp with Apache License 2.0 6 votes vote down vote up
public List<TaskInfo> xmlReadTaskInfo(Document document, String local) {
    Document doc = document;
    List<Node> list = doc.selectNodes("/ROOT/TaskId");
    Iterator<Node> it = list.iterator();
    List<TaskInfo> taskInfoList = new ArrayList<TaskInfo>();
    while (it.hasNext()) {
        TaskInfo taskInfo = new TaskInfo();
        Element taskElement = (Element) it.next();
        Node taskId = taskElement.selectSingleNode("taskId");
        Node labelKey = taskElement.selectSingleNode("taskLabelKey");
        Node labelValue = taskElement.selectSingleNode("taskLabelValue");
        Node summaryKey = taskElement.selectSingleNode("taskSummaryKey");
        Node summaryValue = taskElement.selectSingleNode("taskSummaryValue");
        taskInfo.setTaskId(taskId.getText());
        taskInfo.setTaskLabel(labelKey.getText());
        taskInfo.setTaskLabelValue(labelValue.getText());
        taskInfo.setTaskSummary(summaryKey.getText());
        taskInfo.setTaskSummaryValue(summaryValue.getText());
        taskInfo.setTasklocal(local);
        taskInfoList.add(taskInfo);
    }
    return taskInfoList;
}
 
Example #14
Source File: XmlUtils.java    From nbp with Apache License 2.0 6 votes vote down vote up
public List<EventsInfo> xmlReadEventTypeInfo(Document document, String local) {
    Document doc = document;
    List<Node> list = doc.selectNodes("/ROOT/EventID");
    Iterator<Node> it = list.iterator();
    List<EventsInfo> eventInfoList = new ArrayList<EventsInfo>();
    while (it.hasNext()) {
        EventsInfo event = new EventsInfo();
        Element eventElement = (Element) it.next();
        Node evety = eventElement.selectSingleNode("EventType");
        Node id = eventElement.selectSingleNode("EventType/eventTypeID");
        Node des = eventElement.selectSingleNode("EventType/description");
        event.setEventName(String.valueOf(eventElement.attribute("name")
                .getValue()));
        event.setEventTypeId(id.getText());
        event.setEventDescription(des.getText());
        event.setEventTypeSchema(evety.asXML());
        event.setEventSeverity(eventElement.attribute("severity")
                .getValue());
        event.setEventLocal(local);
        eventInfoList.add(event);
    }
    return eventInfoList;
}
 
Example #15
Source File: PictureDom4jDbTemplate.java    From egdownloader with GNU General Public License v2.0 6 votes vote down vote up
public boolean update(Picture t) {
	if(t == null){
		return false;
	}
	while(locked){
		update(t);
	}
	locked = true;
	Node node = dom.selectSingleNode("/pictures/picture[@id='" + t.getId() + "']");
	if(node != null){
		try {
			Dom4jUtil2.deleteElement(dom.getRootElement(), (Element)node);
			Dom4jUtil2.appendElement(dom.getRootElement(), picture2Element(t));
			Dom4jUtil2.writeDOM2XML(ComponentConst.PICTURE_XML_DATA_PATH, dom);
			locked = false;
			return true;
		} catch (Exception e) {
			locked = false;
			return false;
		}
	}
	locked = false;
	return false;
}
 
Example #16
Source File: ContentTypesConfigImpl.java    From studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param config
 * @param copyDependencyNodes
 */
protected void loadCopyDependencyPatterns(ContentTypeConfigTO config, List<Node> copyDependencyNodes) {
    List<CopyDependencyConfigTO> copyConfig = new ArrayList<CopyDependencyConfigTO>();
    if (copyDependencyNodes != null) {
        for (Node copyDependency : copyDependencyNodes) {
            Node patternNode = copyDependency.selectSingleNode("pattern");
            Node targetNode = copyDependency.selectSingleNode("target");
            if(patternNode!=null && targetNode!=null){
                String pattern = patternNode.getText();
                String target = targetNode.getText();
                if(StringUtils.isNotEmpty(pattern) && StringUtils.isNotEmpty(target)){
                    CopyDependencyConfigTO copyDependencyConfigTO  = new CopyDependencyConfigTO(pattern,target);
                    copyConfig.add(copyDependencyConfigTO);
                }
            }
        }
    }
    config.setCopyDepedencyPattern(copyConfig);

}
 
Example #17
Source File: CalculatedFieldsDAOFileImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
private String loadExpression(Node calculatedFieldNode) {
	String expression;

	expression = null;

	Node expressionNode = calculatedFieldNode.selectSingleNode(EXPRESSION_TAG);
	if (expressionNode != null) {
		expression = expressionNode.getStringValue();
	} else { // for back compatibility
		expression = calculatedFieldNode.getStringValue();
	}

	return expression;
}
 
Example #18
Source File: CalculatedFieldsDAOFileImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
private ModelCalculatedField.Slot loadSlot(Node slotNode) {
	ModelCalculatedField.Slot slot;

	String slotValue = slotNode.valueOf("@value");
	slot = new ModelCalculatedField.Slot(slotValue);

	List<Node> mappedValues = slotNode.selectNodes(VALUESET_TAG);
	for (Node mappedValuesNode : mappedValues) {
		ModelCalculatedField.Slot.IMappedValuesDescriptor descriptor = loadDescriptor(mappedValuesNode);
		slot.addMappedValuesDescriptors(descriptor);
	}

	return slot;
}
 
Example #19
Source File: CheckMessages.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Element checkElement(Node node, String elementName) throws DocumentException {
    if (!(node instanceof Element)) {
        throw new CheckMessagesException("Node is not an element", this, node);
    }
    Element element = (Element) node;
    Element child = element.element(elementName);
    if (child == null) {
        throw new CheckMessagesException("Missing " + elementName + " element", this, node);
    }
    return child;
}
 
Example #20
Source File: BetweenHandler.java    From zealot with Apache License 2.0 5 votes vote down vote up
/**
 * 构建一般区间查询(数字、字符串等)的动态条件sql.
 * @param source 构建所需的资源对象
 * @return 返回SqlInfo对象
 */
@Override
public SqlInfo buildSqlInfo(BuildSource source) {
    /* 获取拼接的参数 */
    SqlInfo sqlInfo = source.getSqlInfo();
    Node node = source.getNode();

    /* 判断必填的参数是否为空 */
    String fieldText = XmlNodeHelper.getAndCheckNodeText(node, ZealotConst.ATTR_FIELD);
    String[] valueTextArr = XmlNodeHelper.getBothCheckNodeText(node);

    /* 如果匹配中字符没有,则认为是必然生成项 */
    Node matchNode = node.selectSingleNode(ZealotConst.ATTR_MATCH);
    String matchText = XmlNodeHelper.getNodeText(matchNode);
    if (StringHelper.isBlank(matchText)) {
        sqlInfo = XmlSqlInfoBuilder.newInstace(source).buildBetweenSql(fieldText,
                valueTextArr[0], valueTextArr[1]);
    } else {
        /* 如果match匹配成功,则生成数据库sql条件和参数. */
        Boolean isTrue = (Boolean) ParseHelper.parseExpressWithException(matchText, source.getParamObj());
        if (isTrue) {
            sqlInfo = XmlSqlInfoBuilder.newInstace(source).buildBetweenSql(fieldText,
                    valueTextArr[0], valueTextArr[1]);
        }
    }

    return sqlInfo;
}
 
Example #21
Source File: ManifestFileUtils.java    From atlas with Apache License 2.0 5 votes vote down vote up
private static List<Node> selectComponents(Element root) {

        String[] components = new String[] {"activity", "provider", "receiver", "service"};

        List<Node> nodes = new ArrayList<>();
        for (String component : components) {
            nodes.addAll(root.selectNodes("//" + component));
        }

        return nodes;
    }
 
Example #22
Source File: ManifestFileUtils.java    From atlas with Apache License 2.0 5 votes vote down vote up
private static void removeProvider(Document document) throws IOException, DocumentException {

        Element root = document.getRootElement();// Get the root node
        List<? extends Node> nodes = root.selectNodes("//provider");
        for (Node node : nodes) {
            Element element = (Element)node;
            String name = element.attributeValue("name");
            logger.info("[Remove Provider]" + name);
            element.getParent().remove(element);
        }
    }
 
Example #23
Source File: Parser.java    From ParsePDM with Apache License 2.0 5 votes vote down vote up
private String selectSingleNodeStringText(Node parentNode, String childNodeName) {
    Node childNode = parentNode.selectSingleNode(childNodeName);
    if (childNode != null) {
        return childNode.getText();
    } else {
        return null;
    }
}
 
Example #24
Source File: SecurityServiceImpl.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void loadRoles(Element root, PermissionsConfigTO config) {
    if (root.getName().equals(StudioXmlConstants.DOCUMENT_ROLE_MAPPINGS)) {
        Map<String, List<String>> rolesMap = new HashMap<String, List<String>>();

        List<Node> userNodes = root.selectNodes(StudioXmlConstants.DOCUMENT_ELM_USER_NODE);
        rolesMap = getRoles(userNodes, rolesMap);

        List<Node> groupNodes = root.selectNodes(StudioXmlConstants.DOCUMENT_ELM_GROUPS_NODE);
        rolesMap = getRoles(groupNodes, rolesMap);

        config.setRoles(rolesMap);
    }
}
 
Example #25
Source File: SecurityServiceImpl.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected Map<String, List<String>> getRoles(List<Node> nodes, Map<String, List<String>> rolesMap) {
    for (Node node : nodes) {
        String name = node.valueOf(StudioXmlConstants.DOCUMENT_ATTR_PERMISSIONS_NAME);
        if (!StringUtils.isEmpty(name)) {
            List<Node> roleNodes = node.selectNodes(StudioXmlConstants.DOCUMENT_ELM_PERMISSION_ROLE);
            List<String> roles = new ArrayList<String>();
            for (Node roleNode : roleNodes) {
                roles.add(roleNode.getText());
            }
            rolesMap.put(name, roles);
        }
    }
    return rolesMap;
}
 
Example #26
Source File: PluginLoader.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static String findMessageText(List<Document> messageCollectionList, String xpath, String missingMsg) {
    for (Document document : messageCollectionList) {
        Node node = document.selectSingleNode(xpath);
        if (node != null) {
            return node.getText().trim();
        }
    }
    return missingMsg;
}
 
Example #27
Source File: PictureDom4jDbTemplate.java    From egdownloader with GNU General Public License v2.0 5 votes vote down vote up
public List<Picture> query() {
	@SuppressWarnings("unchecked")
	List<Node> nodes = dom.selectNodes("/pictures/picture");
	if(nodes != null && nodes.size() > 0){
		List<Picture> pics = new ArrayList<Picture>();
		for (Node node : nodes) {
			pics.add(node2Picture(node));
		}
		return pics;
	}
	return null;
}
 
Example #28
Source File: TextHandler.java    From zealot with Apache License 2.0 5 votes vote down vote up
/**
 * 构建'<text></text>'标签中sqlInfo中的SQL文本信息,如果有非文本节点则抛出异常.
 * 即text节点中的内容不能包含其他标签
 * @param node xml标签节点
 */
@SuppressWarnings("unchecked")
private void concatSqlText(Node node, SqlInfo sqlInfo) {
    // 获取所有子节点,并分别将其使用StringBuilder拼接起来
    List<Node> nodes = node.selectNodes(ZealotConst.ATTR_CHILD);
    for (Node n: nodes) {
        if (ZealotConst.NODETYPE_TEXT.equals(n.getNodeTypeName())) {
            // 如果子节点node 是文本节点,则直接获取其文本
            sqlInfo.getJoin().append(n.getText());
        } else {
            throw new ContainXmlTagException("<text></text>标签中不能包含其他xml标签,只能是文本元素!");
        }
    }
}
 
Example #29
Source File: DefaultElementInterface.java    From mts with GNU General Public License v3.0 5 votes vote down vote up
public static void replaceNode(DefaultElement parent, Node reference, Node element)
{
    int index = parent.indexOf(reference);
    
    if(null != element)
    {
        parent.addNewNode(index, element);
    }
    parent.removeNode(reference);
}
 
Example #30
Source File: GraphQLTypeFactoryImpl.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void createField(Document contentTypeDefinition, Node contentTypeField, String parentGraphQLTypeName,
                        GraphQLObjectType.Builder parentGraphQLType) {
    String contentTypeFieldId = XmlUtils.selectSingleNodeValue(contentTypeField, contentTypeFieldIdXPath);

    if (ArrayUtils.isNotEmpty(ignoredFields) && ArrayUtils.contains(ignoredFields, contentTypeFieldId)) {
        return;
    }

    String contentTypeFieldType = XmlUtils.selectSingleNodeValue(contentTypeField, contentTypeFieldTypeXPath);
    String graphQLFieldName = getGraphQLName(contentTypeFieldId);

    // Don't add the field again if it already exists
    if (!parentGraphQLType.hasField(graphQLFieldName)) {
        logger.debug("Creating GraphQL field '{}' for '{}'", graphQLFieldName, contentTypeFieldId);

        GraphQLFieldDefinition.Builder graphQLField = GraphQLFieldDefinition.newFieldDefinition()
            .name(graphQLFieldName)
            .description(XmlUtils.selectSingleNodeValue(contentTypeField, contentTypeFieldTitleXPath));

        if (fieldFactories.containsKey(contentTypeFieldType)) {
            fieldFactories.get(contentTypeFieldType).createField(contentTypeDefinition, contentTypeField,
                                                                 contentTypeFieldId, parentGraphQLTypeName,
                                                                 parentGraphQLType, graphQLFieldName, graphQLField);
        } else {
            setTypeFromFieldName(contentTypeFieldId, graphQLField);
        }

        parentGraphQLType.field(graphQLField);
    }
}