Example usage for org.w3c.dom Element hasAttribute

List of usage examples for org.w3c.dom Element hasAttribute

Introduction

In this page you can find the example usage for org.w3c.dom Element hasAttribute.

Prototype

public boolean hasAttribute(String name);

Source Link

Document

Returns true when an attribute with a given name is specified on this element or has a default value, false otherwise.

Usage

From source file:org.wso2.developerstudio.eclipse.esb.mediators.impl.XSLTMediatorImpl.java

/**
 * {@inheritDoc}/*from   ww w  .  j a va  2 s.  c  o m*/
 */
protected void doLoad(Element self) throws Exception {
    switch (getCurrentEsbVersion()) {
    case ESB301:
        getXsltKey().load(self);
        getSourceXPath().load(self);

        // Properties.
        loadObjects(self, "property", XSLTProperty.class, new ObjectHandler<XSLTProperty>() {
            public void handle(XSLTProperty object) {
                getProperties().add(object);
            }
        });

        // Features.
        loadObjects(self, "feature", XSLTFeature.class, new ObjectHandler<XSLTFeature>() {
            public void handle(XSLTFeature object) {
                getFeatures().add(object);
            }
        });

        // Resources.
        loadObjects(self, "resource", XSLTResource.class, new ObjectHandler<XSLTResource>() {
            public void handle(XSLTResource object) {
                getResources().add(object);
            }
        });
        break;
    case ESB400:
        getSourceXPath().load(self);

        // load XSLT key
        if (self.hasAttribute("key")) {
            String xsltKeyValue = self.getAttribute("key");
            if (xsltKeyValue == null) {
                xsltKeyValue = "";
            }
            xsltKeyValue = xsltKeyValue.trim();
            if (xsltKeyValue.startsWith("{") && xsltKeyValue.endsWith("}")) {
                setXsltSchemaKeyType(getXsltSchemaKeyType().DYNAMIC);
                xsltKeyValue = xsltKeyValue.substring(1, xsltKeyValue.length() - 2);
                getXsltDynamicSchemaKey().setPropertyValue(xsltKeyValue);
            } else {
                setXsltSchemaKeyType(getXsltSchemaKeyType().STATIC);
                getXsltStaticSchemaKey().setKeyValue(xsltKeyValue);
            }
        } else {
            setXsltSchemaKeyType(getXsltSchemaKeyType().STATIC);
        }

        // Properties.
        loadObjects(self, "property", XSLTProperty.class, new ObjectHandler<XSLTProperty>() {
            public void handle(XSLTProperty object) {
                getProperties().add(object);
            }
        });

        // Features.
        loadObjects(self, "feature", XSLTFeature.class, new ObjectHandler<XSLTFeature>() {
            public void handle(XSLTFeature object) {
                getFeatures().add(object);
            }
        });

        // Resources.
        loadObjects(self, "resource", XSLTResource.class, new ObjectHandler<XSLTResource>() {
            public void handle(XSLTResource object) {
                getResources().add(object);
            }
        });
        break;
    }
    super.doLoad(self);
}

From source file:org.xwiki.filter.xml.internal.parser.DefaultXMLParser.java

private Object unserializeParameter(Type type, Element element) throws ClassNotFoundException {
    if (element.hasAttribute(this.configuration.getAttributeParameterType())) {
        String typeString = element.getAttribute(this.configuration.getAttributeParameterType());
        return this.parameterManager.unSerialize(
                Class.forName(typeString, true, Thread.currentThread().getContextClassLoader()), element);
    }/*from  w w  w . jav  a  2  s.  c  o m*/

    return this.parameterManager.unSerialize(type, element);
}

From source file:org.xwiki.platform.patchservice.impl.PositionImpl.java

/**
 * {@inheritDoc}/*  w  w  w  .  j  a va2 s .  co  m*/
 */
public void fromXml(Element e) throws XWikiException {
    this.row = Integer.parseInt(e.getAttribute(ROW_ATTRIBUTE_NAME));
    this.column = Integer.parseInt(e.getAttribute(COLUMN_ATTRIBUTE_NAME));
    if (e.hasAttribute(BEFORE_ATTRIBUTE_NAME)) {
        this.before = e.getAttribute(BEFORE_ATTRIBUTE_NAME);
    }
    if (e.hasAttribute(AFTER_ATTRIBUTE_NAME)) {
        this.after = e.getAttribute(AFTER_ATTRIBUTE_NAME);
    }
    if (e.hasAttribute(SPAN_ATTRIBUTE_NAME)) {
        this.span = Integer.parseInt(e.getAttribute(SPAN_ATTRIBUTE_NAME));
    }
}

From source file:tectonicus.BlockRegistryParser.java

private SubTexture parseTexture(Element element, String attribName, SubTexture defaultTex) {
    if (!element.hasAttribute(attribName))
        return defaultTex;

    String texName = element.getAttribute(attribName);
    SubTexture result = texturePack.findTexture(texName);

    if (result == null)
        return defaultTex;

    return result;
}

From source file:tectonicus.BlockRegistryParser.java

private Color parseColor(Element element, String attribName, Color defaultColor) {
    if (!element.hasAttribute(attribName))
        return defaultColor;

    String colorName = element.getAttribute(attribName);
    Color result = parseHtmlColor(colorName);

    if (result == null)
        return defaultColor;

    return result;
}

From source file:transtool.xmlTools.GatherItems.java

/**
 *
 * @param data// ww  w .  ja  v  a 2  s  .c o  m
 * @param doc
 */
void createQuizItem(Element data, Document doc) {
    QuizItem quiz = new QuizItem();
    quiz.setSavePath(savePath);
    quiz.setBrainhoneyPath(brainhoneyPath);
    quiz.setParent(data.getElementsByTagName("parent").item(0).getTextContent());
    if (data.getElementsByTagName("title").getLength() != 0) {
        quiz.setName(data.getElementsByTagName("title").item(0).getTextContent());
    }
    quiz.setLocation(data.getElementsByTagName("href").item(0).getTextContent());
    if (data.getElementsByTagName("gradable").getLength() > 0) {
        quiz.setGradeable(data.getElementsByTagName("gradable").item(0).getTextContent());
        quiz.setWeight(data.getElementsByTagName("weight").item(0).getTextContent());
        quiz.setCategory(data.getElementsByTagName("category").item(0).getTextContent());
    } else {
        quiz.setGradeable("false");
    }

    NodeList attemptLimit = data.getElementsByTagName("attemptlimit");
    if (attemptLimit.getLength() > 0) {
        quiz.setAttemptLimit(data.getElementsByTagName("attemptlimit").item(0).getTextContent());
    }

    NodeList question = data.getElementsByTagName("question");

    ArrayList<BrainhoneyContents> quizQuestions = new ArrayList<>();

    for (int j = 0; j < question.getLength(); j++) {

        BrainhoneyContents quizQuestion = new BrainhoneyContents();
        Element quizElement = (Element) question.item(j);
        if (quizElement.hasAttribute("id")) {
            if (quizElement.getAttribute("id").length() > 5) {
                quizQuestion.setQuestionID(quizElement.getAttribute("id"));
                quizQuestions.add(quizQuestion);
            }
        }
    }

    quiz.setItemID(Integer.toString(id));
    quiz.setIdent(Integer.toString(identifier));

    NodeList questions = doc.getElementsByTagName("question");

    for (int j = 0; j < questions.getLength(); j++) {
        Element bQuestion = (Element) questions.item(j);
        if (bQuestion.hasAttribute("questionid")) {
            for (BrainhoneyContents quizQuestion : quizQuestions) {
                if (quizQuestion.getQuestionID().equals(bQuestion.getAttribute("questionid"))) {
                    quizQuestion.setDidFill(true);
                    quizQuestion.setBody(bQuestion.getElementsByTagName("body").item(0).getTextContent());
                    quizQuestion.setScore(bQuestion.getAttribute("score"));
                    quizQuestion.setInteractionType(bQuestion.getElementsByTagName("interaction").item(0)
                            .getAttributes().getNamedItem("type").getTextContent());
                    quizQuestion.setPartial(bQuestion.getAttribute("partial"));

                    if (bQuestion.getElementsByTagName("value").getLength() > 0) {
                        NodeList values;
                        values = bQuestion.getElementsByTagName("value");
                        ArrayList<String> value = new ArrayList<>();
                        for (int k = 0; k < values.getLength(); k++) {
                            value.add(values.item(k).getTextContent());
                        }
                        quizQuestion.setRightAnswer(value);

                    } else if (quizQuestion.getInteractionType().equals("match")) {
                        NodeList answers;
                        answers = bQuestion.getElementsByTagName("answer");
                        ArrayList<String> answer = new ArrayList<>();
                        for (int k = 0; k < answers.getLength(); k++) {
                            answer.add(answers.item(k).getTextContent());
                        }
                        quizQuestion.setRightAnswer(answer);
                    }

                    if (bQuestion.getElementsByTagName("body").getLength() > 1) {
                        NodeList bodies = bQuestion.getElementsByTagName("body");
                        ArrayList<String> bText = new ArrayList<>();
                        for (int k = 1; k < bodies.getLength(); k++) {
                            Element body = (Element) bodies.item(k);
                            bText.add(body.getTextContent());
                        }
                        quizQuestion.setqChoice(bText);
                    }
                }
            }
        }
    }

    quiz.setItemQuizFeed(itemID, quizID);
    quiz.setBrainhoney(quizQuestions);

    items.add(quiz);
    quizItem.add(quiz);

    identifier++;
    id++;
}

From source file:uk.ac.tgac.conan.process.asm.KmerRange.java

/**
 * Creates a kmer range object from an Xml Config element.  If there's a list attribute then use that.  If not then
 * we assume a range has been specified, and we generate a list from those attributes.
 * @param ele/*from w w  w .j a v  a  2s .  c om*/
 */
public KmerRange(Element ele, int defaultMin, int defaultMax, int defaultStep) {

    if (ele.hasAttribute(KEY_ATTR_LIST)) {
        this.setFromString(XmlHelper.getTextValue(ele, KEY_ATTR_LIST));
    } else {

        String step = XmlHelper.getTextValue(ele, KEY_ATTR_STEP).toUpperCase();

        int min = ele.hasAttribute(KEY_ATTR_K_MIN) ? XmlHelper.getIntValue(ele, KEY_ATTR_K_MIN) : defaultMin;

        int max = ele.hasAttribute(KEY_ATTR_K_MAX) ? XmlHelper.getIntValue(ele, KEY_ATTR_K_MAX) : defaultMax;

        int stepSize = ele.hasAttribute(KEY_ATTR_STEP)
                ? StringUtils.isNumeric(step) ? Integer.parseInt(step) : StepSize.valueOf(step).getStep()
                : defaultStep;

        this.setFromProperties(min, max, stepSize);
    }
}

From source file:uk.ac.tgac.rampart.stage.analyse.asm.AnalyseAssembliesArgs.java

public AnalyseAssembliesArgs(AnalyseAssembliesParams params, Element element, File analyseReadsDir,
        File outputDir, Organism organism, String jobPrefix, boolean doingReadKmerAnalysis) throws IOException {

    this(params);

    // Check there's nothing
    if (!XmlHelper.validate(element, new String[] {}, new String[] { KEY_ATTR_PARALLEL, },
            new String[] { KEY_ELEM_TOOL }, new String[0])) {
        throw new IOException("Found unrecognised element or attribute in \"analyse_mass\"");
    }//from  w ww .  ja  v a 2s .  com

    this.analyseReadsDir = analyseReadsDir;
    this.outputDir = outputDir;
    this.organism = organism;
    this.jobPrefix = jobPrefix;

    this.runParallel = element.hasAttribute(KEY_ATTR_PARALLEL)
            ? XmlHelper.getBooleanValue(element, KEY_ATTR_PARALLEL)
            : DEFAULT_RUN_PARALLEL;

    // All libraries
    NodeList nodes = element.getElementsByTagName(KEY_ELEM_TOOL);
    for (int i = 0; i < nodes.getLength(); i++) {
        this.tools.add(new ToolArgs((Element) nodes.item(i), outputDir, analyseReadsDir, organism, jobPrefix,
                this.runParallel, doingReadKmerAnalysis));
    }

    for (AnalyseAssembliesArgs.ToolArgs requestedService : this.tools) {
        AssemblyAnalyser aa = this.assemblyAnalyserFactory.create(requestedService.getName());
        aa.setArgs(requestedService);
        this.assemblyAnalysers.add(aa);
    }
}

From source file:uk.ac.tgac.rampart.stage.util.CoverageRange.java

/**
 * Create a coverage range from an Xml element
 * @param ele An XML element describing this coverage range
 *///  ww  w .  j  ava2s  . c om
public CoverageRange(Element ele) {

    if (ele.hasAttribute(KEY_ATTR_LIST)) {
        this.setFromString(XmlHelper.getTextValue(ele, KEY_ATTR_LIST));
    } else {
        this.setFromProperties(XmlHelper.getIntValue(ele, KEY_ATTR_CVG_MIN),
                XmlHelper.getIntValue(ele, KEY_ATTR_CVG_MAX),
                StepSize.valueOf(XmlHelper.getTextValue(ele, KEY_ATTR_CVG_STEP).toUpperCase()),
                XmlHelper.getBooleanValue(ele, KEY_ATTR_ALL));

    }
}

From source file:uk.ac.tgac.rampart.stage.util.VariableRange.java

/**
 * Create a coverage range from an Xml element
 * @param ele An XML element describing the variable range
 *///from   ww w.  ja  va  2s. c o m
public VariableRange(Element ele) {

    this();

    if (ele.hasAttribute(KEY_ATTR_NAME)) {
        this.name = XmlHelper.getTextValue(ele, KEY_ATTR_NAME);
    } else {
        throw new IllegalArgumentException(
                "Xml element for variable range does not contain the \"" + KEY_ATTR_NAME + "\" attribute");
    }

    if (ele.hasAttribute(KEY_ATTR_VALUES)) {
        this.setFromString(XmlHelper.getTextValue(ele, KEY_ATTR_VALUES));
    } else {
        throw new IllegalArgumentException(
                "Xml element for variable range does not contain the \"" + KEY_ATTR_VALUES + "\" attribute");
    }
}