Example usage for org.jdom2 Element getName

List of usage examples for org.jdom2 Element getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the (local) name of the element (without any namespace prefix).

Usage

From source file:com.rhythm.louie.server.LouieProperties.java

License:Apache License

private static void processServiceDefaults(Element defaults) {
    for (Element defaultProp : defaults.getChildren()) {
        String propName = defaultProp.getName().toLowerCase();
        String propValue = defaultProp.getTextTrim();
        if (null != propName)
            switch (propName) {
            case CACHING:
                ServiceProperties.setDefaultCaching(Boolean.parseBoolean(propValue));
                break;
            case ENABLE:
                ServiceProperties.setDefaultEnable(Boolean.parseBoolean(propValue));
                break;
            case REMOTE_SERVER:
                ServiceProperties.setDefaultRemoteServer(propValue);
                break;
            case READ_ONLY:
                ServiceProperties.setDefaultReadOnly(Boolean.parseBoolean(propValue));
                break;
            default:
                LoggerFactory.getLogger(LouieProperties.class)
                        .warn("Unexpected default service config key {}:{}", propName, propValue);
                break;
            }/* www . ja v  a2 s.co m*/
    }
}

From source file:com.rhythm.louie.server.LouieProperties.java

License:Apache License

private static void processServices(Element services, boolean internal) {
    if (services == null)
        return;/*from  w ww . j  av a 2s  .  c o  m*/

    for (Element elem : services.getChildren()) {
        if (DEFAULT.equalsIgnoreCase(elem.getName())) {
            processServiceDefaults(elem);
            break;
        }
    }

    List<ServiceProperties> servicesList = new ArrayList<>();
    for (Element service : services.getChildren()) {
        String elementName = service.getName();
        if (!SERVICE.equalsIgnoreCase(elementName)) {
            if (!DEFAULT.equalsIgnoreCase(elementName)) {
                LoggerFactory.getLogger(LouieProperties.class).warn("Unknown {} element: {}", SERVICE_PARENT,
                        elementName);
            }
            continue;
        }

        String serviceName = null;
        Boolean enable = null;
        for (Attribute attr : service.getAttributes()) {
            String propName = attr.getName().toLowerCase();
            String propValue = attr.getValue();
            if (null != propName)
                switch (propName) {
                case NAME:
                    serviceName = propValue;
                    break;
                case ENABLE:
                    enable = Boolean.valueOf(propValue);
                    break;
                default:
                    LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected service attribute {}:{}",
                            propName, propValue);
                    break;
                }
        }

        if (serviceName == null) {
            LoggerFactory.getLogger(LouieProperties.class)
                    .error("A service was missing it's 'name' attribute and will be skipped");
            continue;
        }

        ServiceProperties prop = new ServiceProperties(serviceName);
        if (enable != null) {
            prop.setEnable(enable);
        }

        for (Element serviceProp : service.getChildren()) {
            String propName = serviceProp.getName().toLowerCase();
            String propValue = serviceProp.getTextTrim();
            if (null != propName)
                switch (propName) {
                case CACHING:
                    prop.setCaching(Boolean.valueOf(propValue));
                    break;
                case READ_ONLY:
                    prop.setReadOnly(Boolean.valueOf(propValue));
                    break;
                case PROVIDER_CL:
                    prop.setProviderClass(propValue);
                    break;
                case RESPECTED_GROUPS:
                    AccessManager.loadServiceAccess(serviceName, serviceProp);
                    break;
                case RESERVED:
                    if (internal)
                        prop.setReserved(Boolean.valueOf(propValue));
                    break;
                case LAYERS:
                    processServiceLayers(serviceProp, prop);
                    break;
                case CUSTOM:
                    for (Element child : serviceProp.getChildren()) {
                        prop.addCustomProp(child.getName(), child.getTextTrim());
                    }
                    break;
                default:
                    LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected server property  {}:{}",
                            propName, propValue);
                }
        }
        servicesList.add(prop);
    }
    ServiceProperties.processServices(servicesList);
}

From source file:com.rhythm.louie.server.LouieProperties.java

License:Apache License

private static void processServiceLayers(Element layers, ServiceProperties props) {
    for (Element layer : layers.getChildren()) {
        String layerName = layer.getName().toLowerCase();
        switch (layerName) {
        case LAYER:
            props.addLayer(new CustomServiceLayer(layer.getAttributeValue("class")));
            break;
        case LAYER_DAO:
            props.addLayer(AnnotatedServiceLayer.DAO);
            break;
        case LAYER_CACHE:
            props.addLayer(AnnotatedServiceLayer.CACHE);
            break;
        case LAYER_ROUTER:
            props.addLayer(AnnotatedServiceLayer.ROUTER);
            break;
        case LAYER_REMOTE:
            String server = layer.getAttributeValue(SERVER);
            String host = layer.getAttributeValue(HOST);
            String gateway = layer.getAttributeValue(GATEWAY);
            String port = layer.getAttributeValue(PORT);
            if (server != null) {
                props.addLayer(new RemoteServiceLayer(server));
            } else if (host != null && gateway != null && port != null) {
                props.addLayer(new RemoteServiceLayer(host, gateway, Integer.parseInt(port)));
            } else {
                String defaultServer = ServiceProperties.getDefaultRemoteServer();
                if (defaultServer == null) {
                    LoggerFactory.getLogger(LouieProperties.class).error(
                            "Failed to configure remote layer for service {}. Check configs.", props.getName());
                }/*from www.j a va 2 s  .c o  m*/
                props.addLayer(new RemoteServiceLayer(defaultServer));
            }
            break;
        default:
            LoggerFactory.getLogger(LouieProperties.class).warn("Unkown layer:{}", layerName);
        }
    }
}

From source file:com.rhythm.louie.server.LouieProperties.java

License:Apache License

private static void processCustomProperties(Element customElem) {
    for (Element customProp : customElem.getChildren()) {
        String propName = customProp.getName();
        CustomProperty custom = new CustomProperty(propName);
        for (Element child : customProp.getChildren()) {
            custom.setProperty(child.getName(), child.getTextTrim());
        }/*from ww w  .java2s  . c  om*/
        customProperties.put(propName, custom);
    }
}

From source file:com.rhythm.louie.server.TaskSchedulerProperties.java

License:Apache License

public static void processProperties(Element scheduler) {
    for (Element child : scheduler.getChildren()) {
        String elemName = child.getName().toLowerCase();
        String elemValue = child.getTextTrim();
        switch (elemName) {
        case POOL_SIZE:
            threadPoolSize = Integer.parseInt(elemValue);
            break;
        case JNDI:
            jndiKey = elemValue;/* w ww  .  j  ava2  s .c  o  m*/
            break;
        default:
            LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected scheduler property  {}:{}",
                    elemName, elemValue);
            break;
        }
    }
}

From source file:com.rometools.modules.atom.io.AtomModuleParser.java

License:Apache License

@Override
public Module parse(Element element, Locale locale) {
    AtomLinkModuleImpl mod = new AtomLinkModuleImpl();
    if (element.getName().equals("channel") || element.getName().equals("item")) {
        List<Element> links = element.getChildren("link", NS);
        List<Link> result = new LinkedList<Link>();
        for (Element link : links) {
            Link l = parseLink(link);//w w  w  .j a  va 2  s . c o  m
            result.add(l);
        }
        mod.setLinks(result);
        return mod;
    }
    return null;
}

From source file:com.rometools.modules.base.io.CustomTagParser.java

License:Open Source License

@Override
public Module parse(final Element element, final Locale locale) {
    final CustomTags module = new CustomTagsImpl();
    final ArrayList<CustomTag> tags = new ArrayList<CustomTag>();
    final List<Element> elements = element.getChildren();
    final Iterator<Element> it = elements.iterator();
    while (it.hasNext()) {
        final Element child = it.next();
        if (child.getNamespace().equals(NS)) {
            final String type = child.getAttributeValue("type");
            try {
                if (type == null) {
                    continue;
                } else if (type.equals("string")) {
                    tags.add(new CustomTagImpl(child.getName(), child.getText()));
                } else if (type.equals("int")) {
                    tags.add(new CustomTagImpl(child.getName(), new Integer(child.getTextTrim())));
                } else if (type.equals("float")) {
                    tags.add(new CustomTagImpl(child.getName(), new Float(child.getTextTrim())));
                } else if (type.equals("intUnit")) {
                    tags.add(new CustomTagImpl(child.getName(), new IntUnit(child.getTextTrim())));
                } else if (type.equals("floatUnit")) {
                    tags.add(new CustomTagImpl(child.getName(), new FloatUnit(child.getTextTrim())));
                } else if (type.equals("date")) {
                    try {
                        tags.add(new CustomTagImpl(child.getName(),
                                new ShortDate(GoogleBaseParser.SHORT_DT_FMT.parse(child.getTextTrim()))));
                    } catch (final ParseException e) {
                        LOG.warn("Unable to parse date type on " + child.getName(), e);
                    }/*from w w  w . j  a v  a2  s . c  o  m*/
                } else if (type.equals("dateTime")) {
                    try {
                        tags.add(new CustomTagImpl(child.getName(),
                                GoogleBaseParser.LONG_DT_FMT.parse(child.getTextTrim())));
                    } catch (final ParseException e) {
                        LOG.warn("Unable to parse date type on " + child.getName(), e);
                    }
                } else if (type.equals("dateTimeRange")) {
                    try {
                        tags.add(new CustomTagImpl(child.getName(),
                                new DateTimeRange(
                                        GoogleBaseParser.LONG_DT_FMT.parse(
                                                child.getChild("start", CustomTagParser.NS).getText().trim()),
                                        GoogleBaseParser.LONG_DT_FMT.parse(
                                                child.getChild("end", CustomTagParser.NS).getText().trim()))));
                    } catch (final Exception e) {
                        LOG.warn("Unable to parse date type on " + child.getName(), e);
                    }
                } else if (type.equals("url")) {
                    try {
                        tags.add(new CustomTagImpl(child.getName(), new URL(child.getTextTrim())));
                    } catch (final MalformedURLException e) {
                        LOG.warn("Unable to parse URL type on " + child.getName(), e);
                    }
                } else if (type.equals("boolean")) {
                    tags.add(
                            new CustomTagImpl(child.getName(), new Boolean(child.getTextTrim().toLowerCase())));
                } else if (type.equals("location")) {
                    tags.add(new CustomTagImpl(child.getName(), new CustomTagImpl.Location(child.getText())));
                } else {
                    throw new Exception("Unknown type: " + type);
                }
            } catch (final Exception e) {
                LOG.warn("Unable to parse type on " + child.getName(), e);
            }
        }
    }
    module.setValues(tags);
    return module;
}

From source file:com.rometools.modules.base.io.GoogleBaseParser.java

License:Open Source License

@Override
public Module parse(final Element element, final Locale locale) {
    final HashMap<String, PropertyDescriptor> tag2pd = new HashMap<String, PropertyDescriptor>();
    final GoogleBaseImpl module = new GoogleBaseImpl();

    try {//from   w w w  . j  a v  a  2  s. com
        for (final PropertyDescriptor pd : pds) {
            final String tagName = GoogleBaseParser.PROPS2TAGS.getProperty(pd.getName());

            if (tagName == null) {
                LOG.debug("Property: {} doesn't have a tag mapping.", pd.getName());
            } else {
                tag2pd.put(tagName, pd);
            }
        }
    } catch (final Exception e) {
        throw new RuntimeException("Exception building tag to property mapping. ", e);
    }

    final List<Element> children = element.getChildren();
    final Iterator<Element> it = children.iterator();

    while (it.hasNext()) {
        final Element child = it.next();

        if (child.getNamespace().equals(GoogleBaseParser.NS)) {
            final PropertyDescriptor pd = tag2pd.get(child.getName());

            if (pd != null) {
                try {
                    handleTag(child, pd, module);
                } catch (final Exception e) {
                    LOG.warn("Unable to handle tag: " + child.getName(), e);
                    e.printStackTrace();
                }
            }
        }
    }

    return module;
}

From source file:com.rometools.modules.cc.io.CCModuleGenerator.java

License:Open Source License

private void generateRSS1(final CreativeCommons module, final Element element) {
    // throw new RuntimeException( "Generating RSS1 Feeds not currently Supported.");

    LOG.debug(element.getName());
    if (element.getName().equals("channel")) {
        // Do all licenses list.
        final License[] all = module.getAllLicenses();
        for (final License element2 : all) {
            final Element license = new Element("License", RSS1);
            license.setAttribute("about", element2.getValue(), RDF);
            final License.Behaviour[] permits = element2.getPermits();
            for (int j = 0; permits != null && j < permits.length; j++) {
                final Element permit = new Element("permits", RSS1);
                permit.setAttribute("resource", permits[j].toString(), RDF);
                license.addContent(permit);
            }/*from www . j  a  v a 2  s . c  o m*/
            final License.Behaviour[] requires = element2.getPermits();
            for (int j = 0; requires != null && j < requires.length; j++) {
                final Element permit = new Element("requires", RSS1);
                permit.setAttribute("resource", permits[j].toString(), RDF);
                license.addContent(permit);
            }
            LOG.debug("Is Root? {}", element.getParentElement());
            element.getParentElement().addContent(license);
        }
    }

    // Do local licenses
    final License[] licenses = module.getLicenses();
    for (final License license2 : licenses) {
        final Element license = new Element("license", RSS1);
        license.setAttribute("resource", license2.getValue(), RDF);
        element.addContent(license);
    }

}

From source file:com.rometools.modules.cc.io.ModuleParserRSS2.java

License:Open Source License

@Override
public Module parse(final Element element, final Locale locale) {
    final CreativeCommonsImpl module = new CreativeCommonsImpl();
    // Do channel global
    {//w  w  w  .ja  v a  2s  .c  o  m
        Element root = element;
        while (!root.getName().equals("channel") && !root.getName().equals("feed")) {
            root = root.getParentElement();
        }
        final ArrayList<License> licenses = new ArrayList<License>();
        List<Element> items = null;
        if (root.getName().equals("channel")) {
            items = root.getChildren("item");
        } else {
            items = root.getChildren("entry");
        }

        final Iterator<Element> iit = items.iterator();
        while (iit.hasNext()) {
            final Element item = iit.next();
            final List<Element> licenseTags = item.getChildren("license", NS);
            final Iterator<Element> lit = licenseTags.iterator();
            while (lit.hasNext()) {
                final Element licenseTag = lit.next();
                final License license = License.findByValue(licenseTag.getTextTrim());
                if (!licenses.contains(license)) {
                    ;
                }
                licenses.add(license);
            }
        }
        if (!licenses.isEmpty()) {
            module.setAllLicenses(licenses.toArray(new License[0]));
        }
    }
    // do element local
    final ArrayList<License> licenses = new ArrayList<License>();
    final List<Element> licenseTags = element.getChildren("license", NS);
    final Iterator<Element> it = licenseTags.iterator();
    while (it.hasNext()) {
        final Element licenseTag = it.next();
        licenses.add(License.findByValue(licenseTag.getTextTrim()));
    }
    if (!licenses.isEmpty()) {
        module.setLicenses(licenses.toArray(new License[0]));
    }

    if (module.getLicenses() != null && module.getAllLicenses() != null) {
        return module;
    } else {
        return null;
    }
}