Example usage for org.dom4j Attribute getValue

List of usage examples for org.dom4j Attribute getValue

Introduction

In this page you can find the example usage for org.dom4j Attribute getValue.

Prototype

String getValue();

Source Link

Document

Returns the value of the attribute.

Usage

From source file:org.mwolff.generator.xml.XMLHelper.java

License:Open Source License

private static void extractClassAttributes(final Element element, ClassStructure classStructure) {

    for (@SuppressWarnings("unchecked")
    final Iterator<Attribute> attributeIterator = element.attributeIterator(); attributeIterator.hasNext();) {

        final Attribute attribute = attributeIterator.next();

        if ("identifier".equals(attribute.getName())) {
            classStructure.setIdentifier(attribute.getValue());
        }/*from www  .  ja v  a2s . c  o m*/

        if ("extends".equals(attribute.getName())) {
            classStructure.setExtendsString(attribute.getValue());
        }

        if ("implements".equals(attribute.getName())) {
            classStructure.setImplementsString(attribute.getValue());
        }

    }
}

From source file:org.mwolff.generator.xml.XMLHelper.java

License:Open Source License

private static void createInstanceVariables(ClassStructure classStructure, Element innerElement) {

    final List<InstanceVariable> variableList = new ArrayList<InstanceVariable>();
    @SuppressWarnings("unchecked")
    final List<Element> instanceVarialbleList = innerElement.elements();

    for (Element instanceVariables : instanceVarialbleList) {

        final InstanceVariable variable = new InstanceVariable();
        variable.setCardinality("none");

        for (@SuppressWarnings("unchecked")
        final Iterator<Attribute> variableIterator = instanceVariables.attributeIterator(); variableIterator
                .hasNext();) {/*from   w w  w.  j a  v  a 2s  .com*/

            final Attribute attribute = variableIterator.next();

            LOG.debug(attribute.getName());

            if ("id".equals(attribute.getName())) {
                variable.setIdentifier(attribute.getValue());
            }

            if ("type".equals(attribute.getName())) {
                variable.setType(attribute.getValue());
            }

            if ("scope".equals(attribute.getName())) {
                variable.setModifier(attribute.getValue());
            }

            if ("cardinality".equals(attribute.getName())) {
                variable.setCardinality(attribute.getValue());
            }
        }

        variableList.add(variable);
        LOG.info("Create new instance variable named " + variable.getIdentifier());
    }
    classStructure.setInstanceVariableList(variableList);
}

From source file:org.neuclear.id.Identity.java

License:LGPL

protected static String extractOrginalUrl(final Element elem) {
    final Attribute origattr = ((Attribute) elem
            .selectSingleNode("//html/head/link[starts-with(@rel,'original')]/@href"));
    final String original = (origattr != null) ? origattr.getValue() : "";
    return original;
}

From source file:org.neuclear.id.verifier.VerifyingReader.java

License:Open Source License

private String extractName(final Element elem) {
    if (elem.getName().equals("html")) {
        Attribute type = (Attribute) elem.selectSingleNode("//html/head/meta[@name='neu:type']/@content");
        if (type != null && type.getValue() != null)
            return type.getValue().toLowerCase();
        return "identity"; //default to identity
    }//from  w ww.  j a va2  s.  co  m
    return elem.getName();
}

From source file:org.nuxeo.ecm.jsf2.migration.parser.ReRenderParser.java

License:Open Source License

/**
 * Create a new attribute with the new name.
 *
 * @param node//from  w  ww  .  j a v  a  2s .co  m
 * @return
 */
protected Attribute createNewAttribute(Attribute originalAttribute) {
    String newName = rule.getNewValue();
    String newValue = generateNewValue(originalAttribute.getValue());
    return new DefaultAttribute(newName, newValue);
}

From source file:org.nuxeo.ecm.platform.template.XMLSerializer.java

License:Open Source License

public static List<TemplateInput> readFromXml(String xml) throws Exception {

    List<TemplateInput> result = new ArrayList<TemplateInput>();

    Document xmlDoc = DocumentHelper.parseText(xml);

    List nodes = xmlDoc.getRootElement().elements(fieldTag);

    for (Object node : nodes) {

        DefaultElement elem = (DefaultElement) node;
        Attribute name = elem.attribute("name");
        TemplateInput param = new TemplateInput(name.getValue());

        InputType type = InputType.StringValue;

        if (elem.attribute("type") != null) {
            type = InputType.getByValue(elem.attribute("type").getValue());
            param.setType(type);//from w  w  w. j av a 2 s. c om
        }

        String strValue = elem.attributeValue("value");
        if (InputType.StringValue.equals(type)) {
            param.setStringValue(strValue);
        } else if (InputType.DateValue.equals(type)) {
            param.setDateValue(dateFormat.parse(strValue));
        } else if (InputType.BooleanValue.equals(type)) {
            param.setBooleanValue(new Boolean(strValue));
        } else {
            param.setSource(elem.attributeValue("source"));
        }

        if (elem.attribute("readonly") != null) {
            param.setReadOnly(Boolean.parseBoolean(elem.attributeValue("readonly")));
        }

        if (elem.attribute("autoloop") != null) {
            param.setAutoLoop(Boolean.parseBoolean(elem.attributeValue("autoloop")));
        }

        param.setDesciption(elem.getText());

        result.add(param);
    }

    return result;
}

From source file:org.nuxeo.template.XMLSerializer.java

License:Open Source License

public static List<TemplateInput> readFromXml(String xml) throws Exception {

    List<TemplateInput> result = new ArrayList<TemplateInput>();

    Document xmlDoc = DocumentHelper.parseText(xml);

    @SuppressWarnings("rawtypes")
    List nodes = xmlDoc.getRootElement().elements(fieldTag);

    for (Object node : nodes) {

        DefaultElement elem = (DefaultElement) node;
        Attribute name = elem.attribute("name");
        TemplateInput param = new TemplateInput(name.getValue());

        InputType type = InputType.StringValue;

        if (elem.attribute("type") != null) {
            type = InputType.getByValue(elem.attribute("type").getValue());
            param.setType(type);/*from ww  w. j  av a2 s  .  c  o  m*/
        }

        String strValue = elem.attributeValue("value");
        if (InputType.StringValue.equals(type)) {
            param.setStringValue(strValue);
        } else if (InputType.DateValue.equals(type)) {
            param.setDateValue(dateFormat.parse(strValue));
        } else if (InputType.BooleanValue.equals(type)) {
            param.setBooleanValue(new Boolean(strValue));
        } else {
            param.setSource(elem.attributeValue("source"));
        }

        if (elem.attribute("readonly") != null) {
            param.setReadOnly(Boolean.parseBoolean(elem.attributeValue("readonly")));
        }

        if (elem.attribute("autoloop") != null) {
            param.setAutoLoop(Boolean.parseBoolean(elem.attributeValue("autoloop")));
        }

        param.setDesciption(elem.getText());

        result.add(param);
    }

    return result;
}

From source file:org.olat.ims.qti.editor.beecom.parser.AssessmentParser.java

License:Apache License

/**
 * @see org.olat.ims.qti.editor.beecom.IParser#parse(org.dom4j.Element)
 *///  w w w .j a  v a 2s . com
@Override
public Object parse(final Element element) {
    // assert element.getName().equalsIgnoreCase("assessment");
    final Assessment assessment = new Assessment();

    // attributes

    Attribute attr = element.attribute("ident");
    if (attr != null) {
        assessment.setIdent(attr.getValue());
    }
    attr = element.attribute("title");
    if (attr != null) {
        assessment.setTitle(attr.getValue());
    }

    // elements

    // DURATION
    final QTIObject duration = (QTIObject) parserManager.parse(element.element("duration"));
    assessment.setDuration(duration);

    // ASSESSMENTCONTROL
    final List assessmentcontrolsXML = element.elements("assessmentcontrol");
    final List assessmentcontrols = new ArrayList();
    for (final Iterator i = assessmentcontrolsXML.iterator(); i.hasNext();) {
        assessmentcontrols.add(parserManager.parse((Element) i.next()));
        assessment.setInheritControls(true);
    }
    if (assessmentcontrols.size() == 0) {
        assessmentcontrols.add(new Control());
        assessment.setInheritControls(false);
    }
    assessment.setAssessmentcontrols(assessmentcontrols);

    // OUTCOMES PROCESSING
    final OutcomesProcessing outcomesProcessing = (OutcomesProcessing) parserManager
            .parse(element.element("outcomes_processing"));
    if (outcomesProcessing != null) {
        assessment.setOutcomes_processing(outcomesProcessing);
    }

    // SECTIONS
    final List sectionsXML = element.elements("section");
    final List sections = new ArrayList();
    for (final Iterator i = sectionsXML.iterator(); i.hasNext();) {
        sections.add(parserManager.parse((Element) i.next()));
    }
    assessment.setSections(sections);

    // ITEMS
    final List itemsXML = element.elements("item");
    final List items = new ArrayList();
    for (final Iterator i = itemsXML.iterator(); i.hasNext();) {
        items.add(parserManager.parse((Element) i.next()));
    }
    assessment.setItems(items);

    // OBJECTIVES
    final Element mattext = (Element) element.selectSingleNode("./objectives/material/mattext");
    if (mattext != null) {
        assessment.setObjectives(mattext.getTextTrim());
    }

    // METADATA
    final Metadata metadata = (Metadata) parserManager.parse(element.element("qtimetadata"));
    if (metadata != null) {
        assessment.setMetadata(metadata);
    }

    return assessment;
}

From source file:org.olat.ims.qti.editor.beecom.parser.FeedbackParser.java

License:Apache License

/**
 * @see org.olat.ims.qti.editor.beecom.objects.IParser#parse(org.dom4j.Element)
 *//*from w ww. ja  va2s. c  o  m*/
@Override
public Object parse(final Element element) {
    // assert element.getName().equalsIgnoreCase("sectionfeedback")
    // || element.getName().equalsIgnoreCase("itemfeedback")
    // || element.getName().equalsIgnoreCase("assessmentfeedback");

    final List materialsXML = element.selectNodes(".//material");
    if (materialsXML.size() == 0) {
        return null;
    }

    final Feedback feedback = new Feedback();
    // attributes
    Attribute tmp = element.attribute("ident");
    if (tmp != null) {
        feedback.setIdent(tmp.getValue());
    }
    tmp = element.attribute("title");
    if (tmp != null) {
        feedback.setTitle(tmp.getValue());
    }
    tmp = element.attribute("view");
    if (tmp != null) {
        feedback.setView(tmp.getValue());
    }

    // get type
    if (element.element("solution") != null) {
        return null;
    } else if (element.element("hint") != null) {
        return null;
    }

    // parse Material
    // MATERIAL
    final List materials = new ArrayList();
    for (final Iterator i = materialsXML.iterator(); i.hasNext();) {
        materials.add(parserManager.parse((Element) i.next()));
    }
    feedback.setMaterials(materials);
    return feedback;
}

From source file:org.olat.ims.qti.editor.beecom.parser.ItemParser.java

License:Apache License

/**
 * @see org.olat.ims.qti.editor.beecom.parser.IParser#parse(org.dom4j.Element)
 *//*w  w w  . jav  a2s . c  om*/
@Override
public Object parse(final Element element) {
    // assert element.getName().equalsIgnoreCase("item");
    final Item item = new Item();
    Attribute tmp = element.attribute("ident");
    if (tmp != null) {
        item.setIdent(tmp.getValue());
    } else {
        item.setIdent("" + CodeHelper.getRAMUniqueID());
    }

    tmp = element.attribute("title");
    if (tmp != null) {
        item.setTitle(tmp.getValue());
    }

    tmp = element.attribute("label");
    if (tmp != null) {
        item.setLabel(tmp.getValue());
    }

    tmp = element.attribute("maxattempts");
    if (tmp != null) {
        try {
            item.setMaxattempts(Integer.parseInt(tmp.getValue()));
        } catch (final NumberFormatException nfe) {
            item.setMaxattempts(0);
        }
    }

    // if editor can't handle type of item, just keep raw XML
    if (!(item.getIdent().startsWith(ITEM_PREFIX_SCQ) || item.getIdent().startsWith(ITEM_PREFIX_MCQ)
            || item.getIdent().startsWith(ITEM_PREFIX_FIB) || item.getIdent().startsWith(ITEM_PREFIX_ESSAY)
            || item.getIdent().startsWith(ITEM_PREFIX_KPRIM))) {
        item.setRawXML(new QTIXMLWrapper(element));
        return item;
    }

    // exported olat surveys don't have the correct essay prefix. Search
    // for render_fib that contains rows attribute and convert them to essay
    if (item.getIdent().startsWith(ITEM_PREFIX_FIB) && element.selectNodes(".//render_fib[@rows]").size() > 0) {
        item.setIdent(item.getIdent().replaceFirst("FIB", "ESSAY"));
    }

    // DURATION
    final Duration duration = (Duration) parserManager.parse(element.element("duration"));
    item.setDuration(duration);

    // CONTROLS
    final List itemcontrolsXML = element.elements("itemcontrol");
    final List itemcontrols = new ArrayList();
    for (final Iterator i = itemcontrolsXML.iterator(); i.hasNext();) {
        itemcontrols.add(parserManager.parse((Element) i.next()));
    }
    if (itemcontrols.size() == 0) {
        itemcontrols.add(new Control());
    }
    item.setItemcontrols(itemcontrols);

    // OBJECTIVES
    final Element mattext = (Element) element.selectSingleNode("./objectives/material/mattext");
    if (mattext != null) {
        item.setObjectives(mattext.getTextTrim());
    }

    // QUESTIONS
    if (item.getIdent().startsWith(ITEM_PREFIX_SCQ)) {
        item.setQuestion(ChoiceQuestion.getInstance(element));
    } else if (item.getIdent().startsWith(ITEM_PREFIX_MCQ)) {
        item.setQuestion(ChoiceQuestion.getInstance(element));
    } else if (item.getIdent().startsWith(ITEM_PREFIX_FIB)) {
        item.setQuestion(FIBQuestion.getInstance(element));
    } else if (item.getIdent().startsWith(ITEM_PREFIX_ESSAY)) {
        item.setQuestion(EssayQuestion.getInstance(element));
    } else if (item.getIdent().startsWith(ITEM_PREFIX_KPRIM)) {
        item.setQuestion(ChoiceQuestion.getInstance(element));
    }

    // FEEDBACKS
    final List feedbacksXML = element.elements("itemfeedback");
    final List feedbacks = new ArrayList();
    item.setItemfeedbacks(feedbacks);
    final Question question = item.getQuestion();
    for (final Iterator i = feedbacksXML.iterator(); i.hasNext();) {
        final Element el_feedback = (Element) i.next();
        if (el_feedback.element("solution") != null) { // fetch solution
            final Element el_solution = el_feedback.element("solution");
            question.setSolutionText(getMaterialAsString(el_solution));
        } else if (el_feedback.element("hint") != null) { // fetch hint
            final Element el_hint = el_feedback.element("hint");
            question.setHintText(getMaterialAsString(el_hint));
        } else {
            final QTIObject tmpObj = (QTIObject) parserManager.parse(el_feedback);
            if (tmpObj != null) {
                feedbacks.add(tmpObj);
            }
        }
    }

    return item;
}