Java Code Examples for org.dom4j.Attribute.setValue()

The following are Jave code examples for showing how to use setValue() of the org.dom4j.Attribute class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: atlas   File: ManifestFileUtils.java   View Source Code Vote up 6 votes
/**
 * Update the attributes of element
 *
 * @param element
 * @param properties
 */
private static void updateElement(Element element, Map<String, String> properties) {
    for (Map.Entry<String, String> entry : properties.entrySet()) {
        String key = entry.getKey();
        if (key.startsWith("tools:")) {
            continue;
        }
        String keyNoPrefix = key;
        String[] values = StringUtils.split(key, ":");
        if (values.length > 1) {
            keyNoPrefix = values[1];
        }
        if (null == entry.getValue()) {
            continue;
        } else {
            Attribute attribute = element.attribute(keyNoPrefix);
            if (null != attribute) {
                attribute.setValue(entry.getValue());
            } else {
                element.addAttribute(key, entry.getValue());
            }
        }
    }
}
 
Example 2
Project: atlas   File: ManifestFileUtils.java   View Source Code Vote up 5 votes
private static void fillFullClazzName(Element root, String packageName, String type) {
    List<? extends Node> applicatNodes = root.selectNodes("//" + type);
    for (Node node : applicatNodes) {
        Element element = (Element)node;
        Attribute attribute = element.attribute("name");
        if (attribute != null) {
            if (attribute.getValue().startsWith(".")) {
                attribute.setValue(packageName + attribute.getValue());
            }
        }
    }
}
 
Example 3
Project: GraphicsViewJambi   File: ExportNetworkToXML.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
public boolean addJunctionConnection(final String id, final String fromNode, 
									  final String from_x, final String from_y, 
									  final String toNode, 
									  final String to_x, final String to_y, 
									  final String dir)
{
	String s = "intconnction[@fromNode='"+fromNode+"' and @toNode='"+toNode+"']";
	List<Element> list = junction.selectNodes(s);
	if(list.isEmpty())
	{
		intconnction = junction.addElement("intconnction");
		intconnction.addAttribute("id", id);
		intconnction.addAttribute("numLanes", "1");
		intconnction.addAttribute("fromNode", fromNode);
		intconnction.addAttribute("from_x", from_x);
		intconnction.addAttribute("from_y", from_y);
		intconnction.addAttribute("toNode", toNode);
		intconnction.addAttribute("to_x", to_x);
		intconnction.addAttribute("to_y", to_y);
		intconnction.addAttribute("dir", dir);
		return true;
	}
	else
	{
		Iterator<Element> iter = list.iterator();
		//System.out.println(list.size());
		while (iter.hasNext())
		{
			Element ele = iter.next();
			Attribute attr = ele.attribute("numLanes");
			Integer numLanes = Integer.parseInt(attr.getValue())+1;
			attr.setValue(numLanes.toString());
		}
		//System.out.println("有重复的lane");
		return false;
	}
}
 
Example 4
Project: alfresco-remote-api   File: SearchProxy.java   View Source Code Vote up 4 votes
@Override
protected void writeResponse(InputStream input, OutputStream output)
    throws IOException
{
    if (response.getContentType().startsWith(MimetypeMap.MIMETYPE_ATOM) ||
        response.getContentType().startsWith(MimetypeMap.MIMETYPE_RSS))
    {
        // Only post-process ATOM and RSS feeds
        // Replace all navigation links with "proxied" versions
        SAXReader reader = new SAXReader();
        try
        {
            Document document = reader.read(input);
            Element rootElement = document.getRootElement();

            XPath xpath = rootElement.createXPath(ATOM_LINK_XPATH);
            Map<String,String> uris = new HashMap<String,String>();
            uris.put(ATOM_NS_PREFIX, ATOM_NS_URI);
            xpath.setNamespaceURIs(uris);

            List nodes = xpath.selectNodes(rootElement);
            Iterator iter = nodes.iterator();
            while (iter.hasNext())
            {
                Element element = (Element)iter.next();
                Attribute hrefAttr = element.attribute("href");
                String mimetype = element.attributeValue("type");
                if (mimetype == null || mimetype.length() == 0)
                {
                    mimetype = MimetypeMap.MIMETYPE_HTML;
                }
                String url = createUrl(engine, hrefAttr.getValue(), mimetype);
                if (url.startsWith("/"))
                {
                    url = rootPath + url;
                }
                hrefAttr.setValue(url);
            }
            
            OutputFormat outputFormat = OutputFormat.createPrettyPrint();
            XMLWriter writer = new XMLWriter(output, outputFormat);
            writer.write(rootElement);
            writer.flush();                
        }
        catch(DocumentException e)
        {
            throw new IOException(e.toString());
        }
    }
    else
    {
        super.writeResponse(input, output);
    }
}