Java Code Examples for org.dom4j.Node#selectSingleNode()

The following examples show how to use org.dom4j.Node#selectSingleNode() . 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: 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 2
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 3
Source File: CalculatedFieldsDAOFileImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
private ModelCalculatedField.Slot.MappedValuesRangeDescriptor loadRangeDescriptor(Node mappedValuesNode) {
	ModelCalculatedField.Slot.MappedValuesRangeDescriptor rangeDescriptor = null;

	Node fomrNode = mappedValuesNode.selectSingleNode(FROM_TAG);
	String fromValue = fomrNode.valueOf("@value");
	Node toNode = mappedValuesNode.selectSingleNode(TO_TAG);
	String toValue = toNode.valueOf("@value");
	rangeDescriptor = new ModelCalculatedField.Slot.MappedValuesRangeDescriptor(fromValue, toValue);
	String includeValue = null;
	includeValue = fomrNode.valueOf("@include");
	if (includeValue != null && (includeValue.equalsIgnoreCase("TRUE") || includeValue.equalsIgnoreCase("FALSE"))) {
		rangeDescriptor.setIncludeMinValue(Boolean.parseBoolean(includeValue));
	}
	includeValue = toNode.valueOf("@include");
	if (includeValue != null && (includeValue.equalsIgnoreCase("TRUE") || includeValue.equalsIgnoreCase("FALSE"))) {
		rangeDescriptor.setIncludeMaxValue(Boolean.parseBoolean(includeValue));
	}

	return rangeDescriptor;
}
 
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: XmlNodeHelper.java    From zealot with Apache License 2.0 5 votes vote down vote up
/**
 * 检查和获取节点文本,会检查节点是否为空,如果节点为空,则抛出异常.
 * @param node dom4j节点
 * @param nodeName 节点名称
 * @return 返回节点文本值
 */
public static String getAndCheckNodeText(Node node, String nodeName) {
    /* 判断必填的参数是否为空 */
    Node fieldNode = node.selectSingleNode(nodeName);
    String fieldText = XmlNodeHelper.getNodeText(fieldNode);
    if (StringHelper.isBlank(fieldText)) {
        throw new FieldEmptyException("填写的字段值是空的");
    }
    return fieldText;
}
 
Example 6
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 7
Source File: Parser.java    From ParsePDM with Apache License 2.0 5 votes vote down vote up
public ArrayList<PDMReference> pdmReferenceParser(Node node) throws Exception {
    ArrayList<PDMReference> referenceList = new ArrayList<PDMReference>();
    for (Object reference : node.selectNodes("c:References/o:Reference")) {
        Node referenceNode = (Node) reference;
        PDMReference pdmReference = new PDMReference();
        pdmReference.setId(((Element) referenceNode).attributeValue("Id"));
        pdmReference.setName(referenceNode.selectSingleNode("a:Name").getText());
        pdmReference.setCode(referenceNode.selectSingleNode("a:Code").getText());
        pdmReference.setConstraintName(selectSingleNodeStringText(referenceNode, "ForeignKeyConstraintName"));
        pdmReference.setUpdateConstraint(selectSingleNodeIntText(referenceNode, "UpdateConstraint"));
        pdmReference.setDeleteConstraint(selectSingleNodeIntText(referenceNode, "DeleteConstraint"));
        pdmReference.setImplementationType(selectSingleNodeStringText(referenceNode, "ImplementationType"));
        // 添加ParentTable
        String parentTableId = ((Element) referenceNode.selectSingleNode("c:ParentTable/o:Table")).attributeValue("Ref");
        pdmReference.setParentTable(pdm.getPDMTable(parentTableId));
        // 添加ChildTable
        String childTableId = ((Element) referenceNode.selectSingleNode("c:ChildTable/o:Table")).attributeValue("Ref");
        pdmReference.setChildTable(pdm.getPDMTable(childTableId));
        // 添加Joins
        for (Object jion : referenceNode.selectNodes("c:Joins/o:ReferenceJoin")) {
            Node referenceJoinNode = (Node) jion;
            PDMReferenceJoin pdmReferenceJoin = new PDMReferenceJoin();
            pdmReferenceJoin.setId(((Element) referenceJoinNode).attributeValue("Id"));

            String id = ((Element) referenceJoinNode.selectSingleNode("c:Object1/o:Column")).attributeValue("Ref");
            pdmReferenceJoin.setParentTable_Col(pdmReference.getParentTable().getPDMColumn(id));
            Element element = (Element) referenceJoinNode.selectSingleNode("c:Object2/o:Column");
            if (element == null) {
                continue;
            }
            id = element.attributeValue("Ref");
            pdmReferenceJoin.setChildTable_Col(pdmReference.getChildTable().getPDMColumn(id));

            pdmReference.addReferenceJoin(pdmReferenceJoin);
        }

        referenceList.add(pdmReference);
    }
    return referenceList;
}
 
Example 8
Source File: PluginLoader.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static String getChildText(Node node, String childName) throws PluginException {
    Node child = node.selectSingleNode(childName);
    if (child == null) {
        throw new PluginException("Could not find child \"" + childName + "\" for node");
    }
    return child.getText();
}
 
Example 9
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 10
Source File: NormalHandler.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) {
    /* 获取拼接的参数 */
    String suffix = source.getSuffix();
    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).buildNormalSql(fieldText, valueText, suffix);
    } else {
        /* 如果match匹配成功,则生成数据库sql条件和参数 */
        Boolean isTrue = (Boolean) ParseHelper.parseExpressWithException(matchText, source.getParamObj());
        if (isTrue) {
            sqlInfo = XmlSqlInfoBuilder.newInstace(source).buildNormalSql(fieldText, valueText, suffix);
        }
    }

    source.resetPrefix();
    return sqlInfo;
}
 
Example 11
Source File: XmlNodeHelper.java    From zealot with Apache License 2.0 5 votes vote down vote up
/**
 * 检查和获取开始和结束文本的内容,返回一个数组,会检查两个节点是否为空,如果都为空,则抛出异常.
 * @param node dom4j节点
 * @return 返回开始和结束文本的二元数组
 */
public static String[] getBothCheckNodeText(Node node) {
    Node startNode = node.selectSingleNode(ZealotConst.ATTR_START);
    Node endNode = node.selectSingleNode(ZealotConst.ATTR_ENT);
    String startText = XmlNodeHelper.getNodeText(startNode);
    String endText = XmlNodeHelper.getNodeText(endNode);
    if (StringHelper.isBlank(startText) && StringHelper.isBlank(endText)) {
        throw new FieldEmptyException("填写的开始和结束字段值是空的");
    }
    return new String[] {startText, endText};
}
 
Example 12
Source File: UnittypeXML.java    From freeacs with MIT License 5 votes vote down vote up
public static String getAttr(Node node, String attrName) throws Exception {
  Attribute attr = (Attribute) node.selectSingleNode("@" + attrName);
  if (attr != null) {
    return attr.getValue();
  } else {
    return "";
  }
}
 
Example 13
Source File: CalculatedFieldsDAOFileImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
private String loadDefaultSlotValue(Node calculatedFieldNode) {

		String defaultSlotValue = null;

		Node slotBlock = calculatedFieldNode.selectSingleNode(SLOTS_TAG);
		if (slotBlock != null) {
			defaultSlotValue = slotBlock.valueOf("@defaultSlotValue");
		}

		return defaultSlotValue;
	}
 
Example 14
Source File: CmisServiceImpl.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
private String getPropertyValue(Node repositoryNode, String property) {
    Node propertyNode = repositoryNode.selectSingleNode(property);
    if (propertyNode != null) {
        return propertyNode.getStringValue();
    }
    return StringUtils.EMPTY;
}
 
Example 15
Source File: PluginManager.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the plugin for required operating system.
 *
 * @param plugin the Plugin element to check.
 * @return true if the operating system is ok for the plugin to run on.
 */
private boolean isOperatingSystemOK( Node plugin )
{
    try
    {
        final Element osElement = (Element) plugin.selectSingleNode( "os" );
        if ( osElement != null )
        {
            String operatingSystem = osElement.getText();

            boolean ok = false;

            final String currentOS = JiveInfo.getOS().toLowerCase();

            // Iterate through comma delimited string
            StringTokenizer tkn = new StringTokenizer( operatingSystem, "," );
            while ( tkn.hasMoreTokens() )
            {
                String os = tkn.nextToken().toLowerCase();
                if ( currentOS.contains( os ) || currentOS.equalsIgnoreCase( os ) )
                {
                    ok = true;
                }
            }

            if ( !ok )
            {
                Log.debug( "Unable to load plugin " + plugin.selectSingleNode( "name" ).getText() + " due to invalid operating system. Required OS = " + operatingSystem );
                return false;
            }
        }
    }
    catch ( Exception e )
    {
        Log.error( "An exception occured while trying to determine operating system compatibility of plugin '"+plugin+"'", e );
    }

    return true;
}
 
Example 16
Source File: Parser.java    From ParsePDM with Apache License 2.0 5 votes vote down vote up
private int selectSingleNodeIntText(Node parentNode, String childNodeName) {
    Node childNode = parentNode.selectSingleNode(childNodeName);
    if (childNode != null) {
        return Integer.parseInt(childNode.getText());
    } else {
        return 0;
    }
}
 
Example 17
Source File: ConversionUtil.java    From pentaho-aggdesigner with GNU General Public License v2.0 5 votes vote down vote up
public static String getXPathNodeText( Node parent, String xpath ) throws AggDesignerException {
  Element element = (Element) parent.selectSingleNode( xpath );
  if ( element == null ) {
    throw new AggDesignerException( "no element found for xpath '" + xpath + "'" );
  }
  return ( (Element) parent.selectSingleNode( xpath ) ).getTextTrim();
}
 
Example 18
Source File: Parser.java    From ParsePDM with Apache License 2.0 4 votes vote down vote up
public ArrayList<PDMTable> pdmTableParser(Node node) throws Exception {
        ArrayList<PDMTable> tableList = new ArrayList<PDMTable>();
        ArrayList l = new ArrayList();
        List ll = node.selectNodes("c:Packages/o:Package/c:Tables/o:Table");
        if (!ll.isEmpty()) {
            l.addAll((ArrayList) node.selectNodes("c:Packages/o:Package/c:Tables/o:Table"));
        }
        List lll = node.selectNodes("c:Tables/o:Table");
        if (!lll.isEmpty()) {
            l.addAll(node.selectNodes("c:Tables/o:Table"));
        }

//		List l = node.selectNodes("c:Packages/o:Package/c:Tables/o:Table");
        for (Object o : l) {
            Node tableNode = (Node) o;
            PDMTable pdmTable = new PDMTable();
            pdmTable.setId(((Element) tableNode).attributeValue("Id"));
            pdmTable.setName(tableNode.selectSingleNode("a:Name").getText());
            pdmTable.setCode(tableNode.selectSingleNode("a:Code").getText());
            // 添加Columns
            pdmTable.setColumns(pdmColumnParser(tableNode));
            // 添加key
            for (Object key : tableNode.selectNodes("c:Keys/o:Key")) {
                Node keyNode = (Node) key;
                PDMKey pdmKey = new PDMKey();
                pdmKey.setId(((Element) keyNode).attributeValue("Id"));
                pdmKey.setName(keyNode.selectSingleNode("a:Name").getText());
                pdmKey.setCode(keyNode.selectSingleNode("a:Code").getText());
                for (Object column : keyNode.selectNodes("c:Key.Columns/o:Column")) {
                    String id = ((Element) column).attributeValue("Ref");
                    pdmKey.addColumn(pdmTable.getPDMColumn(id));
                }
                pdmTable.addKey(pdmKey);
            }
            // 添加PrimaryKey
            if (null != tableNode.selectSingleNode("c:PrimaryKey/o:Key")) {
                String keyId = ((Element) tableNode.selectSingleNode("c:PrimaryKey/o:Key")).attributeValue("Ref");
                pdmTable.setPrimaryKey(pdmTable.getPDMKey(keyId));
            }

            // 添加Indexes
            for (Object index : tableNode.selectNodes("c:Indexes/o:Index")) {
                Node indexNode = (Node) index;
                PDMIndex pdmIndex = new PDMIndex();
                pdmIndex.setId(((Element) indexNode).attributeValue("Id"));
                pdmIndex.setName(indexNode.selectSingleNode("a:Name").getText());
                pdmIndex.setCode(indexNode.selectSingleNode("a:Code").getText());
                /*
                 for (Object column : indexNode.selectNodes("//c:Column/o:Column")) {
                 String id = ((Element) column).attributeValue("Ref");
                 pdmIndex.addColumn(pdmTable.getPDMColumn(id));
                 }
                 */
                pdmTable.addIndex(pdmIndex);
            }
            // 添加User
            Element userElement = (Element) tableNode.selectSingleNode("c:Owner/o:User");
            if (userElement != null) {
                String userId = userElement.attributeValue("Ref");
                pdmTable.setUser(pdm.getPDMUser(userId));
            }

            tableList.add(pdmTable);
        }
        return tableList;
    }
 
Example 19
Source File: RemoteArticleService.java    From boubei-tss with Apache License 2.0 4 votes vote down vote up
public String getArticleListByChannelAndTime(Long channelId, Integer year, Integer month) {
    if(channelId == null){
        throw new BusinessException(EX.CMS_1);
    }
    if(year == null || month == null){
        throw new BusinessException(EX.CMS_10);
    }
    
    Channel channel = channelDao.getEntity(channelId);
    if(channel == null) {
        throw new BusinessException(EX.CMS_11);
    }
    Channel site = channel.getSite();
    String publishBaseDir = site.getPath();
   
    String publishDir = publishBaseDir + "/" + year + "/" + DateUtil.fixMonth(month);
    List<File> xmlFiles = FileHelper.listFilesByTypeDeeply(".xml", new File(publishDir));
  
    Document doc = org.dom4j.DocumentHelper.createDocument();
    Element channelElement = doc.addElement("rss").addAttribute("version", "2.0");
 
    channelElement.addElement("channelName").setText(channel.getName()); 
    channelElement.addElement("totalPageNum").setText("1");
    channelElement.addElement("totalRows").setText("100");
    channelElement.addElement("currentPage").setText("1");
    for( File xmlFile : xmlFiles ){
        if(xmlFile.getName().startsWith(channelId + "_")){
            Document articleDoc = XMLDocUtil.createDocByAbsolutePath2(xmlFile.getPath());
            
            Node articleNode   = articleDoc.getRootElement();
            Node idNode        = articleNode.selectSingleNode("//id");
            Node titleNode     = articleNode.selectSingleNode("//title");
            Node authorNode    = articleNode.selectSingleNode("//author");
            Node summaryNode   = articleNode.selectSingleNode("//summary");
            Node issueDateNode = articleNode.selectSingleNode("//issueDate");
            
            createArticleElement(channelElement,
            		XMLDocUtil.getNodeText(idNode), 
            		XMLDocUtil.getNodeText(titleNode), 
            		XMLDocUtil.getNodeText(authorNode),
            		DateUtil.parse(XMLDocUtil.getNodeText(issueDateNode)), 
            		XMLDocUtil.getNodeText(summaryNode), 
                    0, 0, null);
        }
    }
    return "<Response><ArticleList>" + channelElement.asXML() + "</ArticleList></Response>";
}
 
Example 20
Source File: XmlNodeHelper.java    From zealot with Apache License 2.0 2 votes vote down vote up
/**
 * 获取节点文本.
 * @param node dom4j节点
 * @param attrName 节点属性
 * @return 返回节点文本值
 */
public static String getNodeAttrText(Node node, String attrName) {
    Node fieldNode = node.selectSingleNode(attrName);
    return XmlNodeHelper.getNodeText(fieldNode);
}