Example usage for org.jdom2 Element getChild

List of usage examples for org.jdom2 Element getChild

Introduction

In this page you can find the example usage for org.jdom2 Element getChild.

Prototype

public Element getChild(final String cname) 

Source Link

Document

This returns the first child element within this element with the given local name and belonging to no namespace.

Usage

From source file:com.github.lucapino.sheetmaker.renderer.JavaTemplateRenderer.java

private BufferedImage processActions(Element imageElement, BufferedImage tmpImage) {
    // verify if there are filters
    Element actions = imageElement.getChild("Actions");
    if (actions != null) {
        List<Element> filters = actions.getChildren();
        for (Element filter : filters) {
            logger.info("Processing action {}", filter.getName());
            // TODO: implement filters
            switch (filter.getName()) {
            // Crop
            case "Crop":
                break;
            // GlassTable
            case "GlassTable":
                MirrorFilter mirrorFilter = new MirrorFilter();
                float reflectionOpacity = Float.valueOf(filter.getAttributeValue("ReflectionOpacity"));
                mirrorFilter.setOpacity(reflectionOpacity / 100);
                mirrorFilter.setCentreY(1f);
                mirrorFilter.setGap(0f);

                tmpImage = mirrorFilter.filter(tmpImage, null);
                break;
            // Glow
            case "Glow":
                GlowFilter glowFilter = new GlowFilter();
                float amount = Float.valueOf(filter.getAttributeValue("Amount"));
                glowFilter.setAmount(amount);
                tmpImage = glowFilter.filter(tmpImage, null);
                break;
            // GaussianBlur
            case "GaussianBlur":
                GaussianFilter gaussianFilter = new GaussianFilter();
                gaussianFilter.setRadius(Float.valueOf(filter.getAttributeValue("Radius")));
                tmpImage = gaussianFilter.filter(tmpImage, null);
                break;
            // AdjustHue
            case "AdjustHue":
                break;
            // AdjustGamma
            case "AdjustGamma":
                break;
            // RoundCorners
            case "RoundCorners":
                break;
            // AdjustSaturation
            case "AdjustSaturation":
                break;
            // AdjustBrightness
            case "AdjustBrightness":
                break;
            // AdjustOpacity
            case "AdjustOpacity":
                //                        int opacity = (int) (Float.valueOf(filter.getAttributeValue("Opacity")) * 255 / 100);
                //                        OpacityFilter opacityFilter = new OpacityFilter(opacity);
                //                        tmpImage = opacityFilter.filter(tmpImage, null);
                break;
            // PerspectiveView
            case "PerspectiveView":
                break;
            // Rotate
            case "Rotate":
                RotateFilter rotateFilter = new RotateFilter();
                float rotateAngle = Float.valueOf(filter.getAttributeValue("Angle"));
                rotateFilter.setAngle(rotateAngle);
                tmpImage = rotateFilter.filter(tmpImage, null);
                break;
            // DropShadow
            case "DropShadow":
                logger.info("Dropping shadow...");
                ShadowFilter shadow = new ShadowFilter();
                float angle = Float.valueOf(filter.getAttributeValue("Angle"));
                shadow.setAngle(angle);//w  w  w.  j  ava  2 s  .c o  m
                float distance = Float.valueOf(filter.getAttributeValue("Distance"));
                shadow.setDistance(distance);
                // shadow.setRadius(3.0f);
                float opacity = Float.valueOf(filter.getAttributeValue("Opacity"));
                shadow.setOpacity(opacity / 100);
                tmpImage = shadow.filter(tmpImage, null);
                break;
            // Skew
            case "Skew":
                break;
            // Flip
            case "Flip":
                FlipFilter flipFilter = new FlipFilter();
                // Type can be "Horizontal" or "Vertical"
                String type = filter.getAttributeValue("Type");
                switch (type.toLowerCase()) {
                case "horizontal":
                    flipFilter.setOperation(FlipFilter.FLIP_H);
                    break;
                case "vertical":
                    flipFilter.setOperation(FlipFilter.FLIP_V);
                    break;
                }
                tmpImage = flipFilter.filter(tmpImage, null);
                break;

            }
        }
    }
    return tmpImage;
}

From source file:com.github.lucapino.sheetmaker.renderer.TemplateSettings.java

public TemplateSettings(Element settingsElement) {
    for (Element setting : settingsElement.getChildren()) {
        SettingsElement element = new SettingsElement(setting);
        settingsElements.put(setting.getName(), element);
    }/*ww w  .j a v a  2 s .c  o  m*/
    starsRatingFilename = settingsElement.getChild(RATING).getAttributeValue(RATING_FILENAME);
}

From source file:com.hotaviano.tableexporter.pdf.PDFExporter.java

License:Open Source License

private int columnLength(Document document) {
    Element child = document.getRootElement().getChild("thead");
    return child.getChild("tr").getChildren().size();
}

From source file:com.hpe.application.automation.tools.octane.actions.UFTTestUtil.java

License:Open Source License

/**
 * Extract test description from UFT GUI test.
 * Note : UFT API test doesn't contain description
 * @param dirPath path of UFT test/*  w ww.  j  av a  2s . c o  m*/
 * @return test description
 */
public static String getTestDescription(FilePath dirPath) {
    String desc;

    try {
        if (!dirPath.exists()) {
            return null;
        }

        FilePath tspTestFile = new FilePath(dirPath, "Test.tsp");
        InputStream is = new FileInputStream(tspTestFile.getRemote());
        String xmlContent = decodeXmlContent(is);

        SAXBuilder saxBuilder = new SAXBuilder(XMLReaders.NONVALIDATING, null, null);
        Document document = saxBuilder.build(new StringReader(xmlContent));
        Element rootElement = document.getRootElement();
        Element descElement = rootElement.getChild("Description");
        desc = descElement.getValue();
    } catch (Exception e) {
        return null;
    }

    return desc;
}

From source file:com.init.octo.util.FindXML.java

License:Open Source License

/**
 * This method locates an XML tag or attribute based on an input string.
 * The input locator string must be in the format root.element.element or root.element.[attribute]
 *
 * @param   locator - the definition of the element you want to locate
 * @param   root - the root element of the XML structure
 *
 * @returns   String - the string we have found, or null of it wasn't found
 *///from ww  w .j a  v a2 s. c o  m

static public String findXML(String locator, Element root) {

    Element element = null;
    String retStr = null;
    StringTokenizer tokens = new StringTokenizer(locator, ".");
    String str = tokens.nextToken();

    if (tokens.countTokens() == 0) {
        locator = "root." + locator;
        tokens = new StringTokenizer(locator, ".");
        str = tokens.nextToken();
    }

    // follow the locator text element name definition down...

    element = root;

    while (tokens.hasMoreTokens()) {
        str = tokens.nextToken();

        if (str.startsWith("[")) { // an attribute has been specified
            String attName = str.substring(1, str.indexOf("]"));
            retStr = element.getAttributeValue(attName);
            element = null;
            break;
        } else {
            String[] spec = str.split(":");

            if (spec.length == 1) {
                element = element.getChild(str);
            } else {
                /** A specific member of a repeating group has been specified... **/
                Iterator<?> it = element.getChildren(spec[0]).iterator();
                int idx = 1;
                int num = 0;

                try {
                    num = Integer.parseInt(spec[1]);
                } catch (Exception x) {
                    log.warn("Bad element index [" + spec[1] + "]");
                    num = 1;
                }

                while (it.hasNext()) {
                    element = (Element) it.next();
                    if (idx == num) {
                        break;
                    }
                }

                /** If we go past the end of the list we will return the last one... **/
                /** this way the call can detect no change in the output...          **/
            }
        }
        if (element == null) {
            return (null);
        }
    }

    if (element != null) { // wasn't specified as an attribute...
        retStr = element.getTextTrim();
    }

    return (retStr);

}

From source file:com.jamfsoftware.jss.healthcheck.controller.ConfigurationController.java

License:Open Source License

private boolean canGetFile(File file) {
    if (file.exists()) {
        SAXBuilder builder = new SAXBuilder();
        try {//from w ww.  ja  v  a  2  s. c om
            Document document = builder.build(file);
            Element root = document.getRootElement();
            root.getChild("jss_url").getValue();
            return true;
        } catch (Exception e) {
            LOGGER.error("", e);
        }
    }

    return false;
}

From source file:com.jamfsoftware.jss.healthcheck.controller.ConfigurationController.java

License:Open Source License

/**
 * This method reads in a CSV path to keys and a CSV string of keys.
 * It loops down the path given, and then searches for all of the keys.
 *
 * @return string array of all of the found keys.
 *///from   w  ww. j a va 2  s.c  om
public String[] getValue(String path_string, String keys_string) {
    Element object = null;
    //Make two arrays out of the path given and a final content array that will be filled.
    String[] path = path_string.split(",");
    String[] keys = keys_string.split(",");
    String[] content = new String[keys.length];
    //If the path is not the root XML
    if (path.length > 1) {
        //Loop through the path
        for (int i = 0; i < path.length; i++) {
            //Get the first child from the root initialized by the constructor
            if (i == 0) {
                //Set object equal to the root.
                object = this.root.getChild(path[i]);
                //Its not the root, so use the object.
            } else {
                object = object.getChild(path[i]);
            }
        }
        //If the path is only one in length then just get elements from the root
    } else {
        object = this.root;
    }

    //Loop through the keys and fill the content array.
    for (int i = 0; i < keys.length; i++) {
        content[i] = object.getChild(keys[i]).getValue();
    }

    return content;
}

From source file:com.jamfsoftware.jss.healthcheck.HealthCheckUtility.java

License:Open Source License

private void startMonitor() {
    Scanner scanner = new Scanner(System.in);
    ConfigurationController con = new ConfigurationController();

    while (!con.canGetFile()) {
        if (!(con.attemptAutoDiscover())) {
            System.out.println(//from   w ww . j a  v a 2s . c  o m
                    "Path to Config.xml not found. Please type the full path below or type 'exit' to close the program. ");
            String path = scanner.next();
            if (path.equals("exit")) {
                System.exit(0);
            } else {
                prefs.put("config_xml_path", path);
            }
        }
    }

    String xmlPath = prefs.get("config_xml_path", "Path to file '/Users/user/desktop/config.xml'");
    SAXBuilder builder = new SAXBuilder();
    File xmlFile = new File(xmlPath);
    try {
        Document document = builder.build(xmlFile);
        Element root = document.getRootElement();
        HealthCheck hc = new HealthCheck();
        int mobile_device_length = hc.checkAPILength(root.getChild("jss_url").getValue(),
                root.getChild("jss_username").getValue(), root.getChild("jss_password").getValue(),
                "mobiledevicecommands");
        int computer_length = hc.checkAPILength(root.getChild("jss_url").getValue(),
                root.getChild("jss_username").getValue(), root.getChild("jss_password").getValue(),
                "computercommands");
        writeLogEntry(mobile_device_length, computer_length);
    } catch (Exception e) {
        LOGGER.error("Config XML file damaged. Unable to run monitor.", e);
    }
}

From source file:com.khodev.oradiff.io.XmlSchemaReader.java

License:Open Source License

private List<Element> getChildren(Element element, String name) {
    return element.getChild(name).getChildren();
}

From source file:com.khodev.oradiff.io.XmlSchemaReader.java

License:Open Source License

private Procedure getProcedure(Element element) {
    Procedure procedure = new Procedure(element.getAttributeValue("name"));
    procedure.getBody().clear();//from www.  ja  v a2s .c  o m
    String bodyStr = element.getChild("body").getText();
    String[] lines = bodyStr.split("\n");
    for (String line : lines)
        procedure.getBody().add(line + "\n");
    return procedure;
}