Java Code Examples for org.dom4j.Element#remove()

The following examples show how to use org.dom4j.Element#remove() . 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: XMLProperties.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * Removes the given attribute from the XML document.
 *
 * @param name the property name to lookup - ie, "foo.bar"
 * @param attribute the name of the attribute, ie "id"
 * @return the value of the attribute of the given property or {@code null} if
 *      it did not exist.
 */
public String removeAttribute(String name, String attribute) {
    if (name == null || attribute == null) {
        return null;
    }
    String[] propName = parsePropertyName(name);
    // Search for this property by traversing down the XML hierarchy.
    Element element = document.getRootElement();
    for (String child : propName) {
        element = element.element(child);
        if (element == null) {
            // This node doesn't match this part of the property name which
            // indicates this property doesn't exist so return empty array.
            break;
        }
    }
    String result = null;
    if (element != null) {
        // Get the attribute value and then remove the attribute
        Attribute attr = element.attribute(attribute);
        result = attr.getValue();
        element.remove(attr);
    }
    return result;
}
 
Example 2
Source File: XMLTree.java    From mts with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Restore this XMLTree to his original state
 */
public void restore() {
    for (int i = elementsOrder.size() - 1; i >= 0; i--) {
        Element e = elementsOrder.get(i);
        List<Element> list = elementsMap.get(e);
        if (null != list && !list.isEmpty()) {
            // all Elements in this list should have the same parent
            Element parent = list.get(0).getParent();
            if (null != parent) {
                DefaultElementInterface.insertNode((DefaultElement) parent, list.get(0), e);
                for (Node oldChild : list) {
                    parent.remove(oldChild);
                }

                if (1 == list.size() && e == root) {
                    root = elementsOrder.get(0);
                }

            } else {
                root = elementsOrder.get(0);
            }
        }
    }
}
 
Example 3
Source File: XMLProperties.java    From Whack with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes the specified property.
 *
 * @param name the property to delete.
 */
public synchronized void deleteProperty(String name) {
    // Remove property from cache.
    propertyCache.remove(name);

    String[] propName = parsePropertyName(name);
    // Search for this property by traversing down the XML heirarchy.
    Element element = document.getRootElement();
    for (int i = 0; i < propName.length - 1; i++) {
        element = element.element(propName[i]);
        // Can't find the property so return.
        if (element == null) {
            return;
        }
    }
    // Found the correct element to remove, so remove it...
    element.remove(element.element(propName[propName.length - 1]));
    // .. then write to disk.
    saveProperties();

    // Generate event.
    PropertyEventDispatcher.dispatchEvent(name,
            PropertyEventDispatcher.EventType.xml_property_deleted, Collections.emptyMap());
}
 
Example 4
Source File: WebGroupBox.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public boolean saveSettings(Element element) {
    if (!isSettingsEnabled()) {
        return false;
    }

    if (!settingsChanged) {
        return false;
    }

    Element groupBoxElement = element.element("groupBox");
    if (groupBoxElement != null) {
        element.remove(groupBoxElement);
    }
    groupBoxElement = element.addElement("groupBox");
    groupBoxElement.addAttribute("expanded", BooleanUtils.toStringTrueFalse(isExpanded()));
    return true;
}
 
Example 5
Source File: ElementUtil.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Deletes the specified property.</p>
 * <p>You MAY NOT use the atttribute
 * markup (using a ':' in the last element name) with this call.
 * deleteProperty() removes both the containing text, and the element itself along with
 * any attributes associated with that element.</p>
 *
 * @param element the element to delete the property from
 * @param name the property to delete.
 */
public static void deleteProperty(Element element, String name) {
    // Remove property from cache.
    String[] propName = parsePropertyName(name);

    // Search for this property by traversing down the XML heirarchy.
    for (int i = 0; i < propName.length - 1; i++) {
        element = element.element(propName[i]);
        // Can't find the property so return.
        if (element == null) {
            return;
        }
    }
    // Found the correct element to remove, so remove it...
    element.remove(element.element(propName[propName.length - 1]));
}
 
Example 6
Source File: FIBQuestion.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * Build mastery respcondition for FIB in all-banks-must-be-correct mode. Adds one respcondition in which all blanks must be answered correctly. This respcondition
 * uses the mastery feedback.
 * 
 * @param resprocessingXML
 */
private void buildRespconditionFIBSingle(final Element resprocessingXML) {
    final Element correct = resprocessingXML.addElement("respcondition");
    correct.addAttribute("title", "Mastery");
    correct.addAttribute("continue", "Yes");

    final Element conditionvar = correct.addElement("conditionvar");
    final Element and = conditionvar.addElement("and");
    for (final Iterator i = getResponses().iterator(); i.hasNext();) {
        final FIBResponse fib = (FIBResponse) i.next();
        if (fib.getType().equals(FIBResponse.TYPE_BLANK)) {
            final String[] correctFIBs = fib.getCorrectBlank().split(";");
            final Element or = and.addElement("or");
            for (int j = 0; j < correctFIBs.length; j++) {
                final Element varequal = or.addElement("varequal");
                varequal.addAttribute("respident", fib.getIdent());
                varequal.addAttribute("case", fib.getCaseSensitive());
                if (correctFIBs[j].length() > 0) {
                    varequal.addCDATA(correctFIBs[j]);
                }
            }
        }
    }

    final Element setvar = correct.addElement("setvar");
    setvar.addAttribute("varname", "SCORE");
    setvar.addAttribute("action", "Set");
    setvar.setText("" + getSingleCorrectScore());

    // Use mastery feedback
    QTIEditHelperEBL.addFeedbackMastery(correct);

    // remove whole respcondition if empty
    if (and.element("or") == null) {
        resprocessingXML.remove(correct);
    }
}
 
Example 7
Source File: RouteJavaScriptOSGIForESBManager.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
private static void moveNamespaceInChildren(Element treeRoot, Namespace oldNsp, Namespace newNsp) {
    for (Iterator<?> i = treeRoot.elementIterator(); i.hasNext();) {
        Element e = (Element) i.next();
        if (e.getNamespace().equals(oldNsp)) {
            e.setQName(QName.get(e.getName(), newNsp));
            e.remove(oldNsp);
        }
        moveNamespaceInChildren(e, oldNsp, newNsp);
    }
}
 
Example 8
Source File: RouteJavaScriptOSGIForESBManager.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
private static void moveNamespace(Element treeRoot, String oldNspURI, String newNspURI) {
    Namespace oldNsp = treeRoot.getNamespace();
    if (oldNspURI.equals(oldNsp.getURI())) {
        Namespace newNsp = Namespace.get(oldNsp.getPrefix(), newNspURI);
        treeRoot.setQName(QName.get(treeRoot.getName(), newNsp));
        treeRoot.remove(oldNsp);
    }
    moveNamespaceInChildren(treeRoot, oldNspURI, newNspURI);
}
 
Example 9
Source File: ChoiceQuestion.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * Build fail resprocessing: Adjust score to 0 (if multiple correct mode) and set hints, solutions and fail feedback
 * 
 * @param resprocessingXML
 * @param isSingleCorrect
 */
private void buildRespcondition_fail(final Element resprocessingXML, final boolean isSingleCorrect) {
    // build
    final Element respcondition_fail = resprocessingXML.addElement("respcondition");
    respcondition_fail.addAttribute("title", "Fail");
    respcondition_fail.addAttribute("continue", "Yes");
    final Element conditionvar = respcondition_fail.addElement("conditionvar");
    final Element or = conditionvar.addElement("or");

    for (final Iterator i = getResponses().iterator(); i.hasNext();) {
        final ChoiceResponse tmpChoice = (ChoiceResponse) i.next();
        Element varequal;
        // Add this response to the fail case
        // if single correct type and not correct
        // or multi correct and points negative or 0
        if ((isSingleCorrect && !tmpChoice.isCorrect()) || (!isSingleCorrect && tmpChoice.getPoints() <= 0)) {
            varequal = or.addElement("varequal");
            varequal.addAttribute("respident", getIdent());
            varequal.addAttribute("case", "Yes");
            varequal.addText(tmpChoice.getIdent());
        }
    } // for loop

    if (isSingleCorrect) {
        final Element setvar = respcondition_fail.addElement("setvar");
        setvar.addAttribute("varname", "SCORE");
        setvar.addAttribute("action", "Set");
        setvar.addText("0");
    }

    // Use fail feedback, hints and solutions
    QTIEditHelperEBL.addFeedbackFail(respcondition_fail);
    QTIEditHelperEBL.addFeedbackHint(respcondition_fail);
    QTIEditHelperEBL.addFeedbackSolution(respcondition_fail);

    // remove whole respcondition if empty
    if (or.element("varequal") == null) {
        resprocessingXML.remove(respcondition_fail);
    }
}
 
Example 10
Source File: ChoiceQuestion.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * Build fail resprocessing: Adjust score to 0 (if multiple correct mode) and set hints, solutions and fail feedback
 * 
 * @param resprocessingXML
 * @param isSingleCorrect
 */
private void buildRespcondition_fail(final Element resprocessingXML, final boolean isSingleCorrect) {
    // build
    final Element respcondition_fail = resprocessingXML.addElement("respcondition");
    respcondition_fail.addAttribute("title", "Fail");
    respcondition_fail.addAttribute("continue", "Yes");
    final Element conditionvar = respcondition_fail.addElement("conditionvar");
    final Element or = conditionvar.addElement("or");

    for (final Iterator i = getResponses().iterator(); i.hasNext();) {
        final ChoiceResponse tmpChoice = (ChoiceResponse) i.next();
        Element varequal;
        // Add this response to the fail case
        // if single correct type and not correct
        // or multi correct and points negative or 0
        if ((isSingleCorrect && !tmpChoice.isCorrect()) || (!isSingleCorrect && tmpChoice.getPoints() <= 0)) {
            varequal = or.addElement("varequal");
            varequal.addAttribute("respident", getIdent());
            varequal.addAttribute("case", "Yes");
            varequal.addText(tmpChoice.getIdent());
        }
    } // for loop

    if (isSingleCorrect) {
        final Element setvar = respcondition_fail.addElement("setvar");
        setvar.addAttribute("varname", "SCORE");
        setvar.addAttribute("action", "Set");
        setvar.addText("0");
    }

    // Use fail feedback, hints and solutions
    QTIEditHelperEBL.addFeedbackFail(respcondition_fail);
    QTIEditHelperEBL.addFeedbackHint(respcondition_fail);
    QTIEditHelperEBL.addFeedbackSolution(respcondition_fail);

    // remove whole respcondition if empty
    if (or.element("varequal") == null) {
        resprocessingXML.remove(respcondition_fail);
    }
}
 
Example 11
Source File: WebGroupTable.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public boolean saveSettings(Element element) {
    if (!isSettingsEnabled()) {
        return false;
    }

    boolean commonTableSettingsChanged = super.saveSettings(element);
    boolean groupTableSettingsChanged = isGroupTableSettingsChanged(element.element("groupProperties"));

    if (!groupTableSettingsChanged && !commonTableSettingsChanged) {
        return false;
    }

    if (groupTableSettingsChanged) {

        // add "column" if there is no such element
        if (element.element("columns") == null) {
            Element columnsElem = element.addElement("columns");
            saveCommonTableColumnSettings(columnsElem);
        }

        Element groupPropertiesElement = element.element("groupProperties");
        if (groupPropertiesElement != null) {
            element.remove(groupPropertiesElement);
        }

        groupPropertiesElement = element.addElement("groupProperties");

        for (Object groupProperty : component.getGroupProperties()) {
            Column<E> column = getColumn(groupProperty.toString());

            if (getNotCollapsedColumns().contains(column)) {
                Element groupPropertyElement = groupPropertiesElement.addElement("property");
                groupPropertyElement.addAttribute("id", groupProperty.toString());
            }
        }
    }

    return true;
}
 
Example 12
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 13
Source File: WebAbstractDataGrid.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public boolean saveSettings(Element element) {
    if (!isSettingsEnabled()) {
        return false;
    }

    Element columnsElem = element.element("columns");

    String sortColumnId = null;
    String sortDirection = null;

    if (columnsElem != null) {
        sortColumnId = columnsElem.attributeValue("sortColumnId");
        sortDirection = columnsElem.attributeValue("sortDirection");
    }

    boolean commonSettingsChanged = isCommonDataGridSettingsChanged(columnsElem);
    boolean sortChanged = isSortPropertySettingsChanged(sortColumnId, sortDirection);

    boolean settingsChanged = commonSettingsChanged || sortChanged;

    if (settingsChanged) {
        if (columnsElem != null) {
            element.remove(columnsElem);
        }
        columnsElem = element.addElement("columns");

        List<Column<E>> visibleColumns = getVisibleColumns();
        for (Column<E> column : visibleColumns) {
            Element colElem = columnsElem.addElement("columns");
            colElem.addAttribute("id", column.toString());

            double width = column.getWidth();
            if (width > -1) {
                colElem.addAttribute("width", String.valueOf(width));
            }

            colElem.addAttribute("collapsed", Boolean.toString(column.isCollapsed()));
        }

        List<GridSortOrder<E>> sortOrders = component.getSortOrder();
        if (!sortOrders.isEmpty()) {
            GridSortOrder<E> sortOrder = sortOrders.get(0);

            columnsElem.addAttribute("sortColumnId", sortOrder.getSorted().getId());
            columnsElem.addAttribute("sortDirection", sortOrder.getDirection().toString());
        }
    }

    return settingsChanged;
}
 
Example 14
Source File: Simplicity.java    From MesquiteCore with GNU Lesser General Public License v3.0 4 votes vote down vote up
public  void renameSettingsFile(int i, String newName){
	if (!MesquiteInteger.isCombinable(i) || i<0 || i>= InterfaceManager.settingsFiles.size())
		return;
	StringArray s = (StringArray)InterfaceManager.settingsFiles.elementAt(i);
	String path = s.getValue(PATH);
	String settingsXML = s.getValue(XML);
	Element root = XMLUtil.getRootXMLElementFromString("mesquite",settingsXML);
	if (root==null)
		return;
	Element element = root.element("simplicitySettings");
	if (element != null) {
		Element versionElement = element.element("version");
		if (versionElement == null)
			return ;
		else {
			int version = MesquiteInteger.fromString(element.elementText("version"));
			boolean acceptableVersion = version==1;
			if (acceptableVersion) {
				Element name = element.element("name");

				Element settingsFile = DocumentHelper.createElement("mesquite");
				Document doc = DocumentHelper.createDocument(settingsFile);
				Element hidden = DocumentHelper.createElement("simplicitySettings");
				settingsFile.add(hidden);
				XMLUtil.addFilledElement(hidden, "version","1");
				XMLUtil.addFilledElement(hidden, "name",newName);
				Element hp = element.element("hiddenPackages");
				element.remove(hp);
				hidden.add(hp);
				hp = element.element("hiddenMenuItems");
				element.remove(hp);
				hidden.add(hp);
				hp = element.element("hiddenTools");
				element.remove(hp);
				hidden.add(hp);
				s.setName(newName);
				MesquiteFile.putFileContents(path, XMLUtil.getDocumentAsXMLString(doc), false);
			}
		} 
	}
}
 
Example 15
Source File: IQBlockingHandler.java    From Openfire with Apache License 2.0 4 votes vote down vote up
/**
 * Removes a collection of JIDs from the blocklist of the provided user.
 *
 * This method removes the JIDs to the default privacy list. When no default privacy list exists for this user, this
 * method does nothing.
 *
 * @param user       The owner of the blocklist to which JIDs are to be added (cannot be null).
 * @param toUnblocks The JIDs to be removed (can be null, which results in a noop).
 * @return The JIDs that are removed (never null, possibly empty).
 */
protected Set<JID> removeFromBlockList( User user, Collection<JID> toUnblocks )
{
    final Set<JID> result = new HashSet<>();
    if ( toUnblocks == null || toUnblocks.isEmpty() )
    {
        return result;
    }

    Log.debug( "Obtain the default privacy list for '{}'", user.getUsername() );
    PrivacyList defaultPrivacyList = PrivacyListManager.getInstance().getDefaultPrivacyList( user.getUsername() );
    if ( defaultPrivacyList == null )
    {
        return result;
    }

    Log.debug( "Removing {} JIDs as blocked items from list '{}' (belonging to '{}')", toUnblocks.size(), defaultPrivacyList.getName(), user.getUsername() );
    final Element listElement = defaultPrivacyList.asElement();
    final Set<Element> toRemove = new HashSet<>();
    for ( final Element element : listElement.elements( "item" ) )
    {
        final JID jid = new JID( element.attributeValue( "value" ) );
        if ( "jid".equals( element.attributeValue( "type" ) )
            && "deny".equals( element.attributeValue( "action" ) )
            && toUnblocks.contains( jid ) )
        {
            toRemove.add( element );
            result.add( jid );
        }
    }

    if ( !toRemove.isEmpty() )
    {
        for ( final Element remove : toRemove )
        {
            listElement.remove( remove );
        }

        defaultPrivacyList.updateList( listElement );
        PrivacyListProvider.getInstance().updatePrivacyList( user.getUsername(), defaultPrivacyList );
    }

    return result;
}
 
Example 16
Source File: Scenario.java    From mts with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Parse the scenario
 */
private void parse(XMLDocument scenarioDocument) throws Exception {
    //String relativePath = getFilename();

    //XMLDocument scenarioDocument = XMLDocumentCache.getXMLDocument(URIRegistry.MTS_TEST_HOME.resolve(relativePath), URIFactory.newURI("../conf/schemas/scenario.xsd"));

    Element root = scenarioDocument.getDocument().getRootElement();


    /**
     * Check the position of the finally tag
     */
    boolean isFinallyLast = false;
    int finallyInstances = 0;
    List<Element> elements = root.elements();
    for (Element element : elements) {
        isFinallyLast = false;
        if (element.getName().equals("finally")) {
            isFinallyLast = true;
            finallyInstances++;
        }
    }

    if (finallyInstances == 1 && !isFinallyLast) {
        throw new ParsingException("Finally must be the last operation of the scenario.");
    }
    else if (finallyInstances > 1) {
        throw new ParsingException("There must be at most one finally operation.");
    }

    /**
     * Create the finally operations sequence. If there is a finally then the sequence is created and then the finally tag is removed from the scenario. To allow the creation of the scenario
     * operations sequence.
     */
    if (finallyInstances == 1) {
        Element finallyRoot = root.element("finally");
        root.remove(finallyRoot);
        this._operationSequenceFinally = new OperationSequence(finallyRoot, this);
    }

    _operationSequenceScenario = new OperationSequence(root, this);
}
 
Example 17
Source File: XMLProperties.java    From Openfire with Apache License 2.0 4 votes vote down vote up
/**
 * Sets a property to an array of values. Multiple values matching the same property
 * is mapped to an XML file as multiple elements containing each value.
 * For example, using the name "foo.bar.prop", and the value string array containing
 * {"some value", "other value", "last value"} would produce the following XML:
 * <pre>
 * &lt;foo&gt;
 *     &lt;bar&gt;
 *         &lt;prop&gt;some value&lt;/prop&gt;
 *         &lt;prop&gt;other value&lt;/prop&gt;
 *         &lt;prop&gt;last value&lt;/prop&gt;
 *     &lt;/bar&gt;
 * &lt;/foo&gt;
 * </pre>
 *
 * @param name the name of the property.
 * @param values the values for the property (can be empty but not null).
 */
public void setProperties(String name, List<String> values) {
    String[] propName = parsePropertyName(name);
    // Search for this property by traversing down the XML hierarchy,
    // stopping one short.
    Element element = document.getRootElement();
    for (int i = 0; i < propName.length - 1; i++) {
        // If we don't find this part of the property in the XML hierarchy
        // we add it as a new node
        if (element.element(propName[i]) == null) {
            element.addElement(propName[i]);
        }
        element = element.element(propName[i]);
    }
    String childName = propName[propName.length - 1];
    // We found matching property, clear all children.
    List<Element> toRemove = new ArrayList<>();
    Iterator<Element> iter = element.elementIterator(childName);
    while (iter.hasNext()) {
        toRemove.add(iter.next());
    }
    for (iter = toRemove.iterator(); iter.hasNext();) {
        element.remove(iter.next());
    }
    // Add the new children.
    for (String value : values) {
        Element childElement = element.addElement(childName);
        if (value.startsWith("<![CDATA[")) {
            Iterator<Node> it = childElement.nodeIterator();
            while (it.hasNext()) {
                Node node = it.next();
                if (node instanceof CDATA) {
                    childElement.remove(node);
                    break;
                }
            }
            childElement.addCDATA(value.substring(9, value.length()-3));
        }
        else {
            String propValue = value;
            // check to see if the property is marked as encrypted
            if (JiveGlobals.isPropertyEncrypted(name)) {
                propValue = JiveGlobals.getPropertyEncryptor().encrypt(value);
                childElement.addAttribute(ENCRYPTED_ATTRIBUTE, "true");
            }
            childElement.setText(propValue);
        }
    }
    saveProperties();

    // Generate event.
    Map<String, Object> params = new HashMap<>();
    params.put("value", values);
    PropertyEventDispatcher.dispatchEvent(name,
            PropertyEventDispatcher.EventType.xml_property_set, params);
}
 
Example 18
Source File: XMLUtil.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 修改XML文件
 * @param fileName
 * @param newFileName
 * @return
 */
private static Document testModifyXMLFile(String fileName) {
    SAXReader reader = new SAXReader();
    Document document = null;
    try {
        document = reader.read(new File(fileName));
        // 用xpath查找对象
        List<?> list = document.selectNodes("/catalog/journal/@title");
        Iterator<?> itr = list.iterator();
        while (itr.hasNext()) {
            Attribute attribute = (Attribute) itr.next();
            if (attribute.getValue().equals("XML Zone")) {
                attribute.setText("Modi XML");
            }
        }
        // 在journal元素中增加date元素
        list = document.selectNodes("/catalog/journal");
        itr = list.iterator();
        if (itr.hasNext()) {
            Element journalElement = (Element) itr.next();
            Element dateElement = journalElement.addElement("date");
            dateElement.setText("2006-07-10");
            dateElement.addAttribute("type", "Gregorian calendar");
        }
        // 删除title接点
        list = document.selectNodes("/catalog/journal/article");
        itr = list.iterator();
        while (itr.hasNext()) {
            Element articleElement = (Element) itr.next();
            Iterator<Element> iter = articleElement.elementIterator("title");
            while (iter.hasNext()) {
                Element titleElement = (Element) iter.next();
                if (titleElement.getText().equals("Dom4j Create XML Schema")) {
                    articleElement.remove(titleElement);
                }
            }
        }

    } catch (DocumentException e) {
        e.printStackTrace();
    }

    return document;

}
 
Example 19
Source File: IosNativePageSourceHandler.java    From agent with MIT License 4 votes vote down vote up
/**
 * android / ios 复用一套前端inspector组件,将ios的布局转成android格式
 *
 * @param element
 */
@Override
public void handleElement(Element element) {
    if (element == null) {
        return;
    }

    String elementName = element.getName();
    if (StringUtils.isEmpty(elementName)) {
        return;
    }

    if ("AppiumAUT".equals(elementName)) {
        element.setName("hierarchy");
    } else {
        element.setName("node");

        Attribute xAttr = element.attribute("x");
        String startX = xAttr.getValue();
        element.remove(xAttr);

        Attribute yAttr = element.attribute("y");
        String startY = yAttr.getValue();
        element.remove(yAttr);

        Attribute widthAttr = element.attribute("width");
        String width = widthAttr.getValue();
        element.remove(widthAttr);

        Attribute heightAttr = element.attribute("height");
        String height = heightAttr.getValue();
        element.remove(heightAttr);

        Integer endX = Integer.parseInt(startX) + Integer.parseInt(width);
        Integer endY = Integer.parseInt(startY) + Integer.parseInt(height);

        String bounds = String.format("[%s,%s][%d,%d]", startX, startY, endX, endY);
        element.addAttribute("bounds", bounds);

        // 前端el-tree
        // defaultProps: {
        //   children: 'nodes',
        //   label: 'class'
        // }
        element.addAttribute("class", elementName);
    }

    List<Element> elements = element.elements();
    elements.forEach(e -> handleElement(e));
}
 
Example 20
Source File: ChoiceQuestion.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * Build resprocessing for multiple choice item with a single correct answer. Set score to correct value and use mastery feedback.
 * 
 * @param resprocessingXML
 */
private void buildRespconditionMCSingle_mastery(final Element resprocessingXML) {
    final Element respcondition_correct = resprocessingXML.addElement("respcondition");
    respcondition_correct.addAttribute("title", "Mastery");
    respcondition_correct.addAttribute("continue", "Yes");

    final Element conditionvar = respcondition_correct.addElement("conditionvar");
    final Element and = conditionvar.addElement("and");
    final Element not = conditionvar.addElement("not");
    final Element or = not.addElement("or");
    for (final Iterator i = getResponses().iterator(); i.hasNext();) {
        final ChoiceResponse tmpChoice = (ChoiceResponse) i.next();
        Element varequal;
        if (tmpChoice.isCorrect()) { // correct answers
            varequal = and.addElement("varequal");
        } else { // incorrect answers
            varequal = or.addElement("varequal");
        }
        varequal.addAttribute("respident", getIdent());
        varequal.addAttribute("case", "Yes");
        varequal.addText(tmpChoice.getIdent());
    } // for loop

    final Element setvar = respcondition_correct.addElement("setvar");
    setvar.addAttribute("varname", "SCORE");
    setvar.addAttribute("action", "Set");
    setvar.addText("" + getSingleCorrectScore());

    // Use mastery feedback
    QTIEditHelperEBL.addFeedbackMastery(respcondition_correct);

    // remove whole respcondition if empty
    if (or.element("varequal") == null && and.element("varequal") == null) {
        resprocessingXML.remove(respcondition_correct);
    } else {
        // remove any unset <and> and <not> nodes
        if (and.element("varequal") == null) {
            conditionvar.remove(and);
        }
        if (or.element("varequal") == null) {
            conditionvar.remove(not);
        }
    }

}