Java Code Examples for org.jdom.Element#getTextTrim()

The following examples show how to use org.jdom.Element#getTextTrim() . 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: CreoleAnnotationHandler.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Recursively search the given element for JAR entries and add these jars to
 * the GateClassLoader
 * 
 * @param jdomElt
 *          JDOM element representing a creole.xml file
 */
@SuppressWarnings("unchecked")
private void addJarsToClassLoader(GateClassLoader gcl, Element jdomElt)
    throws MalformedURLException {
  if("JAR".equals(jdomElt.getName())) {
    URL url = new URL(plugin.getBaseURL(), jdomElt.getTextTrim());
    try {
      java.io.InputStream s = url.openStream();
      s.close();
      gcl.addURL(url);
    } catch(IOException e) {
      log.debug("Unable to add JAR "
          + url
          + " specified in creole file "
          + " to class loader, hopefully the required classes are already on the classpath.");
    }
  } else {
    for(Element child : (List<Element>)jdomElt.getChildren()) {
      addJarsToClassLoader(gcl, child);
    }
  }
}
 
Example 2
Source File: DAOEGTaskConfiguration.java    From BART with MIT License 6 votes vote down vote up
private OutlierErrorConfiguration extractOutlierErrorConfiguration(Element outlierErrorsTag) {
    OutlierErrorConfiguration outlierErrorConfiguration = new OutlierErrorConfiguration();
    Element tablesElement = getMandatoryElement(outlierErrorsTag, "tables");
    List<Element> tables = getMandatoryElements(tablesElement, "table");
    for (Element table : tables) {
        Attribute tableName = getMandatoryAttribute(table, "name");
        Element attributesElement = getMandatoryElement(table, "attributes");
        List<Element> attributeElements = getMandatoryElements(attributesElement, "attribute");
        for (Element attribute : attributeElements) {
            Attribute percentageAttribute = getMandatoryAttribute(attribute, "percentage");
            Attribute detectableAttribute = getMandatoryAttribute(attribute, "detectable");
            String attributeName = attribute.getTextTrim();
            double percentage = Double.parseDouble(percentageAttribute.getValue().trim());
            boolean detectable = Boolean.parseBoolean(detectableAttribute.getValue().trim());
            outlierErrorConfiguration.addAttributes(tableName.getValue().trim(), attributeName, percentage, detectable);
        }
    }
    return outlierErrorConfiguration;
}
 
Example 3
Source File: PrintHandler.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public void setResourceMetadataXml(Element the_md) {
    // version 1 and higher are different formats, hence a slightly weird test
    Iterator mdroles = the_md.getDescendants(new ElementFilter("intendedEndUserRole", ns.lom_ns()));
    if (mdroles != null) {
    while (mdroles.hasNext()) {
 Element role = (Element)mdroles.next();
     Iterator values = role.getDescendants(new ElementFilter("value", ns.lom_ns()));
     if (values != null) {
  while (values.hasNext()) {
 if (roles == null)
     roles = new HashSet<String>();
      Element value = (Element)values.next();
      String roleName = value.getTextTrim();
      roles.add(roleName);
  }
     }
 }
    }

    if (log.isDebugEnabled())
 log.debug("resource md xml: "+the_md); 
}
 
Example 4
Source File: PrintHandler.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public void setResourceMetadataXml(Element the_md) {
    // version 1 and higher are different formats, hence a slightly weird test
    Iterator mdroles = the_md.getDescendants(new ElementFilter("intendedEndUserRole", ns.lom_ns()));
    if (mdroles != null) {
    while (mdroles.hasNext()) {
 Element role = (Element)mdroles.next();
     Iterator values = role.getDescendants(new ElementFilter("value", ns.lom_ns()));
     if (values != null) {
  while (values.hasNext()) {
 if (roles == null)
     roles = new HashSet<String>();
      Element value = (Element)values.next();
      String roleName = value.getTextTrim();
      roles.add(roleName);
  }
     }
 }
    }

    if (log.isDebugEnabled())
 log.debug("resource md xml: "+the_md); 
}
 
Example 5
Source File: XmlHelper.java    From rice with Educational Community License v2.0 6 votes vote down vote up
private static void trimSAXElement(Element element) throws SAXException, IOException, ParserConfigurationException {

        if (!element.getChildren().isEmpty()) {
            for (Object child : element.getChildren()) {
                if (child != null) {
                    trimSAXElement((Element) child);
                }
            }
        } else {
            String text = element.getTextTrim();
            if (StringUtils.isEmpty(text)) {
                text = "";
            }
            element.setText(text);
        }
    }
 
Example 6
Source File: JDOMUtils.java    From geowave with Apache License 2.0 6 votes vote down vote up
public static String getProp(
    final Element e,
    final String childName,
    final Logger logger,
    final String errorMessage) {
  final Element childEl = e.getChild(childName);
  if (childEl == null) {
    logger.error(errorMessage);
    return null;
  }

  final String val = childEl.getTextTrim();

  if (val == null) {
    logger.error(errorMessage);
    return null;
  }

  return val;
}
 
Example 7
Source File: RunConfigurationFlagsState.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void readExternal(Element element) {
  ImmutableList.Builder<String> flagsBuilder = ImmutableList.builder();
  for (Element e : element.getChildren(tag)) {
    String flag = e.getTextTrim();
    if (flag != null && !flag.isEmpty()) {
      flagsBuilder.add(flag);
    }
  }
  flags = flagsBuilder.build();
}
 
Example 8
Source File: DiscreteCPD.java    From microrts with GNU General Public License v3.0 5 votes vote down vote up
public DiscreteCPD(Element e) throws Exception {    
    if (!e.getName().equals("DiscreteCPD")) throw new Exception("Head tag is not 'DiscreteCPD'!");
    Xvalues = Integer.parseInt(e.getAttributeValue("Xvalues"));
    Yvalues = Integer.parseInt(e.getAttributeValue("Yvalues"));
    counts = new int[Xvalues][Yvalues];
    String text = e.getTextTrim();
    String tokens[] = text.split(" |\n");
    for(int k = 0,i = 0;i<Xvalues;i++) {
        for(int j = 0;j<Yvalues;j++,k++) {
            while(tokens[k].equals("")) k++;
            counts[i][j] = Integer.parseInt(tokens[k]);
        }
    }
}
 
Example 9
Source File: Polygon.java    From beast-mcmc with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Polygon(Element e) {

        boolean closed = Boolean.valueOf(e.getAttributeValue(CLOSED));

        List children = e.getChildren();
        for (int a = 0; a < children.size(); a++) {
            Element childElement = (Element)children.get(a);
            if (childElement.getName().equals(COORDINATES)) {

            String value = childElement.getTextTrim();
            StringTokenizer st1 = new StringTokenizer(value, "\n");
            int count = st1.countTokens();  //System.out.println(count);

            x = new double[count];
            y = new double[count];
            z = new double[count];
            // assumes closed!
            length = x.length - 1;

            for (int i = 0; i < count; i++) {
                String line = st1.nextToken();
                StringTokenizer st2 = new StringTokenizer(line, ",");
                if (st2.countTokens() != 3)
                    throw new IllegalArgumentException("All KML coordinates must contain (X,Y,Z) values.  Three dimensions not found in element '" + line + "'");
                x[i] = Double.valueOf(st2.nextToken());
                y[i] = Double.valueOf(st2.nextToken());
                z[i] = Double.valueOf(st2.nextToken());
                }
            //gets the density value
            //String densityValue = e.getChild(DENSITY).getTextTrim();
            //d = Double.valueOf(densityValue);
            }
        }
        planarInZ = isPlanarInZ();
    }
 
Example 10
Source File: NewPolygon2D.java    From beast-mcmc with GNU Lesser General Public License v2.1 5 votes vote down vote up
public NewPolygon2D(Element e) {

        List<Element> children = e.getChildren();
//        for (int a = 0; a < children.size(); a++) {
        for (Element childElement : children) {
//            Element childElement = (Element) children.get(a);
            if (childElement.getName().equals(KMLCoordinates.COORDINATES)) {

                String value = childElement.getTextTrim();
                StringTokenizer st1 = new StringTokenizer(value, "\n");
                int count = st1.countTokens();  //System.out.println(count);

//                point2Ds = new LinkedList<Point2D>();
                this.path = new GeneralPath();

                for (int i = 0; i < count; i++) {
                    String line = st1.nextToken();
                    StringTokenizer st2 = new StringTokenizer(line, ",");
                    if (st2.countTokens() != 3)
                        throw new IllegalArgumentException("All KML coordinates must contain (X,Y,Z) values.  Three dimensions not found in element '" + line + "'");
                    final float x = Float.valueOf(st2.nextToken());
                    final float y = Float.valueOf(st2.nextToken());
                    if (i == 0) {
                        path.moveTo(x, y);
                    } else {
                        path.lineTo(x, y);
                    }
//                    point2Ds.add(new Point2D.Double(x, y));
                }
//                length = point2Ds.size() - 1;
                break;

            }
        }
    }
 
Example 11
Source File: AbstractPolygon2D.java    From beast-mcmc with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void parseCoordinates(Element element) {

        if (element.getName().equalsIgnoreCase(KMLCoordinates.COORDINATES)) {
            String value = element.getTextTrim();
            StringTokenizer st1 = new StringTokenizer(value, KMLCoordinates.POINT_SEPARATORS);
            int count = st1.countTokens();
//            System.out.println(count + " tokens");

            point2Ds = new ArrayList<Point2D>(count);
            for (int i = 0; i < count; i++) {
                String line = st1.nextToken();
                StringTokenizer st2 = new StringTokenizer(line, KMLCoordinates.SEPARATOR);
                if (st2.countTokens() < 2 || st2.countTokens() > 3)
                    throw new IllegalArgumentException("All KML coordinates must contain (X,Y) or (X,Y,Z) values.  Error in element '" + line + "'");
                final double x = Double.valueOf(st2.nextToken());
                final double y = Double.valueOf(st2.nextToken());
                point2Ds.add(new Point2D.Double(x, y));
            }
            convertPointsToArrays();
            length = point2Ds.size() - 1;
        } else {
            for (Object child : element.getChildren()) {

                if (child instanceof Element) {
                    parseCoordinates((Element) child);
                }
            }
        }
    }
 
Example 12
Source File: BeastImporter.java    From beast-mcmc with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Taxon readTaxon(TaxonList primaryTaxa, Element e) throws Importer.ImportException {

        String id = e.getAttributeValue(XMLParser.ID);

        Taxon taxon = null;

        if (id != null) {
            taxon = new Taxon(id);

            List children = e.getChildren();
            for(Object aChildren : children) {
                Element child = (Element) aChildren;

                if( child.getName().equalsIgnoreCase(dr.evolution.util.Date.DATE) ) {
                    Date date = readDate(child);
                    taxon.setAttribute(dr.evolution.util.Date.DATE, date);
                } else if( child.getName().equalsIgnoreCase(AttributeParser.ATTRIBUTE) ) {
                    String name = child.getAttributeValue(AttributeParser.NAME);
                    String value = child.getAttributeValue(AttributeParser.VALUE);
                    if (value == null) {
                        value = child.getTextTrim();
                    }
                    taxon.setAttribute(name, value);
                }
            }
        } else {
            String idref = e.getAttributeValue(XMLParser.IDREF);
            int index = primaryTaxa.getTaxonIndex(idref);
            if (index >= 0) {
                taxon = primaryTaxa.getTaxon(index);
            }
        }

        return taxon;
    }
 
Example 13
Source File: BeastImporter.java    From beast-mcmc with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Taxon readTaxon(TaxonList primaryTaxa, Element e) throws Importer.ImportException {

        String id = e.getAttributeValue(XMLParser.ID);

        Taxon taxon = null;

        if (id != null) {
            taxon = new Taxon(id);

            List children = e.getChildren();
            for(Object aChildren : children) {
                Element child = (Element) aChildren;

                if( child.getName().equalsIgnoreCase(dr.evolution.util.Date.DATE) ) {
                    Date date = readDate(child);
                    taxon.setAttribute(dr.evolution.util.Date.DATE, date);
                } else if( child.getName().equalsIgnoreCase(AttributeParser.ATTRIBUTE) ) {
                    String name = child.getAttributeValue(AttributeParser.NAME);
                    String value = child.getAttributeValue(AttributeParser.VALUE);
                    if (value == null) {
                        value = child.getTextTrim();
                    }
                    taxon.setAttribute(name, value);
                }
            }
        } else {
            String idref = e.getAttributeValue(XMLParser.IDREF);
            int index = primaryTaxa.getTaxonIndex(idref);
            if (index >= 0) {
                taxon = primaryTaxa.getTaxon(index);
            }
        }

        return taxon;
    }
 
Example 14
Source File: JDOMUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
public static String getStringVal(final Element e, final boolean trim) {
  if (e == null) {
    return null;
  } else {
    if (trim) {
      return e.getTextTrim();
    } else {
      return e.getText();
    }
  }
}
 
Example 15
Source File: JDOMUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
public static String getStringValIgnoreNamespace(
    final Element parentEl,
    final String childName,
    final Namespace[] namespaces,
    final boolean tryLowerCase) {
  final Element el = getChildIgnoreNamespace(parentEl, childName, namespaces, tryLowerCase);

  if (el != null) {
    return el.getTextTrim();
  } else {
    return null;
  }
}
 
Example 16
Source File: RuleXmlParser.java    From rice with Educational Community License v2.0 4 votes vote down vote up
/**
 * Parses, and only parses, a rule definition (be it a top-level rule, or a rule delegation).  This method will
 * NOT dirty or save any existing data, it is side-effect-free.
 * @param element the rule element
 * @return a new RuleBaseValues object which is not yet saved
 * @throws XmlException
 */
private RuleBaseValues parseRule(Element element) throws XmlException {
    String name = element.getChildText(NAME, element.getNamespace());
    RuleBaseValues rule = createRule(name);
    
    setDefaultRuleValues(rule);
    rule.setName(name);
    
    String toDatestr = element.getChildText( TO_DATE, element.getNamespace());
    String fromDatestr = element.getChildText( FROM_DATE, element.getNamespace());
    rule.setToDateValue(formatDate("toDate", toDatestr));
    rule.setFromDateValue(formatDate("fromDate", fromDatestr));

    String description = element.getChildText(DESCRIPTION, element.getNamespace());
    if (StringUtils.isBlank(description)) {
        throw new XmlException("Rule must have a description.");
    }
            
    String documentTypeName = element.getChildText(DOCUMENT_TYPE, element.getNamespace());
    if (StringUtils.isBlank(documentTypeName)) {
    	throw new XmlException("Rule must have a document type.");
    }
    DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName);
    if (documentType == null) {
    	throw new XmlException("Could not locate document type '" + documentTypeName + "'");
    }

    RuleTemplateBo ruleTemplate = null;
    String ruleTemplateName = element.getChildText(RULE_TEMPLATE, element.getNamespace());        
    Element ruleExtensionsElement = element.getChild(RULE_EXTENSIONS, element.getNamespace());
    if (!StringUtils.isBlank(ruleTemplateName)) {
    	ruleTemplate = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName(ruleTemplateName);
    	if (ruleTemplate == null) {
    		throw new XmlException("Could not locate rule template '" + ruleTemplateName + "'");
    	}
    } else {
    	if (ruleExtensionsElement != null) {
    		throw new XmlException("Templateless rules may not have rule extensions");
    	}
    }

    RuleExpressionDef ruleExpressionDef = null;
    Element exprElement = element.getChild(RULE_EXPRESSION, element.getNamespace());
    if (exprElement != null) {
    	String exprType = exprElement.getAttributeValue("type");
    	if (StringUtils.isEmpty(exprType)) {
    		throw new XmlException("Expression type must be specified");
    	}
    	String expression = exprElement.getTextTrim();
    	ruleExpressionDef = new RuleExpressionDef();
    	ruleExpressionDef.setType(exprType);
    	ruleExpressionDef.setExpression(expression);
    }
    
    String forceActionValue = element.getChildText(FORCE_ACTION, element.getNamespace());
    Boolean forceAction = Boolean.valueOf(DEFAULT_FORCE_ACTION);
    if (!StringUtils.isBlank(forceActionValue)) {
        forceAction = Boolean.valueOf(forceActionValue);
    }

    rule.setDocTypeName(documentType.getName());
    if (ruleTemplate != null) {
        rule.setRuleTemplateId(ruleTemplate.getId());
        rule.setRuleTemplate(ruleTemplate);
    }
    if (ruleExpressionDef != null) {
        rule.setRuleExpressionDef(ruleExpressionDef);
    }
    rule.setDescription(description);
    rule.setForceAction(forceAction);

    Element responsibilitiesElement = element.getChild(RESPONSIBILITIES, element.getNamespace());
    rule.setRuleResponsibilities(parseResponsibilities(responsibilitiesElement, rule));
    rule.setRuleExtensions(parseRuleExtensions(ruleExtensionsElement, rule));

    return rule;
}