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

The following examples show how to use org.dom4j.Node#getText() . 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: NotificationServiceImpl.java    From studio with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void loadEmailTemplates(final Element emailTemplates, final Map<String, EmailMessageTemplateTO>
    messageContainer) {
    if (emailTemplates != null) {
        List<Element> messages = emailTemplates.elements();
        if (!messages.isEmpty()) {
            for (Element message : messages) {
                final Node subjectNode = message.element("subject");
                final Node bodyNode = message.element("body");
                final String messageKey = message.attributeValue("key");
                if (subjectNode != null && bodyNode != null) {
                    EmailMessageTemplateTO emailMessageTemplateTO = new EmailMessageTemplateTO(subjectNode
                        .getText(), bodyNode.getText());
                    messageContainer.put(messageKey, emailMessageTemplateTO);
                } else {
                    logger.error("Email message malformed");
                }
            }
        } else {
            logger.error("completed Messages is empty");
        }
    } else {
        logger.error("Unable to read completed Messages (they don't exist)");
    }
}
 
Example 2
Source File: LilithDataStore.java    From CardFantasy with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static LilithDataStore loadDefault() {
    LilithDataStore store = new LilithDataStore();

    URL url = LilithDataStore.class.getClassLoader().getResource("cfvbaibai/cardfantasy/game/LilithData.xml");
    SAXReader reader = new SAXReader();
    try {
        Document doc = reader.read(url);
        @SuppressWarnings("unchecked")
        List<Node> lilithNodes = doc.selectNodes("/Liliths/Lilith");
        for (Node lilithNode : lilithNodes) {
            int adjAT = Integer.parseInt(lilithNode.valueOf("@adjAT"));
            int adjHP = Integer.parseInt(lilithNode.valueOf("@adjHP"));
            String id = lilithNode.valueOf("@id");
            String deckDescs = lilithNode.getText();
            LilithStartupInfo lsi = new LilithStartupInfo(id, deckDescs, adjAT, adjHP);
            store.add(lsi);
        }
        return store;
    } catch (DocumentException e) {
        throw new CardFantasyRuntimeException("Cannot load card info XML.", e);
    }
}
 
Example 3
Source File: ContentServiceImpl.java    From studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * get WCM content item order metadata
 *
 * @param nodes
 * @return item orders metadata
 */
protected List<DmOrderTO> getItemOrders(List<Node> nodes) {
    // TODO: SJ: Rewrite this and the whole order/sort system; 3.1+
    if (nodes != null) {
        List<DmOrderTO> orders = new ArrayList<DmOrderTO>(nodes.size());
        for (Node node : nodes) {

            String orderName = DmConstants.JSON_KEY_ORDER_DEFAULT;
            String orderStr = node.getText();
            addOrderValue(orders, orderName, orderStr);
        }
        return orders;
    } else {
        return null;
    }
}
 
Example 4
Source File: ContentTypesConfigImpl.java    From studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * load delete dependencies mapping
 *
 * @param contentTypeConfig
 * @param nodes
 */
protected void loadDeleteDependencies(ContentTypeConfigTO contentTypeConfig, List<Node> nodes) {
    List<DeleteDependencyConfigTO> deleteConfigs = new ArrayList<>();
    if (nodes != null) {
        for (Node node : nodes) {
            Node patternNode = node.selectSingleNode("pattern");
            Node removeFolderNode = node.selectSingleNode("remove-empty-folder");
            if(patternNode!=null){
                String pattern = patternNode.getText();
                String removeEmptyFolder = removeFolderNode.getText();
                boolean isRemoveEmptyFolder=false;
                if(removeEmptyFolder!=null){
                    isRemoveEmptyFolder = Boolean.valueOf(removeEmptyFolder);
                }
                if(StringUtils.isNotEmpty(pattern)){
                    DeleteDependencyConfigTO deleteConfigTO =
                            new DeleteDependencyConfigTO(pattern, isRemoveEmptyFolder);
                    deleteConfigs.add(deleteConfigTO);
                }
            }
        }
        contentTypeConfig.setDeleteDependencies(deleteConfigs);
    }
}
 
Example 5
Source File: ContentTypesConfigImpl.java    From studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * get paths
 *
 * @param root
 * @param path
 * @return get paths
 */
@SuppressWarnings("unchecked")
private List<String> getPaths(Element root, String path) {
    List<String> paths = null;
    List<Node> nodes = root.selectNodes(path);
    if (nodes != null && nodes.size() > 0) {
        paths = new ArrayList<String>(nodes.size());
        for (Node node : nodes) {
            String role = node.getText();
            if (!StringUtils.isEmpty(role)) {
                paths.add(role);
            }
        }
    } else {
        paths = new ArrayList<String>();
    }
    return paths;
}
 
Example 6
Source File: ContentTypesConfigImpl.java    From studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * load a list of allowed roles
 * @param config
 * @param nodes
 */
protected void loadRoles(ContentTypeConfigTO config, List<Node> nodes) {
    Set<String> roles = null;
    if (nodes != null && nodes.size() > 0) {
        roles = new HashSet<String>(nodes.size());
        for (Node node : nodes) {
            String role = node.getText();
            if (!StringUtils.isEmpty(role)) {
                roles.add(role);
            }
        }
    } else {
        roles = new HashSet<String>();
    }
    config.setAllowedRoles(roles);
}
 
Example 7
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 8
Source File: XmlHttpDecoder.java    From boubei-tss with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * 将Request中的XML数据流解析成普通的名值对后置回Request对象并返回
 * </p>
 * @param element
    *      类似:<Request><Param><Name><![CDATA[resourceId]]></Name><Value><![CDATA[2]]></Value></Param></Request>
 * @param request
 * @return
 */
public static XHttpServletRequest decode(Element element, HttpServletRequest request) {
	HttpServletRequest httpRequest = (HttpServletRequest) request;
	XHttpServletRequest req = XHttpServletRequestWrapper.wrapRequest(httpRequest);

	// 输出请求(request)的详细信息:请求数据流
       log.debug("---------------------------- Request ----------------------------");
       log.debug("AppCode: " + Config.getAttribute(PX.APPLICATION_CODE));
       log.debug("Request: " + req.getContextPath() + req.getServletPath());
       log.debug("Method: " + req.getMethod());
       log.debug("Params: " + element.asXML());
       log.debug("---------------------------- End of Request ----------------------------");
       
       //解析Document对象,将相应的值置入Request对象中
       List<Element> paramNodes = XMLDocUtil.selectNodes(element, "Param");
       for (Element paramNode : paramNodes) {
           Node nameNode  = paramNode.selectSingleNode("Name");
           Node valueNode = paramNode.selectSingleNode("Value");
           if (nameNode != null && valueNode != null) {
               String name  = nameNode.getText();
               String value = valueNode.getText();
               
               value = value.replaceAll("&lt;!\\[CDATA\\[", "<![CDATA[").replaceAll("\\]\\]&gt;", "]]>");
               req.addParameter(name, value);
           }
       }

	return req;
}
 
Example 9
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 10
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 11
Source File: DungeonsStages.java    From CardFantasy with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings("unchecked")
public DungeonsStages() {
    this.dungeonsStages = new HashMap<String, MapInfo>();
    URL url = CardDataStore.class.getClassLoader().getResource("cfvbaibai/cardfantasy/data/DungeonsStages.xml");
    SAXReader reader = new SAXReader();
    String currentId = "";
    try {
        Document doc = reader.read(url);
        List<Node> mapNodes = doc.selectNodes("/Maps/Map");
        for (Node mapNode : mapNodes) {
            String id = mapNode.valueOf("@id");
            currentId = id;
            int heroHP = Integer.parseInt(mapNode.valueOf("@heroHP"));
            String descText = mapNode.getText();
            String[] descs = descText.split(",");
            DeckStartupInfo deck = DeckBuilder.build(descs);
            MapEnemyHero hero = new MapEnemyHero(id, heroHP, deck.getRunes(), deck.getCards());
            String victoryText = mapNode.valueOf("@victory");
            VictoryCondition victory = VictoryCondition.parse(victoryText);
            String deckInfo = mapNode.getText();
            MapInfo mapInfo = new MapInfo(hero, victory, deckInfo);
            this.dungeonsStages.put(id, mapInfo);
        }
    } catch (Exception e) {
        throw new CardFantasyRuntimeException("Cannot load card map info XML due to error at " + currentId, e);
    }
}
 
Example 12
Source File: MapStages.java    From CardFantasy with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings("unchecked")
public MapStages() {
    this.mapStages = new HashMap<String, MapInfo>();
    URL url = CardDataStore.class.getClassLoader().getResource("cfvbaibai/cardfantasy/data/MapStages.xml");
    SAXReader reader = new SAXReader();
    String currentId = "";
    try {
        Document doc = reader.read(url);
        List<Node> mapNodes = doc.selectNodes("/Maps/Map");
        for (Node mapNode : mapNodes) {
            String id = mapNode.valueOf("@id");
            currentId = id;
            int heroHP = Integer.parseInt(mapNode.valueOf("@heroHP"));
            String descText = mapNode.getText();
            String[] descs = descText.split(",");
            DeckStartupInfo deck = DeckBuilder.build(descs);
            MapEnemyHero hero = new MapEnemyHero(id, heroHP, deck.getRunes(), deck.getCards());
            String victoryText = mapNode.valueOf("@victory");
            VictoryCondition victory = VictoryCondition.parse(victoryText);
            String deckInfo = mapNode.getText();
            MapInfo mapInfo = new MapInfo(hero, victory, deckInfo);
            this.mapStages.put(id, mapInfo);
        }
    } catch (Exception e) {
        throw new CardFantasyRuntimeException("Cannot load card map info XML due to error at " + currentId, e);
    }
}
 
Example 13
Source File: ContentServiceImpl.java    From studio with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
protected Document updateContentOnCopy(Document document, String filename, String folder, Map<String,
    String> params, String modifier)
        throws ServiceLayerException {

    //update pageId and groupId with the new one
    Element root = document.getRootElement();
    String originalPageId = null;
    String originalGroupId = null;

    Node filenameNode = root.selectSingleNode("//" + DmXmlConstants.ELM_FILE_NAME);
    if (filenameNode != null) {
        filenameNode.setText(filename);
    }

    Node folderNode = root.selectSingleNode("//" + DmXmlConstants.ELM_FOLDER_NAME);
    if (folderNode != null) {
        folderNode.setText(folder);
    }

    Node pageIdNode = root.selectSingleNode("//" + DmXmlConstants.ELM_PAGE_ID);
    if (pageIdNode != null) {
        originalPageId = pageIdNode.getText();
        pageIdNode.setText(params.get(DmConstants.KEY_PAGE_ID));
    }

    if(modifier != null) {
        Node internalNameNode = root.selectSingleNode("//" + DmXmlConstants.ELM_INTERNAL_NAME);
        if (internalNameNode != null) {
            String internalNameValue = internalNameNode.getText();
            internalNameNode.setText(internalNameValue + " " + modifier);
        }
    }

    Node groupIdNode = root.selectSingleNode("//" + DmXmlConstants.ELM_GROUP_ID);
    if (groupIdNode != null) {
        originalGroupId = groupIdNode.getText();
        groupIdNode.setText(params.get(DmConstants.KEY_PAGE_GROUP_ID));
    }

    List<Node> keys = root.selectNodes("//key");
    if (keys != null) {
        for(Node keyNode : keys) {
            String keyValue = keyNode.getText();
            keyValue = keyValue.replaceAll(originalPageId, params.get(DmConstants.KEY_PAGE_ID));
            keyValue = keyValue.replaceAll(originalGroupId, params.get(DmConstants.KEY_PAGE_GROUP_ID));

            if(keyValue.contains("/page")) {
                keyNode.setText(keyValue);
            }
        }
    }

    List<Node> includes = root.selectNodes("//include");
    if (includes != null) {
        for(Node includeNode : includes) {
            String includeValue = includeNode.getText();
            includeValue = includeValue.replaceAll(originalPageId, params.get(DmConstants.KEY_PAGE_ID));
            includeValue = includeValue.replaceAll(originalGroupId, params.get(DmConstants.KEY_PAGE_GROUP_ID));

            if(includeValue.contains("/page")) {
                includeNode.setText(includeValue);
            }
        }
    }

    return document;
}
 
Example 14
Source File: XMLInputFieldsImportProgressDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings( "unchecked" )
private void setNodeField( Node node, IProgressMonitor monitor ) {
  Element e = (Element) node;
  // get all attributes
  List<Attribute> lista = e.attributes();
  for ( int i = 0; i < lista.size(); i++ ) {
    setAttributeField( lista.get( i ), monitor );
  }

  // Get Node Name
  String nodename = node.getName();
  String nodenametxt = cleanString( node.getPath() );

  if ( !Utils.isEmpty( nodenametxt ) && !list.contains( nodenametxt ) ) {
    nr++;
    monitor.subTask( BaseMessages.getString( PKG, "GetXMLDataXMLInputFieldsImportProgressDialog.Task.FetchFields",
        String.valueOf( nr ) ) );
    monitor.subTask( BaseMessages.getString( PKG, "GetXMLDataXMLInputFieldsImportProgressDialog.Task.AddingField",
        nodename ) );

    RowMetaAndData row = new RowMetaAndData();
    row.addValue( VALUE_NAME, Value.VALUE_TYPE_STRING, nodename );
    row.addValue( VALUE_PATH, Value.VALUE_TYPE_STRING, nodenametxt );
    row.addValue( VALUE_ELEMENT, Value.VALUE_TYPE_STRING, GetXMLDataField.ElementTypeDesc[0] );
    row.addValue( VALUE_RESULT, Value.VALUE_TYPE_STRING, GetXMLDataField.ResultTypeDesc[0] );

    // Get Node value
    String valueNode = node.getText();

    // Try to get the Type

    if ( IsDate( valueNode ) ) {
      row.addValue( VALUE_TYPE, Value.VALUE_TYPE_STRING, "Date" );
      row.addValue( VALUE_FORMAT, Value.VALUE_TYPE_STRING, "yyyy/MM/dd" );
    } else if ( IsInteger( valueNode ) ) {
      row.addValue( VALUE_TYPE, Value.VALUE_TYPE_STRING, "Integer" );
      row.addValue( VALUE_FORMAT, Value.VALUE_TYPE_STRING, null );
    } else if ( IsNumber( valueNode ) ) {
      row.addValue( VALUE_TYPE, Value.VALUE_TYPE_STRING, "Number" );
      row.addValue( VALUE_FORMAT, Value.VALUE_TYPE_STRING, null );
    } else {
      row.addValue( VALUE_TYPE, Value.VALUE_TYPE_STRING, "String" );
      row.addValue( VALUE_FORMAT, Value.VALUE_TYPE_STRING, null );
    }
    fieldsList.add( row );
    list.add( nodenametxt );

  } // end if
}
 
Example 15
Source File: ServicesConfigImpl.java    From studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * load page/component/assets patterns configuration
 *
 * @param site
 * @param nodes
 */
@SuppressWarnings("unchecked")
protected void loadPatterns(SiteConfigTO site, RepositoryConfigTO repo, List<Node> nodes) {
    if (nodes != null) {
        for (Node node : nodes) {
            String patternKey = node.valueOf(ATTR_NAME);
            if (!StringUtils.isEmpty(patternKey)) {
                List<Node> patternNodes = node.selectNodes(ELM_PATTERN);
                if (patternNodes != null) {
                    List<String> patterns = new ArrayList<String>(patternNodes.size());
                    for (Node patternNode : patternNodes) {
                        String pattern = patternNode.getText();
                        if (!StringUtils.isEmpty(pattern)) {
                            patterns.add(pattern);
                        }
                    }
                    if (patternKey.equals(PATTERN_PAGE)) {
                        repo.setPagePatterns(patterns);
                    } else if (patternKey.equals(PATTERN_COMPONENT)) {
                        repo.setComponentPatterns(patterns);
                    } else if (patternKey.equals(PATTERN_ASSET)) {
                        repo.setAssetPatterns(patterns);
                    } else if (patternKey.equals(PATTERN_DOCUMENT)) {
                        repo.setDocumentPatterns(patterns);
                    } else if (patternKey.equals(PATTERN_RENDERING_TEMPLATE)) {
                        repo.setRenderingTemplatePatterns(patterns);
                    } else if (patternKey.equals(PATTERN_SCRIPTS)) {
                        repo.setScriptsPatterns(patterns);
                    } else if (patternKey.equals(PATTERN_LEVEL_DESCRIPTOR)) {
                        repo.setLevelDescriptorPatterns(patterns);
                    } else if (patternKey.equals(PATTERN_PREVIEWABLE_MIMETYPES)) {
                        repo.setPreviewableMimetypesPaterns(patterns);
                    } else {
                        LOGGER.error("Unknown pattern key: " + patternKey + " is provided in " + site.getName());
                    }
                }
            } else {
                LOGGER.error("no pattern key provided in " + site.getName() +
                        " configuration. Skipping the pattern.");
            }
        }
    } else {
        LOGGER.warn(site.getName() + " does not have any pattern configuration.");
    }
}
 
Example 16
Source File: XmlInputFieldsImportProgressDialog.java    From hop with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings( "unchecked" )
private void setNodeField( Node node, IProgressMonitor monitor ) {
  Element e = (Element) node;
  // get all attributes
  List<Attribute> lista = e.attributes();
  for ( int i = 0; i < lista.size(); i++ ) {
    setAttributeField( lista.get( i ), monitor );
  }

  // Get Node Name
  String nodename = node.getName();
  String nodenametxt = cleanString( node.getPath() );

  if ( !Utils.isEmpty( nodenametxt ) && !list.contains( nodenametxt ) ) {
    nr++;
    monitor.subTask( BaseMessages.getString( PKG, "GetXMLDataXMLInputFieldsImportProgressDialog.Task.FetchFields",
        String.valueOf( nr ) ) );
    monitor.subTask( BaseMessages.getString( PKG, "GetXMLDataXMLInputFieldsImportProgressDialog.Task.AddingField",
        nodename ) );

    RowMetaAndData row = new RowMetaAndData();
    row.addValue( VALUE_NAME, IValueMeta.TYPE_STRING, nodename );
    row.addValue( VALUE_PATH, IValueMeta.TYPE_STRING, nodenametxt );
    row.addValue( VALUE_ELEMENT, IValueMeta.TYPE_STRING, GetXmlDataField.ElementTypeDesc[0] );
    row.addValue( VALUE_RESULT, IValueMeta.TYPE_STRING, GetXmlDataField.ResultTypeDesc[0] );

    // Get Node value
    String valueNode = node.getText();

    // Try to get the Type

    if ( IsDate( valueNode ) ) {
      row.addValue( VALUE_TYPE, IValueMeta.TYPE_STRING, "Date" );
      row.addValue( VALUE_FORMAT, IValueMeta.TYPE_STRING, "yyyy/MM/dd" );
    } else if ( IsInteger( valueNode ) ) {
      row.addValue( VALUE_TYPE, IValueMeta.TYPE_STRING, "Integer" );
      row.addValue( VALUE_FORMAT, IValueMeta.TYPE_STRING, null );
    } else if ( IsNumber( valueNode ) ) {
      row.addValue( VALUE_TYPE, IValueMeta.TYPE_STRING, "Number" );
      row.addValue( VALUE_FORMAT, IValueMeta.TYPE_STRING, null );
    } else {
      row.addValue( VALUE_TYPE, IValueMeta.TYPE_STRING, "String" );
      row.addValue( VALUE_FORMAT, IValueMeta.TYPE_STRING, null );
    }
    fieldsList.add( row );
    list.add( nodenametxt );

  } // end if
}
 
Example 17
Source File: XmlNodeHelper.java    From zealot with Apache License 2.0 2 votes vote down vote up
/**
 * 获取xml节点的文本值,如果对象是空的,则转为空字符串.
 * @param node dom4j节点
 * @return 返回节点文本值
 */
public static String getNodeText(Node node) {
    return node == null ? "" : node.getText();
}
 
Example 18
Source File: XMLDocUtil.java    From boubei-tss with Apache License 2.0 2 votes vote down vote up
/**
 * 获取Dom节点的文本内容。
 * @param node
 * @return
 */
public static String getNodeText(Node node) {
	return node == null ? null : node.getText();
}