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:io.smartspaces.master.server.services.internal.support.JdomMasterDomainModelImporter.java

License:Apache License

/**
 * Import a master domain model./*w  ww  .j  av a  2  s . co m*/
 *
 * @param model
 *          model to import
 * @param activityRepository
 *          the repository for activity entities
 * @param controllerRepository
 *          the repository for controller entities
 * @param resourceRepository
 *          the resource repository
 * @param automationRepository
 *          the repository for automation entities
 * @param timeProvider
 *          the time provider to use
 */
public void importModel(String model, ActivityRepository activityRepository,
        SpaceControllerRepository controllerRepository, ResourceRepository resourceRepository,
        AutomationRepository automationRepository, TimeProvider timeProvider) {
    Element rootElement = readDescription(model);

    if (!ELEMENT_NAME_DESCRIPTION_ROOT_ELEMENT.equals(rootElement.getName())) {
        throw new SimpleSmartSpacesException(String.format("The description file doesn't have root element %s",
                ELEMENT_NAME_DESCRIPTION_ROOT_ELEMENT));
    }

    getSpaceControllers(rootElement, controllerRepository);
    getActivities(rootElement, activityRepository, timeProvider);
    getLiveActivities(rootElement, activityRepository);
    getLiveActivityGroups(rootElement, activityRepository);
    getSpaces(rootElement, activityRepository);
    getResources(rootElement, resourceRepository);
    getNamedScripts(rootElement, automationRepository);
}

From source file:io.smartspaces.workbench.project.jdom.JdomProjectGroupTemplateSpecificationReader.java

License:Apache License

@Override
public GroupProjectTemplateSpecification readProjectGroupTemplateSpecification(File specFile) {
    try {/*  w  ww . ja  va2  s . c o m*/
        Element rootElement = getRootElement(specFile);
        String type = rootElement.getName();
        GroupProjectTemplateSpecification specification;
        if (PROJECT_GROUP_TEMPLATE_SPECIFICATION_ELEMENT_NAME.equals(type)) {
            specification = makeFromElement(rootElement);
        } else if (PROJECT_GROUP_ELEMENT_NAME.equals(type)) {
            specification = makeFromElement(rootElement);
        } else {
            throw new SimpleSmartSpacesException("Unknown root element type " + type);
        }
        specification.setSpecificationSource(specFile);
        return specification;
    } catch (Exception e) {
        throw new SimpleSmartSpacesException(
                "While processing specification file " + specFile.getAbsolutePath(), e);
    }
}

From source file:io.smartspaces.workbench.project.jdom.JdomProjectGroupTemplateSpecificationReader.java

License:Apache License

/**
 * Add the given element to the spec.//from  w  ww  .j  a  v a2s .  co m
 *
 * @param spec
 *          specification to configure
 * @param namespace
 *          XML namespace for elements
 * @param child
 *          child element to add
 */
private void addElementToSpec(GroupProjectTemplateSpecification spec, Namespace namespace, Element child) {
    String name = child.getName();

    try {
        if (JdomProjectReader.PROJECT_GROUP_ELEMENT_NAME.equals(name)) {
            addProjects(spec, child);
        } else if (JdomPrototypeProcessor.GROUP_ELEMENT_NAME.equals(name)) {
            addPrototypes(spec, child);
        } else if (JdomProjectReader.PROJECT_ELEMENT_NAME_NAME.equals(name)) {
            spec.setName(child.getTextTrim());
        } else if (JdomProjectReader.PROJECT_ELEMENT_NAME_DESCRIPTION.equals(name)) {
            spec.setDescription(child.getTextTrim());
        } else if (JdomReader.PROJECT_ELEMENT_NAME_TEMPLATES.equals(name)) {
            // This is really a prototype chain for the entire group project, but we
            // need to control when it is processed,
            // so instead snarf the attribute from the templates element when it is
            // processed.
            processPrototypeChain(spec, namespace, child);
            spec.addExtraConstituents(getContainerConstituents(namespace, child, null));
        } else if (JdomProjectReader.PROJECT_ELEMENT_NAME_VERSION.equals(name)) {
            spec.setVersion(Version.parseVersion(child.getTextTrim()));
        } else {
            throw new SimpleSmartSpacesException("Unrecognized element name: " + name);
        }
    } catch (Exception e) {
        throw new SimpleSmartSpacesException("While processing projectGroup element: " + name, e);
    }
}

From source file:io.smartspaces.workbench.project.jdom.JdomProjectReader.java

License:Apache License

/**
 * Process an element and return a new project.
 *
 * @param projectElement//from ww w .  j  a va 2  s  .  c  om
 *          element to process
 *
 * @return project representing the element
 */
Project makeProjectFromElement(Element projectElement) {
    Namespace projectNamespace = projectElement.getNamespace();

    if (!PROJECT_ELEMENT_NAME_PROJECT.equals(projectElement.getName())) {
        throw new SimpleSmartSpacesException("Invalid project root element name " + projectElement.getName());
    }

    // When an xi:include statement is used, the included elements do not pick
    // up the default namespace.
    if (!Namespace.NO_NAMESPACE.equals(projectNamespace)) {
        getLog().info(String.format("Applying default namespace '%s' to project element tree",
                projectNamespace.getURI()));
        applyDefaultNamespaceRecursively(projectElement, projectNamespace, true);
    }

    String projectType = getProjectType(projectElement);
    Project project = getWorkbench().getProjectTypeRegistry().newProject(projectType);

    project.setPlatform(getProjectPlatform(projectElement));

    processPrototypeChain(project, projectNamespace, projectElement);
    configureProjectFromElement(project, projectNamespace, projectElement);

    if (project.getSmartSpacesVersionRange() == null) {
        getLog().warn("Did not specify a range of needed Smart Spaces versions. Setting default to "
                + SMARTSPACES_VERSION_RANGE_DEFAULT);
        project.setSmartSpacesVersionRange(SMARTSPACES_VERSION_RANGE_DEFAULT);
    }

    if (failure) {
        throw new SimpleSmartSpacesException("Project specification had errors");
    }

    return project;
}

From source file:io.smartspaces.workbench.project.jdom.JdomProjectReader.java

License:Apache License

/**
 * Recursively apply a default namespace to an element tree. This will log
 * instances that are changed at the root of a tree (but not elements
 * underneath that root).//from www  .j a v a  2 s. c  o m
 *
 * @param element
 *          target root element
 * @param namespace
 *          namespace to apply as default
 * @param shouldLog
 *          {@code true} if logging should be applied to any matches
 */
void applyDefaultNamespaceRecursively(Element element, Namespace namespace, boolean shouldLog) {
    if (Namespace.NO_NAMESPACE.equals(element.getNamespace())) {
        if (shouldLog) {
            getLog().info(
                    String.format("Applying default namespace to element tree root '%s'", element.getName()));
            shouldLog = false;
        }
        element.setNamespace(namespace);
    }
    for (Element child : element.getChildren()) {
        applyDefaultNamespaceRecursively(child, namespace, shouldLog);
    }
}

From source file:io.smartspaces.workbench.project.jdom.JdomPrototypeProcessor.java

License:Apache License

/**
 * Add a prototype record for the given element.
 *
 * @param element//  w w  w .  java2  s  .com
 *          element to add a prototype for
 */
public void addPrototypeElement(Element element) {
    Preconditions.checkArgument(ELEMENT_NAME.equals(element.getName()),
            "Invalid prototype element name " + element.getName());
    String name = element.getAttributeValue(PROTOTYPE_NAME_ATTRIBUTE);
    Preconditions.checkNotNull(name, "Missing prototype name attribute from prototype");
    if (prototypeMap.put(name, element) != null) {
        throw new SimpleSmartSpacesException("Duplicate prototype name " + name);
    }
}

From source file:io.smartspaces.workbench.project.jdom.JdomReader.java

License:Apache License

/**
 * Get the constituent from the element which describes it..
 *
 * @param namespace//  w ww .jav  a 2  s.  c  o m
 *          XML namespace for elements
 * @param constituentElement
 *          the element containing the constituent
 * @param project
 *          the project being built
 * @param constituents
 *          the list of constituents currently being extracted
 */
private void getConstituent(Namespace namespace, Element constituentElement, Project project,
        List<ProjectConstituent> constituents) {
    String type = constituentElement.getName();
    ProjectConstituent.ProjectConstituentBuilderFactory factory = getProjectConstituentFactoryMap().get(type);
    if (factory != null) {
        ProjectConstituent.ProjectConstituentBuilder projectConstituentBuilder = factory.newBuilder();
        projectConstituentBuilder.setLog(getLog());
        ProjectConstituent constituent = projectConstituentBuilder.buildConstituentFromElement(namespace,
                constituentElement, project);
        if (constituent != null) {
            constituents.add(constituent);
        }
        if (projectConstituentBuilder.hasErrors()) {
            addError(String.format("Error building project constituent type '%s'", type));
        }
    } else {
        addError(String.format("Unknown resource type '%s'", type));
    }
}

From source file:io.wcm.handler.richtext.impl.RichTextRewriteContentHandlerImpl.java

License:Apache License

/**
 * Checks if the given element has to be rewritten.
 * Is called for every child single element of the parent given to rewriteContent method.
 * @param element Element to check//from w w  w.j a va 2s.  c  o  m
 * @return null if nothing is to do with this element.
 *         Return empty list to remove this element.
 *         Return list with other content to replace element with new content.
 */
@Override
public List<Content> rewriteElement(Element element) {

    // rewrite anchor elements
    if (StringUtils.equalsIgnoreCase(element.getName(), "a")) {
        return rewriteAnchor(element);
    }

    // rewrite image elements
    else if (StringUtils.equalsIgnoreCase(element.getName(), "img")) {
        return rewriteImage(element);
    }

    // detect BR elements and turn those into "self-closing" elements
    // since the otherwise generated <br> </br> structures are illegal and
    // are not handled correctly by Internet Explorers
    else if (StringUtils.equalsIgnoreCase(element.getName(), "br")) {
        if (element.getContent().size() > 0) {
            element.removeContent();
        }
        return null;
    }

    // detect empty elements and insert at least an empty string to avoid "self-closing" elements
    // that are not handled correctly by most browsers
    else if (NONSELFCLOSING_TAGS.contains(StringUtils.lowerCase(element.getName()))) {
        if (element.getContent().isEmpty()) {
            element.setText("");
        }
        return null;
    }

    return null;
}

From source file:io.wcm.maven.plugins.contentpackage.unpacker.ContentUnpacker.java

License:Apache License

private void applyXmlExcludes(Element element, String parentPath) {
    String path = parentPath + "/" + element.getName();
    if (exclude(path, this.excludeNodes)) {
        element.detach();/*from   w  w w.  j a v a 2  s .c  o m*/
        return;
    }
    List<Attribute> attributes = new ArrayList<>(element.getAttributes());
    for (Attribute attribute : attributes) {
        if (exclude(attribute.getQualifiedName(), this.excludeProperties)) {
            attribute.detach();
        }
    }
    List<Element> children = new ArrayList<>(element.getChildren());
    for (Element child : children) {
        applyXmlExcludes(child, path);
    }
}

From source file:io.wcm.maven.plugins.i18n.readers.XmlI18nReader.java

License:Apache License

private void parseXml(Element node, Map<String, String> map, String prefix) {
    List<Element> children = node.getChildren();
    for (Element child : children) {
        String key = child.getName();
        if (child.getChildren().size() > 0) {
            parseXml(child, map, prefix + key + ".");
        } else {//  w  w  w .  ja v  a 2 s .  com
            map.put(prefix + key, child.getText());
        }
    }
}