Example usage for org.jdom2 Element getParentElement

List of usage examples for org.jdom2 Element getParentElement

Introduction

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

Prototype

final public Element getParentElement() 

Source Link

Document

A convenience method that returns any parent element for this element, or null if the element is unattached or is a root element.

Usage

From source file:org.openflexo.foundation.fml.rm.ViewPointResourceImpl.java

License:Open Source License

private static void convertNames16ToNames17(Document document) {

    // Convert common properties
    addProperty("userID", "FLX", document, null);

    // Edition Patterns
    // Edition patterns name
    convertOldNameToNewNames("EditionPattern", "FlexoConcept", document);
    // Parent pattern property is no more an attribute but an element
    IteratorIterable<? extends Content> fcElementsIterator = document
            .getDescendants(new ElementFilter("FlexoConcept"));
    List<Element> fcElements = IteratorUtils.toList(fcElementsIterator);

    for (Element fc : fcElements) {
        if (fc.getAttribute("parentEditionPattern") != null) {
            Element parentEp = new Element("ParentFlexoConcept");
            Attribute parentIdRef = new Attribute("idref",
                    getFlexoConceptID(document, fc.getAttributeValue("parentEditionPattern")));
            parentEp.getAttributes().add(parentIdRef);
            fc.removeAttribute("parentEditionPattern");
            fc.addContent(parentEp);/*from   w w  w  .ja va 2 s . c om*/
        }
    }

    // Pattern Roles
    // Pattern roles properties
    changePropertyName("editionPatternTypeURI", "flexoConceptTypeURI", document,
            "ContainedEditionPatternInstancePatternRole");
    changePropertyName("editionPatternTypeURI", "flexoConceptTypeURI", document,
            "AddressedSelectEditionPatternInstance");
    changePropertyName("editionPatternTypeURI", "flexoConceptTypeURI", document,
            "SelectEditionPatternInstance");
    changePropertyName("editionPatternTypeURI", "flexoConceptTypeURI", document,
            "EditionPatternInstanceParameter");
    changePropertyName("paletteElementID", "paletteElementId", document, "FMLDiagramPaletteElementBinding");
    changePropertyName("editionPattern", "flexoConcept", document, "PaletteElement");
    removeProperties("patternRole", document);
    removeProperty("className", document, "DrawingGraphicalRepresentation");
    removeProperty("className", document, "ShapeGraphicalRepresentation");
    removeProperty("className", document, "ConnectorGraphicalRepresentation");
    // Pattern roles name
    convertOldNameToNewNames("ContainedEditionPatternInstancePatternRole", "FlexoConceptInstanceRole",
            document);
    convertOldNameToNewNames("EditionPatternInstancePatternRole", "FlexoConceptInstanceRole", document);
    convertOldNameToNewNames("ContainedShapePatternRole", "ShapeRole", document);
    convertOldNameToNewNames("ShapePatternRole", "ShapeRole", document);
    convertOldNameToNewNames("ContextShapePatternRole", "ShapeRole", document);
    convertOldNameToNewNames("ParentShapePatternRole", "ParentShapeRole", document);
    convertOldNameToNewNames("ContainedEMFObjectIndividualPatternRole", "EMFObjectIndividualRole", document);
    convertOldNameToNewNames("EMFObjectIndividualPatternRole", "EMFObjectIndividualRole", document);
    convertOldNameToNewNames("ContainedConnectorPatternRole", "ConnectorRole", document);
    convertOldNameToNewNames("ConnectorPatternRole", "ConnectorRole", document);
    convertOldNameToNewNames("ContainedOWLIndividualPatternRole", "OWLIndividualRole", document);
    convertOldNameToNewNames("OWLIndividualPatternRole", "OWLIndividualRole", document);
    convertOldNameToNewNames("ContainedObjectPropertyStatementPatternRole", "ObjectPropertyStatementRole",
            document);
    convertOldNameToNewNames("ObjectPropertyStatementPatternRole", "ObjectPropertyStatementRole", document);
    convertOldNameToNewNames("ContainedDataPropertyStatementPatternRole", "DataPropertyStatementRole",
            document);
    convertOldNameToNewNames("DataPropertyStatementPatternRole", "DataPropertyStatementRole", document);
    convertOldNameToNewNames("ContainedExcelCellPatternRole", "ExcelCellRole", document);
    convertOldNameToNewNames("ExcelCellPatternRole", "ExcelCellRole", document);
    convertOldNameToNewNames("ContainedExcelSheetPatternRole", "ExcelSheetRole", document);
    convertOldNameToNewNames("ExcelSheetPatternRole", "ExcelSheetRole", document);
    convertOldNameToNewNames("ContainedExcelRowPatternRole", "ExcelRowRole", document);
    convertOldNameToNewNames("ExcelRowPatternRole", "ExcelRowRole", document);
    convertOldNameToNewNames("ContainedDiagramPatternRole", "DiagramRole", document);
    convertOldNameToNewNames("DiagramPatternRole", "DiagramRole", document);
    convertOldNameToNewNames("ContainedXMLIndividualPatternRole", "XMLIndividualRole", document);
    convertOldNameToNewNames("XMLIndividualPatternRole", "XMLIndividualRole", document);
    convertOldNameToNewNames("ContainedXSIndividualPatternRole", "XSIndividualRole", document);
    convertOldNameToNewNames("XSIndividualPatternRole", "XSIndividualRole", document);
    convertOldNameToNewNames("ContainedXSClassPatternRole", "XSClassRole", document);
    convertOldNameToNewNames("XSClassPatternRole", "XSClassRole", document);

    // Actions
    convertOldNameToNewNames("EditionPatternInstanceParameter", "FlexoConceptInstanceParameter", document);
    convertOldNameToNewNames("MatchEditionPatternInstance", "MatchFlexoConceptInstance", document);
    convertOldNameToNewNames("CreateEditionPatternInstanceParameter", "CreateFlexoConceptInstanceParameter",
            document);
    // Retrieve Fetch Actions
    IteratorIterable<? extends Content> fetchElementsIterator = document
            .getDescendants(new ElementFilter("FetchRequestIterationAction"));
    List<Element> fetchElements = IteratorUtils.toList(fetchElementsIterator);
    for (Element fetchElement : fetchElements) {
        for (Element child : fetchElement.getChildren()) {
            if (child.getName().equals("AddressedSelectEditionPatternInstance")) {
                child.setName("FetchRequest_SelectFlexoConceptInstance");
            }
            if (child.getName().equals("AddressedSelectEMFObjectIndividual")) {
                child.setName("FetchRequest_SelectEMFObjectIndividual");
            }
            if (child.getName().equals("AddressedSelectIndividual")) {
                child.setName("FetchRequest_SelectIndividual");
            }
            if (child.getName().equals("AddressedSelectExcelCell")) {
                child.setName("FetchRequest_SelectExcelCell");
            }
            if (child.getName().equals("AddressedSelectExcelRow")) {
                child.setName("FetchRequest_SelectExcelRow");
            }
            if (child.getName().equals("AddressedSelectExcelSheet")) {
                child.setName("FetchRequest_SelectExcelSheet");
            }
            if (child.getName().equals("AddressedSelectEditionPatternInstance")) {
                child.setName("FetchRequest_SelectFlexoConceptInstance");
            }
        }
    }
    // Built-in actions
    convertOldNameToNewNames("DeclareFlexoRole", "DeclareFlexoRole", document);
    convertOldNameToNewNames("AddEditionPatternInstance", "AddFlexoConceptInstance", document);
    convertOldNameToNewNames("AddEditionPatternInstanceParameter", "AddFlexoConceptInstanceParameter",
            document);
    convertOldNameToNewNames("AddressedSelectEditionPatternInstance", "SelectFlexoConceptInstance", document);
    convertOldNameToNewNames("AddressedSelectFlexoConceptInstance", "SelectFlexoConceptInstance", document);
    convertOldNameToNewNames("SelectEditionPatternInstance", "SelectFlexoConceptInstance", document);

    // Model Slots
    for (Content content : document.getDescendants()) {
        if (content instanceof Element) {
            Element element = (Element) content;
            if ((element.getParentElement() != null)
                    && (element.getParentElement().getName().equals("DiagramSpecification")
                            || element.getParentElement().getName().equals("VirtualModel"))) {
                if (element.getName().equals("EMFModelSlot")) {
                    element.setName("ModelSlot_EMFModelSlot");
                } else if (element.getName().equals("XMLModelSlot")) {
                    element.setName("ModelSlot_XMLModelSlot");
                } else if (element.getName().equals("XSDModelSlot")) {
                    element.setName("ModelSlot_XSDModelSlot");
                } else if (element.getName().equals("BasicExcelModelSlot")) {
                    element.setName("ModelSlot_BasicExcelModelSlot");
                } else if (element.getName().equals("SemanticsExcelModelSlot")) {
                    element.setName("ModelSlot_SemanticsExcelModelSlot");
                } else if (element.getName().equals("BasicPowerpointModelSlot")) {
                    element.setName("ModelSlot_SemanticsPowerpointModelSlot");
                } else if (element.getName().equals("OWLModelSlot")) {
                    element.setName("ModelSlot_OWLModelSlot");
                } else if (element.getName().equals("FMLRTModelSlot")) {
                    element.setName("ModelSlot_VirtualModelModelSlot");
                }
            } else {
                if (element.getName().equals("AddressedEMFModelSlot")) {
                    element.setName("EMFModelSlot");
                } else if (element.getName().equals("AddressedXMLModelSlot")) {
                    element.setName("XMLModelSlot");
                } else if (element.getName().equals("AddressedXSDModelSlot")) {
                    element.setName("XSDModelSlot");
                } else if (element.getName().equals("AddressedBasicExcelModelSlot")) {
                    element.setName("BasicExcelModelSlot");
                } else if (element.getName().equals("AddressedSemanticsExcelModelSlot")) {
                    element.setName("SemanticsExcelModelSlot");
                } else if (element.getName().equals("AddressedBasicPowerpointModelSlot")) {
                    element.setName("BasicPowerpointModelSlot");
                } else if (element.getName().equals("AddressedSemanticsPowerpointModelSlot")) {
                    element.setName("SemanticsPowerpointModelSlot");
                } else if (element.getName().equals("AddressedOWLModelSlot")) {
                    element.setName("OWLModelSlot");
                } else if (element.getName().equals("AddressedDiagramModelSlot")) {
                    element.setName("TypedDiagramModelSlot");
                } else if (element.getName().equals("AddressedVirtualModelModelSlot")) {
                    element.setName("FMLRTModelSlot");
                }
            }
        }
    }

    // Palettes/ExampleDiagrams
    // Retrieve Connector GRs
    IteratorIterable<? extends Content> connectorGRElementsIterator = document
            .getDescendants(new ElementFilter("ConnectorGraphicalRepresentation"));
    List<Element> connectorGRElements = IteratorUtils.toList(connectorGRElementsIterator);
    for (Element connectorGRElement : connectorGRElements) {
        Element grSpec = null;
        if (connectorGRElement.getChild("RectPolylinConnector") != null) {
            grSpec = connectorGRElement.getChild("RectPolylinConnector");
        } else if (connectorGRElement.getChild("LineConnector") != null) {
            grSpec = connectorGRElement.getChild("LineConnector");
        } else if (connectorGRElement.getChild("CurvedPolylinConnector") != null) {
            grSpec = connectorGRElement.getChild("CurvedPolylinConnector");
        } else if (connectorGRElement.getChild("ArcConnector") != null) {
            grSpec = connectorGRElement.getChild("ArcConnector");
        }
        if (connectorGRElement.getAttribute("startSymbol") != null) {
            Attribute startSymbol = new Attribute("startSymbol",
                    connectorGRElement.getAttributeValue("startSymbol"));
            grSpec.getAttributes().add(startSymbol);
            connectorGRElement.removeAttribute("startSymbol");
        }
        if (connectorGRElement.getAttribute("endSymbol") != null) {
            Attribute endSymbol = new Attribute("endSymbol", connectorGRElement.getAttributeValue("endSymbol"));
            grSpec.getAttributes().add(endSymbol);
            connectorGRElement.removeAttribute("endSymbol");
        }
        if (connectorGRElement.getAttribute("middleSymbol") != null) {
            Attribute middleSymbol = new Attribute("middleSymbol",
                    connectorGRElement.getAttributeValue("middleSymbol"));
            grSpec.getAttributes().add(middleSymbol);
            connectorGRElement.removeAttribute("middleSymbol");
        }
        if (connectorGRElement.getAttribute("startSymbolSize") != null) {
            Attribute startSymbolSize = new Attribute("startSymbolSize",
                    connectorGRElement.getAttributeValue("startSymbolSize"));
            grSpec.getAttributes().add(startSymbolSize);
            connectorGRElement.removeAttribute("startSymbolSize");
        }
        if (connectorGRElement.getAttribute("endSymbolSize") != null) {
            Attribute endSymbolSize = new Attribute("endSymbolSize",
                    connectorGRElement.getAttributeValue("endSymbolSize"));
            grSpec.getAttributes().add(endSymbolSize);
            connectorGRElement.removeAttribute("endSymbolSize");
        }
        if (connectorGRElement.getAttribute("middleSymbolSize") != null) {
            Attribute middleSymbolSize = new Attribute("middleSymbolSize",
                    connectorGRElement.getAttributeValue("middleSymbolSize"));
            grSpec.getAttributes().add(middleSymbolSize);
            connectorGRElement.removeAttribute("middleSymbolSize");
        }
        if (connectorGRElement.getAttribute("relativeMiddleSymbolLocation") != null) {
            Attribute relativeMiddleSymbolLocation = new Attribute("relativeMiddleSymbolLocation",
                    connectorGRElement.getAttributeValue("relativeMiddleSymbolLocation"));
            grSpec.getAttributes().add(relativeMiddleSymbolLocation);
            connectorGRElement.removeAttribute("relativeMiddleSymbolLocation");
        }
    }

    convertOldNameToNewNames("Palette", "DiagramPalette", document);
    convertOldNameToNewNames("PaletteElement", "DiagramPaletteElement", document);
    convertOldNameToNewNames("Shema", "Diagram", document);
    convertOldNameToNewNames("ContainedShape", "Shape", document);
    convertOldNameToNewNames("ContainedConnector", "Connector", document);
    convertOldNameToNewNames("FromShape", "StartShape", document);
    convertOldNameToNewNames("ToShape", "EndShape", document);
    convertOldNameToNewNames("Border", "ShapeBorder", document);
    convertOldNameToNewNames("LineConnector", "LineConnectorSpecification", document);
    convertOldNameToNewNames("CurvedPolylinConnector", "CurvedPolylinConnectorSpecification", document);
    convertOldNameToNewNames("RectPolylinConnector", "RectPolylinConnectorSpecification", document);

    removeNamedElements(document, "PrimaryConceptOWLIndividualPatternRole");
    removeNamedElements(document, "StartShapeGraphicalRepresentation");
    removeNamedElements(document, "EndShapeGraphicalRepresentation");
    removeNamedElements(document, "ArtifactFromShapeGraphicalRepresentation");
    removeNamedElements(document, "ArtifactToShapeGraphicalRepresentation");
    removeNamedElements(document, "PrimaryRepresentationConnectorPatternRole");
    removeNamedElements(document, "PrimaryRepresentationShapePatternRole");
    removeNamedElements(document, "PrimaryConceptObjectPropertyStatementPatternRole");
    removeNamedElements(document, "ToShapePatternRole");
    removeNamedElements(document, "StartShapeGraphicalRepresentation");
    removeNamedElements(document, "EndShapeGraphicalRepresentation");

    // Change all "this"
    for (Content content : document.getDescendants()) {
        if (content instanceof Element) {
            Element element = (Element) content;
            for (Attribute attribute : element.getAttributes()) {
                if (attribute.getValue().startsWith("this")) {
                    if (element.getName().equals("ModelSlot_VirtualModelModelSlot")) {
                        attribute.setValue(attribute.getValue().replace("this", "virtualModelInstance"));
                    }
                    if (element.getName().equals("FMLRTModelSlot")) {
                        attribute.setValue(attribute.getValue().replace("this", "virtualModelInstance"));
                    }
                    if (attribute.getName().equals("virtualModelInstance")) {
                        attribute.setValue(attribute.getValue().replace("this", "virtualModelInstance"));
                    } else {
                        attribute.setValue(attribute.getValue().replace("this", "flexoBehaviourInstance"));
                    }
                }
            }
        }
    }

}

From source file:org.openflexo.foundation.fml.rm.ViewPointResourceImpl.java

License:Open Source License

private static Element createPaletteElementBinding(Element paletteElement, String paletteUri,
        List<Element> dropSchemeElements) {
    Attribute ep = null, ds = null, id = null;
    if (paletteElement.getAttribute("flexoConcept") != null) {
        ep = paletteElement.getAttribute("flexoConcept");
    }/*from   w  w w  . j  a va2s .c o m*/
    if (paletteElement.getAttribute("dropSchemeName") != null) {
        ds = paletteElement.getAttribute("dropSchemeName");
    }
    if (paletteElement.getAttribute("id") != null) {
        id = paletteElement.getAttribute("id");
    }
    if (ep != null && ds != null) {
        Element paletteElementBinding = new Element("FMLDiagramPaletteElementBinding");
        Attribute paletteElementId = new Attribute("paletteElementID",
                paletteUri + "#" + ep.getValue() + id.getValue());
        paletteElementBinding.getAttributes().add(paletteElementId);
        // Find cooresponding dropscheme
        for (Element dropScheme : dropSchemeElements) {
            if (dropScheme.getAttributeValue("name").equals(ds.getValue())
                    && dropScheme.getParentElement().getAttributeValue("name").equals(ep.getValue())) {
                Element dropSchemeRef = new Element("DropScheme");
                dropSchemeRef.setAttribute("idref", dropScheme.getAttributeValue("id"));
                paletteElementBinding.addContent(dropSchemeRef);
            }
        }

        // Update Palette Element, change its name, and remove dropscheme flexo concept informations
        paletteElement.setAttribute("name", ep.getValue() + id.getValue());
        paletteElement.removeAttribute(ep);
        paletteElement.removeAttribute(ds);

        return paletteElementBinding;
    }
    return null;
}

From source file:org.openflexo.foundation.viewpoint.rm.ViewPointResourceImpl.java

License:Open Source License

private static void convertDiagramSpecification16ToVirtualModel17(File file, Document diagram,
        List<File> oldPaletteFiles, List<File> oldExampleDiagramFiles, ViewPointResource viewPointResource) {

    // Create the diagram specification and a virtual model with a diagram typed model slot referencing this diagram specification

    final String ADDRESSED_DIAGRAM_MODEL_SLOT = "AddressedDiagramModelSlot";
    final String MODELSLOT_VIRTUAL_MODEL_MODEL_SLOT = "ModelSlot_VirtualModelModelSlot";
    final String MODELSLOT_TYPED_DIAGRAM_MODEL_SLOT = "ModelSlot_TypedDiagramModelSlot";

    try {/*from   w  w  w.  j  av a2 s  . co  m*/
        String diagramName = file.getName().replace(".xml", "");
        // Create a folder that contains the diagram specification
        File diagramSpecificationFolder = new File(
                file.getParentFile() + "/" + diagramName + ".diagramspecification");
        diagramSpecificationFolder.mkdir();

        // Retrieve diagram drop schemes
        Iterator<Element> dropSchemeElements = diagram.getDescendants(new ElementFilter("DropScheme"));
        List<Element> dropSchemes = IteratorUtils.toList(dropSchemeElements);

        // Retrieve Diagram Model slots references
        Iterator<? extends Content> thisModelSlotsIterator = diagram.getDescendants(
                new ElementFilter("DiagramModelSlot").or(new ElementFilter(ADDRESSED_DIAGRAM_MODEL_SLOT)));
        List<Element> thisModelSlots = IteratorUtils.toList(thisModelSlotsIterator);

        // Retrieve the DiagramModelSlot (this), and transform it to a virtual model slot with a virtual model uri
        int thisID = 0;
        String newThisUri = viewPointResource.getURI() + "/" + diagramName;
        String diagramSpecificationURI = newThisUri + "/" + diagramName + ".diagramspecification";
        Element typedDiagramModelSlot = null;
        boolean foundThis = false;
        for (Element thisMs : thisModelSlots) {
            // Retriev the ID and URI of this DiagramModelSlot
            if (thisMs.getAttribute("name") != null && thisMs.getAttributeValue("name").equals("this")
                    && !foundThis) {
                // Store its ID and its URI
                thisID = thisMs.getAttribute("id").getIntValue();
                if (thisMs.getAttributeValue("virtualModelURI") != null) {
                    newThisUri = thisMs.getAttributeValue("virtualModelURI");
                    thisMs.removeAttribute("virtualModelURI");
                    thisMs.removeAttribute("name");
                    thisMs.getAttribute("id").setName("idref");
                    thisMs.setAttribute("idref", Integer.toString(thisID));
                }
                // Replace by a Typed model slot
                typedDiagramModelSlot = new Element(MODELSLOT_TYPED_DIAGRAM_MODEL_SLOT);
                typedDiagramModelSlot.setAttribute("metaModelURI", diagramSpecificationURI);
                typedDiagramModelSlot.setAttribute("name", "typedDiagramModelSlot");
                typedDiagramModelSlot.setAttribute("id", Integer.toString(computeNewID(diagram)));
                foundThis = true;
            }
        }
        // Replace the Diagram Model Slot by a Virtual Model Model slot
        for (Element thisMs : thisModelSlots) {
            if (hasSameID(thisMs, thisID) && thisMs.getName().equals("DiagramModelSlot")) {
                thisMs.setName("VirtualModelModelSlot");
                thisMs.getAttributes().add(new Attribute("virtualModelURI", newThisUri));
                thisMs.getAttributes().add(new Attribute("name", "virtualModelInstance"));
                thisMs.getAttributes().add(new Attribute("id", Integer.toString(thisID)));
                thisMs.removeAttribute("idref");
            }
        }
        // Update ids for all model slots
        Iterator<? extends Content> diagramModelSlotsIterator = diagram.getDescendants(
                new ElementFilter("DiagramModelSlot").or(new ElementFilter(ADDRESSED_DIAGRAM_MODEL_SLOT)));
        List<Element> thisDiagramModelSlots = IteratorUtils.toList(diagramModelSlotsIterator);
        for (Element diagramMs : thisDiagramModelSlots) {
            if (diagramMs.getAttribute("id") != null && typedDiagramModelSlot != null) {
                diagramMs.setAttribute("id", typedDiagramModelSlot.getAttributeValue("id"));
            }
            if (diagramMs.getAttribute("idref") != null) {
                // Change to TypedDiagramModelSlot
                if (diagramMs.getParentElement().getName().equals("AddShape")
                        || diagramMs.getParentElement().getName().equals("AddConnector")
                        || diagramMs.getParentElement().getName().equals("AddDiagram")
                        || diagramMs.getParentElement().getName().equals("ContainedShapePatternRole")
                        || diagramMs.getParentElement().getName().equals("ContainedConnectorPatternRole")
                        || diagramMs.getParentElement().getName().equals("ContainedDiagramPatternRole")) {
                    if (typedDiagramModelSlot.getAttributeValue("id") != null) {
                        diagramMs.setAttribute("idref", typedDiagramModelSlot.getAttributeValue("id"));
                        diagramMs.setName("TypedDiagramModelSlot");
                    }
                } else {
                    diagramMs.setName(MODELSLOT_VIRTUAL_MODEL_MODEL_SLOT);
                }
            }
        }
        for (Content content : diagram.getDescendants()) {
            if (content instanceof Element) {
                Element element = (Element) content;
                if (element.getName().equals("AddShape") || element.getName().equals("AddConnector")
                        || element.getName().equals("AddDiagram")) {
                    if (element.getChild("TypedDiagramModelSlot") == null
                            && element.getChild("AddressedDiagramModelSlot") == null) {
                        Element adressedMsElement = new Element("TypedDiagramModelSlot");
                        Attribute newIdRefAttribute = new Attribute("idref",
                                typedDiagramModelSlot.getAttributeValue("id"));
                        adressedMsElement.getAttributes().add(newIdRefAttribute);
                        element.addContent(adressedMsElement);
                    }
                }
            }
        }

        // Update DiagramSpecification URI
        for (Content content : diagram.getDescendants()) {
            if (content instanceof Element) {
                Element element = (Element) content;
                if (element.getAttribute("diagramSpecificationURI") != null) {
                    String oldDiagramSpecificationUri = element.getAttributeValue("diagramSpecificationURI");
                    String diagramSpecificationName = oldDiagramSpecificationUri
                            .substring(oldDiagramSpecificationUri.lastIndexOf("/"));
                    String newDiagramSpecificationUri = oldDiagramSpecificationUri + diagramSpecificationName
                            + ".diagramspecification";
                    element.getAttribute("diagramSpecificationURI").setValue(newDiagramSpecificationUri);
                }
            }
        }

        // Change all the "diagram" binding with "this", and "toplevel" with typedDiagramModelSlot.topLevel" in case of not
        // DropSchemeAction
        for (Content content : diagram.getDescendants()) {
            if (content instanceof Element) {
                Element element = (Element) content;
                for (Attribute attribute : element.getAttributes()) {
                    if (attribute.getValue().startsWith("diagram")) {
                        attribute.setValue(attribute.getValue().replace("diagram", "this"));
                    }
                    if (attribute.getValue().startsWith("topLevel")) {
                        boolean diagramScheme = false;
                        Element parentElement = element.getParentElement();
                        while (parentElement != null) {
                            if (parentElement.getName().equals("DropScheme")
                                    || parentElement.getName().equals("LinkScheme")) {
                                diagramScheme = true;
                            }
                            parentElement = parentElement.getParentElement();
                        }
                        if (!diagramScheme) {
                            attribute.setValue(attribute.getValue().replace("topLevel",
                                    "virtualModelInstance.typedDiagramModelSlot"));
                        }
                    }
                }
            }
        }

        // Create the diagram specificaion xml file
        File diagramSpecificationFile = new File(diagramSpecificationFolder, file.getName());
        Document diagramSpecification = new Document();
        Element rootElement = new Element("DiagramSpecification");
        Attribute name = new Attribute("name", diagramName);
        Attribute diagramSpecificationURIAttribute = new Attribute("uri", diagramSpecificationURI);
        diagramSpecification.addContent(rootElement);
        rootElement.getAttributes().add(name);
        rootElement.getAttributes().add(diagramSpecificationURIAttribute);
        XMLUtils.saveXMLFile(diagramSpecification, diagramSpecificationFile);

        // Copy the palette files inside diagram specification repository
        ArrayList<File> newPaletteFiles = new ArrayList<File>();
        for (File paletteFile : oldPaletteFiles) {
            File newFile = new File(diagramSpecificationFolder + "/" + paletteFile.getName());
            FileUtils.rename(paletteFile, newFile);
            newPaletteFiles.add(newFile);
            Document palette = XMLUtils.readXMLFile(newFile);
            Attribute diagramSpecUri = new Attribute("diagramSpecificationURI", diagramSpecificationURI);
            palette.getRootElement().getAttributes().add(diagramSpecUri);
            convertNames16ToNames17(palette);
            XMLUtils.saveXMLFile(palette, newFile);
        }

        // Copy the example diagram files inside diagram specification repository
        ArrayList<File> newExampleDiagramFiles = new ArrayList<File>();
        for (File exampleDiagramFile : oldExampleDiagramFiles) {
            File newFile = new File(diagramSpecificationFolder + "/" + exampleDiagramFile.getName());
            FileUtils.rename(exampleDiagramFile, newFile);
            newExampleDiagramFiles.add(newFile);
            Document exampleDiagram = XMLUtils.readXMLFile(newFile);
            exampleDiagram.getRootElement().setAttribute("uri",
                    diagramSpecificationURI + "/" + exampleDiagram.getRootElement().getAttributeValue("name"));
            Attribute diagramSpecUri = new Attribute("diagramSpecificationURI", diagramSpecificationURI);
            exampleDiagram.getRootElement().getAttributes().add(diagramSpecUri);
            exampleDiagram.getRootElement().setAttribute("uri",
                    diagramSpecificationURI + "/" + exampleDiagram.getRootElement().getAttributeValue("name"));
            convertNames16ToNames17(exampleDiagram);
            XMLUtils.saveXMLFile(exampleDiagram, newFile);
        }

        // Update the diagram palette element bindings
        ArrayList<Element> paletteElementBindings = new ArrayList<Element>();
        for (File paletteFile : newPaletteFiles) {
            Document palette = XMLUtils.readXMLFile(paletteFile);
            String paletteUri = diagramSpecificationURI + "/"
                    + palette.getRootElement().getAttribute("name").getValue() + ".palette";
            Iterator<? extends Content> paletteElements = palette
                    .getDescendants(new ElementFilter("DiagramPaletteElement"));
            while (paletteElements.hasNext()) {
                Element paletteElement = (Element) paletteElements.next();
                Element binding = createPaletteElementBinding(paletteElement, paletteUri, dropSchemes);
                if (binding != null) {
                    paletteElementBindings.add(binding);
                }
            }
            XMLUtils.saveXMLFile(palette, paletteFile);
        }
        // Add the Palette Element Bindings to the TypedDiagramModelSlot
        if (!paletteElementBindings.isEmpty()) {
            typedDiagramModelSlot.addContent(paletteElementBindings);
        }
        if (typedDiagramModelSlot != null) {
            diagram.getRootElement().addContent(typedDiagramModelSlot);
        }

        // Update names
        convertNames16ToNames17(diagram);
        convertOldNameToNewNames("DiagramSpecification", "VirtualModel", diagram);

        // Save the files
        XMLUtils.saveXMLFile(diagram, file);

    } catch (JDOMException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.openflexo.foundation.viewpoint.rm.ViewPointResourceImpl.java

License:Open Source License

private static void convertNames16ToNames17(Document document) {

    // Convert common properties
    addProperty("userID", "FLX", document, null);

    // Edition Patterns
    // Edition patterns name
    convertOldNameToNewNames("EditionPattern", "FlexoConcept", document);
    // Parent pattern role is no more an attribute but an element
    IteratorIterable<? extends Content> fcElementsIterator = document
            .getDescendants(new ElementFilter("FlexoConcept"));
    List<Element> fcElements = IteratorUtils.toList(fcElementsIterator);

    for (Element fc : fcElements) {
        if (fc.getAttribute("parentEditionPattern") != null) {
            Element parentEp = new Element("ParentFlexoConcept");
            Attribute parentIdRef = new Attribute("idref",
                    getFlexoConceptID(document, fc.getAttributeValue("parentEditionPattern")));
            parentEp.getAttributes().add(parentIdRef);
            fc.removeAttribute("parentEditionPattern");
            fc.addContent(parentEp);//from   w w w.  j  a  v  a2s  . com
        }
    }

    // Pattern Roles
    // Pattern roles properties
    changePropertyName("editionPatternTypeURI", "flexoConceptTypeURI", document,
            "ContainedEditionPatternInstancePatternRole");
    changePropertyName("editionPatternTypeURI", "flexoConceptTypeURI", document,
            "AddressedSelectEditionPatternInstance");
    changePropertyName("editionPatternTypeURI", "flexoConceptTypeURI", document,
            "SelectEditionPatternInstance");
    changePropertyName("editionPatternTypeURI", "flexoConceptTypeURI", document,
            "EditionPatternInstanceParameter");
    changePropertyName("paletteElementID", "paletteElementId", document, "FMLDiagramPaletteElementBinding");
    changePropertyName("editionPattern", "flexoConcept", document, "PaletteElement");
    removeProperties("patternRole", document);
    removeProperty("className", document, "DrawingGraphicalRepresentation");
    removeProperty("className", document, "ShapeGraphicalRepresentation");
    removeProperty("className", document, "ConnectorGraphicalRepresentation");
    // Pattern roles name
    convertOldNameToNewNames("ContainedEditionPatternInstancePatternRole", "FlexoConceptInstanceRole",
            document);
    convertOldNameToNewNames("EditionPatternInstancePatternRole", "FlexoConceptInstanceRole", document);
    convertOldNameToNewNames("ContainedShapePatternRole", "ShapeRole", document);
    convertOldNameToNewNames("ShapePatternRole", "ShapeRole", document);
    convertOldNameToNewNames("ContextShapePatternRole", "ShapeRole", document);
    convertOldNameToNewNames("ParentShapePatternRole", "ParentShapeRole", document);
    convertOldNameToNewNames("ContainedEMFObjectIndividualPatternRole", "EMFObjectIndividualRole", document);
    convertOldNameToNewNames("EMFObjectIndividualPatternRole", "EMFObjectIndividualRole", document);
    convertOldNameToNewNames("ContainedConnectorPatternRole", "ConnectorRole", document);
    convertOldNameToNewNames("ConnectorPatternRole", "ConnectorRole", document);
    convertOldNameToNewNames("ContainedOWLIndividualPatternRole", "OWLIndividualRole", document);
    convertOldNameToNewNames("OWLIndividualPatternRole", "OWLIndividualRole", document);
    convertOldNameToNewNames("ContainedObjectPropertyStatementPatternRole", "ObjectPropertyStatementRole",
            document);
    convertOldNameToNewNames("ObjectPropertyStatementPatternRole", "ObjectPropertyStatementRole", document);
    convertOldNameToNewNames("ContainedDataPropertyStatementPatternRole", "DataPropertyStatementRole",
            document);
    convertOldNameToNewNames("DataPropertyStatementPatternRole", "DataPropertyStatementRole", document);
    convertOldNameToNewNames("ContainedExcelCellPatternRole", "ExcelCellRole", document);
    convertOldNameToNewNames("ExcelCellPatternRole", "ExcelCellRole", document);
    convertOldNameToNewNames("ContainedExcelSheetPatternRole", "ExcelSheetRole", document);
    convertOldNameToNewNames("ExcelSheetPatternRole", "ExcelSheetRole", document);
    convertOldNameToNewNames("ContainedExcelRowPatternRole", "ExcelRowRole", document);
    convertOldNameToNewNames("ExcelRowPatternRole", "ExcelRowRole", document);
    convertOldNameToNewNames("ContainedDiagramPatternRole", "DiagramRole", document);
    convertOldNameToNewNames("DiagramPatternRole", "DiagramRole", document);
    convertOldNameToNewNames("ContainedXMLIndividualPatternRole", "XMLIndividualRole", document);
    convertOldNameToNewNames("XMLIndividualPatternRole", "XMLIndividualRole", document);
    convertOldNameToNewNames("ContainedXSIndividualPatternRole", "XSIndividualRole", document);
    convertOldNameToNewNames("XSIndividualPatternRole", "XSIndividualRole", document);
    convertOldNameToNewNames("ContainedXSClassPatternRole", "XSClassRole", document);
    convertOldNameToNewNames("XSClassPatternRole", "XSClassRole", document);

    // Actions
    convertOldNameToNewNames("EditionPatternInstanceParameter", "FlexoConceptInstanceParameter", document);
    convertOldNameToNewNames("MatchEditionPatternInstance", "MatchFlexoConceptInstance", document);
    convertOldNameToNewNames("CreateEditionPatternInstanceParameter", "CreateFlexoConceptInstanceParameter",
            document);
    // Retrieve Fetch Actions
    IteratorIterable<? extends Content> fetchElementsIterator = document
            .getDescendants(new ElementFilter("FetchRequestIterationAction"));
    List<Element> fetchElements = IteratorUtils.toList(fetchElementsIterator);
    for (Element fetchElement : fetchElements) {
        for (Element child : fetchElement.getChildren()) {
            if (child.getName().equals("AddressedSelectEditionPatternInstance")) {
                child.setName("FetchRequest_SelectFlexoConceptInstance");
            }
            if (child.getName().equals("AddressedSelectEMFObjectIndividual")) {
                child.setName("FetchRequest_SelectEMFObjectIndividual");
            }
            if (child.getName().equals("AddressedSelectIndividual")) {
                child.setName("FetchRequest_SelectIndividual");
            }
            if (child.getName().equals("AddressedSelectExcelCell")) {
                child.setName("FetchRequest_SelectExcelCell");
            }
            if (child.getName().equals("AddressedSelectExcelRow")) {
                child.setName("FetchRequest_SelectExcelRow");
            }
            if (child.getName().equals("AddressedSelectExcelSheet")) {
                child.setName("FetchRequest_SelectExcelSheet");
            }
            if (child.getName().equals("AddressedSelectEditionPatternInstance")) {
                child.setName("FetchRequest_SelectFlexoConceptInstance");
            }
        }
    }
    // Built-in actions
    convertOldNameToNewNames("DeclarePatternRole", "DeclareFlexoRole", document);
    convertOldNameToNewNames("AddEditionPatternInstance", "AddFlexoConceptInstance", document);
    convertOldNameToNewNames("AddEditionPatternInstanceParameter", "AddFlexoConceptInstanceParameter",
            document);
    convertOldNameToNewNames("AddressedSelectEditionPatternInstance", "SelectFlexoConceptInstance", document);
    convertOldNameToNewNames("AddressedSelectFlexoConceptInstance", "SelectFlexoConceptInstance", document);
    convertOldNameToNewNames("SelectEditionPatternInstance", "SelectFlexoConceptInstance", document);

    // Model Slots
    for (Content content : document.getDescendants()) {
        if (content instanceof Element) {
            Element element = (Element) content;
            if ((element.getParentElement() != null)
                    && (element.getParentElement().getName().equals("DiagramSpecification")
                            || element.getParentElement().getName().equals("VirtualModel"))) {
                if (element.getName().equals("EMFModelSlot")) {
                    element.setName("ModelSlot_EMFModelSlot");
                } else if (element.getName().equals("XMLModelSlot")) {
                    element.setName("ModelSlot_XMLModelSlot");
                } else if (element.getName().equals("XSDModelSlot")) {
                    element.setName("ModelSlot_XSDModelSlot");
                } else if (element.getName().equals("BasicExcelModelSlot")) {
                    element.setName("ModelSlot_BasicExcelModelSlot");
                } else if (element.getName().equals("SemanticsExcelModelSlot")) {
                    element.setName("ModelSlot_SemanticsExcelModelSlot");
                } else if (element.getName().equals("BasicPowerpointModelSlot")) {
                    element.setName("ModelSlot_SemanticsPowerpointModelSlot");
                } else if (element.getName().equals("OWLModelSlot")) {
                    element.setName("ModelSlot_OWLModelSlot");
                } else if (element.getName().equals("VirtualModelModelSlot")) {
                    element.setName("ModelSlot_VirtualModelModelSlot");
                }
            } else {
                if (element.getName().equals("AddressedEMFModelSlot")) {
                    element.setName("EMFModelSlot");
                } else if (element.getName().equals("AddressedXMLModelSlot")) {
                    element.setName("XMLModelSlot");
                } else if (element.getName().equals("AddressedXSDModelSlot")) {
                    element.setName("XSDModelSlot");
                } else if (element.getName().equals("AddressedBasicExcelModelSlot")) {
                    element.setName("BasicExcelModelSlot");
                } else if (element.getName().equals("AddressedSemanticsExcelModelSlot")) {
                    element.setName("SemanticsExcelModelSlot");
                } else if (element.getName().equals("AddressedBasicPowerpointModelSlot")) {
                    element.setName("BasicPowerpointModelSlot");
                } else if (element.getName().equals("AddressedSemanticsPowerpointModelSlot")) {
                    element.setName("SemanticsPowerpointModelSlot");
                } else if (element.getName().equals("AddressedOWLModelSlot")) {
                    element.setName("OWLModelSlot");
                } else if (element.getName().equals("AddressedDiagramModelSlot")) {
                    element.setName("TypedDiagramModelSlot");
                } else if (element.getName().equals("AddressedVirtualModelModelSlot")) {
                    element.setName("VirtualModelModelSlot");
                }
            }
        }
    }

    // Palettes/ExampleDiagrams
    // Retrieve Connector GRs
    IteratorIterable<? extends Content> connectorGRElementsIterator = document
            .getDescendants(new ElementFilter("ConnectorGraphicalRepresentation"));
    List<Element> connectorGRElements = IteratorUtils.toList(connectorGRElementsIterator);
    for (Element connectorGRElement : connectorGRElements) {
        Element grSpec = null;
        if (connectorGRElement.getChild("RectPolylinConnector") != null) {
            grSpec = connectorGRElement.getChild("RectPolylinConnector");
        } else if (connectorGRElement.getChild("LineConnector") != null) {
            grSpec = connectorGRElement.getChild("LineConnector");
        } else if (connectorGRElement.getChild("CurvedPolylinConnector") != null) {
            grSpec = connectorGRElement.getChild("CurvedPolylinConnector");
        } else if (connectorGRElement.getChild("ArcConnector") != null) {
            grSpec = connectorGRElement.getChild("ArcConnector");
        }
        if (connectorGRElement.getAttribute("startSymbol") != null) {
            Attribute startSymbol = new Attribute("startSymbol",
                    connectorGRElement.getAttributeValue("startSymbol"));
            grSpec.getAttributes().add(startSymbol);
            connectorGRElement.removeAttribute("startSymbol");
        }
        if (connectorGRElement.getAttribute("endSymbol") != null) {
            Attribute endSymbol = new Attribute("endSymbol", connectorGRElement.getAttributeValue("endSymbol"));
            grSpec.getAttributes().add(endSymbol);
            connectorGRElement.removeAttribute("endSymbol");
        }
        if (connectorGRElement.getAttribute("middleSymbol") != null) {
            Attribute middleSymbol = new Attribute("middleSymbol",
                    connectorGRElement.getAttributeValue("middleSymbol"));
            grSpec.getAttributes().add(middleSymbol);
            connectorGRElement.removeAttribute("middleSymbol");
        }
        if (connectorGRElement.getAttribute("startSymbolSize") != null) {
            Attribute startSymbolSize = new Attribute("startSymbolSize",
                    connectorGRElement.getAttributeValue("startSymbolSize"));
            grSpec.getAttributes().add(startSymbolSize);
            connectorGRElement.removeAttribute("startSymbolSize");
        }
        if (connectorGRElement.getAttribute("endSymbolSize") != null) {
            Attribute endSymbolSize = new Attribute("endSymbolSize",
                    connectorGRElement.getAttributeValue("endSymbolSize"));
            grSpec.getAttributes().add(endSymbolSize);
            connectorGRElement.removeAttribute("endSymbolSize");
        }
        if (connectorGRElement.getAttribute("middleSymbolSize") != null) {
            Attribute middleSymbolSize = new Attribute("middleSymbolSize",
                    connectorGRElement.getAttributeValue("middleSymbolSize"));
            grSpec.getAttributes().add(middleSymbolSize);
            connectorGRElement.removeAttribute("middleSymbolSize");
        }
        if (connectorGRElement.getAttribute("relativeMiddleSymbolLocation") != null) {
            Attribute relativeMiddleSymbolLocation = new Attribute("relativeMiddleSymbolLocation",
                    connectorGRElement.getAttributeValue("relativeMiddleSymbolLocation"));
            grSpec.getAttributes().add(relativeMiddleSymbolLocation);
            connectorGRElement.removeAttribute("relativeMiddleSymbolLocation");
        }
    }

    convertOldNameToNewNames("Palette", "DiagramPalette", document);
    convertOldNameToNewNames("PaletteElement", "DiagramPaletteElement", document);
    convertOldNameToNewNames("Shema", "Diagram", document);
    convertOldNameToNewNames("ContainedShape", "Shape", document);
    convertOldNameToNewNames("ContainedConnector", "Connector", document);
    convertOldNameToNewNames("FromShape", "StartShape", document);
    convertOldNameToNewNames("ToShape", "EndShape", document);
    convertOldNameToNewNames("Border", "ShapeBorder", document);
    convertOldNameToNewNames("LineConnector", "LineConnectorSpecification", document);
    convertOldNameToNewNames("CurvedPolylinConnector", "CurvedPolylinConnectorSpecification", document);
    convertOldNameToNewNames("RectPolylinConnector", "RectPolylinConnectorSpecification", document);

    removeNamedElements(document, "PrimaryConceptOWLIndividualPatternRole");
    removeNamedElements(document, "StartShapeGraphicalRepresentation");
    removeNamedElements(document, "EndShapeGraphicalRepresentation");
    removeNamedElements(document, "ArtifactFromShapeGraphicalRepresentation");
    removeNamedElements(document, "ArtifactToShapeGraphicalRepresentation");
    removeNamedElements(document, "PrimaryRepresentationConnectorPatternRole");
    removeNamedElements(document, "PrimaryRepresentationShapePatternRole");
    removeNamedElements(document, "PrimaryConceptObjectPropertyStatementPatternRole");
    removeNamedElements(document, "ToShapePatternRole");
    removeNamedElements(document, "StartShapeGraphicalRepresentation");
    removeNamedElements(document, "EndShapeGraphicalRepresentation");

    // Change all "this"
    for (Content content : document.getDescendants()) {
        if (content instanceof Element) {
            Element element = (Element) content;
            for (Attribute attribute : element.getAttributes()) {
                if (attribute.getValue().startsWith("this")) {
                    if (element.getName().equals("ModelSlot_VirtualModelModelSlot")) {
                        attribute.setValue(attribute.getValue().replace("this", "virtualModelInstance"));
                    }
                    if (element.getName().equals("VirtualModelModelSlot")) {
                        attribute.setValue(attribute.getValue().replace("this", "virtualModelInstance"));
                    }
                    if (attribute.getName().equals("virtualModelInstance")) {
                        attribute.setValue(attribute.getValue().replace("this", "virtualModelInstance"));
                    } else {
                        attribute.setValue(attribute.getValue().replace("this", "flexoBehaviourInstance"));
                    }
                }
            }
        }
    }

}

From source file:org.rometools.feed.module.cc.io.CCModuleGenerator.java

License:Open Source License

public void generate(Module module, Element element) {
    Element root = element;
    while (root.getParentElement() != null) {
        root = root.getParentElement();// w w w  .  j  a  v  a2  s  . c o m
    }
    if (root.getNamespace().equals(RDF) || root.getNamespace().equals(RSS)) {
        generateRSS1((CreativeCommons) module, element);
    } else {
        generateRSS2((CreativeCommons) module, element);
    }
}

From source file:org.rometools.feed.module.cc.io.CCModuleGenerator.java

License:Open Source License

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

    System.out.println(element.getName());
    if (element.getName().equals("channel")) {
        // Do all licenses list.
        License[] all = module.getAllLicenses();
        for (int i = 0; i < all.length; i++) {
            Element license = new Element("License", RSS1);
            license.setAttribute("about", all[i].getValue(), RDF);
            License.Behaviour[] permits = all[i].getPermits();
            for (int j = 0; permits != null && j < permits.length; j++) {
                Element permit = new Element("permits", RSS1);
                permit.setAttribute("resource", permits[j].toString(), RDF);
                license.addContent(permit);
            }/*w  ww. jav  a2s  .c o m*/
            License.Behaviour[] requires = all[i].getPermits();
            for (int j = 0; requires != null && j < requires.length; j++) {
                Element permit = new Element("requires", RSS1);
                permit.setAttribute("resource", permits[j].toString(), RDF);
                license.addContent(permit);
            }
            System.out.println("Is Root?" + element.getParentElement());
            element.getParentElement().addContent(license);
        }
    }

    //Do local licenses
    License[] licenses = module.getLicenses();
    for (int i = 0; i < licenses.length; i++) {
        Element license = new Element("license", RSS1);
        license.setAttribute("resource", licenses[i].getValue(), RDF);
        element.addContent(license);
    }

}

From source file:org.rometools.feed.module.cc.io.ModuleParserRSS1.java

License:Open Source License

public Module parse(Element element) {
    CreativeCommonsImpl module = new CreativeCommonsImpl();
    {//from  w ww . ja  va2 s .  c o  m
        // Parsing Channel level.
        Element root = element;
        while (root.getParentElement() != null)
            root = root.getParentElement();
        List licenseList = root.getChildren("License", NS);
        ArrayList licenses = new ArrayList();
        Iterator it = licenseList.iterator();
        while (it.hasNext()) {
            Element licenseTag = (Element) it.next();
            String licenseURI = licenseTag.getAttributeValue("about", RDF);
            if (licenseURI == null)
                continue;
            License license = License.findByValue(licenseURI);
            {
                ArrayList permitsValues = new ArrayList();
                ArrayList requiresValues = new ArrayList();
                List permitsTags = licenseTag.getChildren("permits", NS);
                Iterator sit = permitsTags.iterator();
                while (sit.hasNext()) {
                    Element permitTag = (Element) sit.next();
                    permitsValues
                            .add(License.Behaviour.findByValue(permitTag.getAttributeValue("resource", RDF)));
                }
                List requiresTags = licenseTag.getChildren("requires", NS);
                sit = requiresTags.iterator();
                while (sit.hasNext()) {
                    Element requireTag = (Element) sit.next();
                    requiresValues
                            .add(License.Behaviour.findByValue(requireTag.getAttributeValue("resource", RDF)));
                }
                license = new License(licenseURI,
                        (License.Behaviour[]) requiresValues
                                .toArray(new License.Behaviour[requiresValues.size()]),
                        (License.Behaviour[]) permitsValues
                                .toArray(new License.Behaviour[permitsValues.size()]));

            }

            licenses.add(license);
        }
        module.setAllLicenses((License[]) licenses.toArray(new License[0]));
    }
    ArrayList licenses = new ArrayList();
    List licenseTags = element.getChildren("license", NS);
    Iterator lit = licenseTags.iterator();
    while (lit.hasNext()) {
        Element licenseTag = (Element) lit.next();
        licenses.add(License.findByValue(licenseTag.getAttributeValue("resource", RDF)));
    }

    if (licenses.size() > 0) {
        module.setLicenses((License[]) licenses.toArray(new License[licenses.size()]));
    }

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

From source file:org.rometools.feed.module.cc.io.ModuleParserRSS2.java

License:Open Source License

public Module parse(Element element) {
    CreativeCommonsImpl module = new CreativeCommonsImpl();
    //Do channel global
    {/*ww  w. j a va 2 s  .co m*/
        Element root = element;
        while (!root.getName().equals("channel") && !root.getName().equals("feed"))
            root = root.getParentElement();
        ArrayList licenses = new ArrayList();
        List items = null;
        if (root.getName().equals("channel"))
            items = root.getChildren("item");
        else
            items = root.getChildren("entry");

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

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

From source file:org.slc.sli.ingestion.parser.impl.XsdTypeProvider.java

License:Apache License

private boolean isContainedByUnboundedElement(Element e, Element parentElement) {
    // we may be able to remove this method/logic as the SLI-Edfi schema overrides all types
    // that contain unbounded choice to remove them.
    Element immediateParent = e.getParentElement();
    while (!immediateParent.equals(parentElement)) {
        if (UNBOUNDED.equals(immediateParent.getAttributeValue(MAX_OCCURS))) {
            return true;
        }/*from   w w  w. j  av  a 2 s .c o m*/
        immediateParent = immediateParent.getParentElement();
    }
    return false;
}

From source file:org.xcri.types.DescriptiveTextType.java

License:Open Source License

private void processXhtml(Element element) throws InvalidElementException {
    try {/* w w w.  j a  v a2 s . co m*/
        //
        // Check for potentially dangerous elements
        //
        @SuppressWarnings("rawtypes")
        Iterator i = element.getDescendants(new ContentSecurityFilter());
        ArrayList<Element> toRemove = new ArrayList<Element>();
        while (i.hasNext()) {
            Element dangerousElement = (Element) i.next();
            toRemove.add(dangerousElement);
            log.warn("description : content contains potentially dangerous XHTML :"
                    + dangerousElement.getName());
        }

        //
        // If configured to do so, remove elements
        //
        if (ParserConfiguration.getInstance().sanitizeXHTML()) {
            for (Element dangerousElement : toRemove) {
                log.warn("description : removing XHTML element :" + dangerousElement.getName());
                dangerousElement.getParentElement().removeContent(dangerousElement);
            }
        }

        xhtml = element;
        isXhtml = true;

        //
        // Set value to text output of XML
        //
        this.setValue(new XMLOutputter().outputString(xhtml));

    } catch (Exception e) {
        throw new InvalidElementException("Error reading content of description element");
    }
}