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

The following examples show how to use org.dom4j.Attribute#setValue() . 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: 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 2
Source File: ManifestFileUtils.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * 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 3
Source File: VersionProperty.java    From jfinal-api-scaffold with MIT License 6 votes vote down vote up
public void setVersion(ClientType type, String version) {
    Element clientElement = null;
    switch (type) {
        case ANDROID:
            clientElement = getElement("client.android");
            break;
        case IPHONE:
            clientElement = getElement("client.iphone");
            break;
        default:
            return;
    }

    Attribute attribute = clientElement.attribute("default");

    if (attribute != null) {
        attribute.setValue(version);
        saveProperties();
    }
}
 
Example 4
Source File: XMLElementRTPFLOWParser.java    From mts with GNU General Public License v3.0 5 votes vote down vote up
public List<Element> replace(Element element, ParameterPool parameterPool) throws Exception {
    List<Element> result = new LinkedList();

    //do classic replacement of attribute and save it in result
    Element newElement = element.createCopy();
    result.add(newElement);
    List<Attribute> attributes = newElement.attributes();

    for (Attribute attribute : attributes) {
        if (!attribute.getName().equalsIgnoreCase("timestamp")
                && !attribute.getName().equalsIgnoreCase("seqnum")
                && !attribute.getName().equalsIgnoreCase("deltaTime")
                && !attribute.getName().equalsIgnoreCase("mark")) {
            String value = attribute.getValue();

            LinkedList<String> parsedValue = parameterPool.parse(value);

            if (parsedValue.size() != 1) {
                throw new ExecutionException("Invalid size of variables in attribute " + value);
            }

            attribute.setValue(parsedValue.getFirst());
        }
    }

    return result;
}
 
Example 5
Source File: XMLElementDefaultParser.java    From mts with GNU General Public License v3.0 5 votes vote down vote up
public List<Element> replace(Element element, ParameterPool parameterPool) throws Exception {
    List<Element> list = new LinkedList<Element>();

    Element newElement = element.createCopy();
    list.add(newElement);
    List<Attribute> attributes = newElement.attributes();


    for (Attribute attribute : attributes) {
        String value = attribute.getValue();

        LinkedList<String> parsedValue = parameterPool.parse(value);

        if (parsedValue.size() > 1) 
        {
            throw new ExecutionException("Invalid size of variables in attribute " + value);
        }

        if (parsedValue.size() == 1) 
        {
        	attribute.setValue(parsedValue.getFirst());
        }
        else
        {
        	attribute.setValue(null);
        }
    }
    return list;
}
 
Example 6
Source File: ManifestFileUtils.java    From atlas with Apache License 2.0 5 votes vote down vote up
private static void disableDebuggable(Document document) {
        Element root = document.getRootElement();// Get the root node
        Element app = root.element("application");
        Attribute attribute = app.attribute("debuggable");
        if (attribute!= null){
            attribute.setValue("false");
            logger.warn("disable android:debuggable .......");
//            app.remove(attribute);
        }
    }
 
Example 7
Source File: ManifestFileUtils.java    From atlas with Apache License 2.0 5 votes vote down vote up
private static void addAndroidLabel(Document document,boolean pushInstall) {
    Element root = document.getRootElement();// Get the root node
    Element applicationElement = root.element("application");
    Attribute attribute = applicationElement.attribute("android:extractNativeLibs");
    if (attribute == null && pushInstall){
        applicationElement.addAttribute("android:extractNativeLibs","false");
    }else if (pushInstall){
        attribute.setValue("false");
    }else if (!pushInstall && attribute!= null){
        applicationElement.remove(attribute);
    }
}
 
Example 8
Source File: ManifestFileUtils.java    From atlas with Apache License 2.0 5 votes vote down vote up
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 9
Source File: XMLUtil.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 设置或添加属性
 * @param element
 * @param name
 * @param value
 */
public static void setAttribute(Element element, String name, String value) {
    Attribute attribute = element.attribute(name);
    if (attribute != null) {
        attribute.setValue(value);
    } else {
        element.addAttribute(name, value);
    }
}
 
Example 10
Source File: RouteJavaScriptOSGIForESBManager.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
private static void formatSchemaLocation(Element root, boolean addBlueprint, boolean addCamel) {
    Attribute schemaLocation = root.attribute("schemaLocation");
    if (schemaLocation == null) {
        return;
    }
    String value = schemaLocation.getValue().replaceAll("(\\A|\\b)\\s\\s+\\b", "\n            ");
    if (addBlueprint) {
        value += "\n            http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd";
    }
    if (addCamel) {
        value += "\n            http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd";
    }
    schemaLocation.setValue(value);
}
 
Example 11
Source File: SearchProxy.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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);
    }
}
 
Example 12
Source File: FilterDelegateImpl.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public boolean saveSettings(Element element) {
    boolean changed = false;
    Element e = element.element("defaultFilter");
    if (e == null)
        e = element.addElement("defaultFilter");

    UUID defaultId = null;
    Boolean applyDefault = false;

    for (FilterEntity filter : filterEntities) {
        if (BooleanUtils.isTrue(filter.getIsDefault())) {
            defaultId = filter.getId();
            applyDefault = filter.getApplyDefault();
            break;
        }
    }

    String newDef = defaultId != null ? defaultId.toString() : null;
    Attribute attr = e.attribute("id");
    String oldDef = attr != null ? attr.getValue() : null;
    if (!Objects.equals(oldDef, newDef)) {
        if (newDef == null && attr != null) {
            e.remove(attr);
        } else {
            if (attr == null)
                e.addAttribute("id", newDef);
            else
                attr.setValue(newDef);
        }
        changed = true;
    }
    Boolean newApplyDef = BooleanUtils.isTrue(applyDefault);
    Attribute applyDefaultAttr = e.attribute("applyDefault");
    Boolean oldApplyDef = applyDefaultAttr != null ? Boolean.valueOf(applyDefaultAttr.getValue()) : false;
    if (!Objects.equals(oldApplyDef, newApplyDef)) {
        if (applyDefaultAttr != null) {
            applyDefaultAttr.setValue(newApplyDef.toString());
        } else {
            e.addAttribute("applyDefault", newApplyDef.toString());
        }
        changed = true;
    }

    if (groupBoxExpandedChanged) {
        Element groupBoxExpandedEl = element.element("groupBoxExpanded");
        if (groupBoxExpandedEl == null)
            groupBoxExpandedEl = element.addElement("groupBoxExpanded");

        Boolean oldGroupBoxExpandedValue =
                groupBoxExpandedEl.getText().isEmpty() ? Boolean.TRUE : Boolean.valueOf(groupBoxExpandedEl.getText());

        Boolean newGroupBoxExpandedValue = groupBoxLayout.isExpanded();
        if (!Objects.equals(oldGroupBoxExpandedValue, newGroupBoxExpandedValue)) {
            groupBoxExpandedEl.setText(newGroupBoxExpandedValue.toString());
            changed = true;
        }
    }

    if (isMaxResultsLayoutVisible()) {
        if (maxResultValueChanged) {
            Element maxResultsEl = element.element("maxResults");
            if (maxResultsEl == null) {
                maxResultsEl = element.addElement("maxResults");
            }

            Integer newMaxResultsValue = maxResultsField.getValue();
            if (newMaxResultsValue != null) {
                maxResultsEl.setText(newMaxResultsValue.toString());
                changed = true;
            }
        }
    }

    return changed;
}
 
Example 13
Source File: UserSettingServiceBean.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public void copySettings(User fromUser, User toUser) {
    MetaClass metaClass = metadata.getClassNN(UserSetting.class);

    if (!security.isEntityOpPermitted(metaClass, EntityOp.CREATE)) {
        throw new AccessDeniedException(PermissionType.ENTITY_OP, metaClass.getName());
    }

    Map<UUID, Presentation> presentationsMap = copyPresentations(fromUser, toUser);
    copyUserFolders(fromUser, toUser, presentationsMap);
    Map<UUID, FilterEntity> filtersMap = copyFilters(fromUser, toUser);

    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();

        Query deleteSettingsQuery = em.createQuery("delete from sec$UserSetting s where s.user.id = ?1");
        deleteSettingsQuery.setParameter(1, toUser.getId());
        deleteSettingsQuery.executeUpdate();
        tx.commitRetaining();
        em = persistence.getEntityManager();

        TypedQuery<UserSetting> q = em.createQuery("select s from sec$UserSetting s where s.user.id = ?1", UserSetting.class);
        q.setParameter(1, fromUser.getId());
        List<UserSetting> fromUserSettings = q.getResultList();

        for (UserSetting currSetting : fromUserSettings) {
            UserSetting newSetting = metadata.create(UserSetting.class);
            newSetting.setUser(toUser);
            newSetting.setClientType(currSetting.getClientType());
            newSetting.setName(currSetting.getName());

            try {
                Document doc = dom4JTools.readDocument(currSetting.getValue());

                List<Element> components = doc.getRootElement().element("components").elements("component");
                for (Element component : components) {
                    Attribute presentationAttr = component.attribute("presentation");
                    if (presentationAttr != null) {
                        UUID presentationId = UuidProvider.fromString(presentationAttr.getValue());
                        Presentation newPresentation = presentationsMap.get(presentationId);
                        if (newPresentation != null) {
                            presentationAttr.setValue(newPresentation.getId().toString());
                        }
                    }
                    Element defaultFilterEl = component.element("defaultFilter");
                    if (defaultFilterEl != null) {
                        Attribute idAttr = defaultFilterEl.attribute("id");
                        if (idAttr != null) {
                            UUID filterId = UuidProvider.fromString(idAttr.getValue());
                            FilterEntity newFilter = filtersMap.get(filterId);
                            if (newFilter != null) {
                                idAttr.setValue(newFilter.getId().toString());
                            }
                        }
                    }
                }

                newSetting.setValue(dom4JTools.writeDocument(doc, true));
            } catch (Exception e) {
                newSetting.setValue(currSetting.getValue());
            }
            em.persist(newSetting);
        }

        tx.commit();
    }
}
 
Example 14
Source File: JUnitReportGenerator.java    From gocd with Apache License 2.0 4 votes vote down vote up
private static void setAttr(int i, Element test, final String attr) {
    Attribute classname = test.attribute(attr);
    classname.setValue(classname.getValue() + i);
}