Example usage for org.dom4j QName QName

List of usage examples for org.dom4j QName QName

Introduction

In this page you can find the example usage for org.dom4j QName QName.

Prototype

public QName(String name, Namespace namespace) 

Source Link

Usage

From source file:edu.ucsd.library.xdre.tab.RecordUtil.java

License:Creative Commons License

private static void addRightsHolder(Element o, String copyrightStatus, String rightsHolder) {
    String predicate = null;//from w  ww  .  j a  v  a 2  s.co  m
    String nameClass = null;
    if (copyrightStatus.equals(copyrightPerson)) {
        predicate = "dams:rightsHolderPersonal";
        nameClass = "mads:PersonalName";
    } else if (copyrightStatus.equals(copyrightCorporate) || copyrightStatus.equals(copyrightRegents)) {
        predicate = "dams:rightsHolderCorporate";
        nameClass = "mads:CorporateName";
    }
    if (copyrightStatus.equals(copyrightOther)) {
        predicate = "dams:rightsHolderName";
        nameClass = "mads:Name";
    }
    Element name = o.addElement(predicate, damsURI).addElement(nameClass, madsURI);
    name.addElement("mads:authoritativeLabel", madsURI).setText(rightsHolder);
    Element el = name.addElement("mads:elementList");
    el.addAttribute(new QName("parseType", rdfNS), "Collection");
    el.addElement("mads:FullNameElement", madsURI).addElement("mads:elementValue", madsURI)
            .setText(rightsHolder);
}

From source file:edu.vt.middleware.ldap.dsml.AbstractDsml.java

License:Open Source License

/**
 * This will take an attribute name and it's values and return a DSML
 * attribute element.// w  w w. j a  v  a2 s . com
 *
 * @param  attrName  <code>String</code>
 * @param  attrValues  <code>Set</code>
 * @param  ns  <code>Namespace</code> of DSML
 * @param  elementName  <code>String</code> of the attribute element
 * @param  elementAttrName  <code>String</code> of the attribute element
 * @param  elementValueName  <code>String</code> of the value element
 *
 * @return  <code>Element</code>
 */
protected Element createDsmlAttribute(final String attrName, final Set<?> attrValues, final Namespace ns,
        final String elementName, final String elementAttrName, final String elementValueName) {
    final Element attrElement = DocumentHelper.createElement("");

    if (attrName != null) {

        attrElement.setQName(new QName(elementName, ns));
        if (elementAttrName != null) {
            attrElement.addAttribute(elementAttrName, attrName);
        }
        if (attrValues != null) {
            final Iterator<?> i = attrValues.iterator();
            while (i.hasNext()) {
                final Object rawValue = i.next();
                String value = null;
                boolean isBase64 = false;
                if (rawValue instanceof String) {
                    value = (String) rawValue;
                } else if (rawValue instanceof byte[]) {
                    value = LdapUtil.base64Encode((byte[]) rawValue);
                    isBase64 = true;
                } else {
                    if (this.logger.isWarnEnabled()) {
                        this.logger.warn("Could not cast attribute value as a byte[]" + " or a String");
                    }
                }
                if (value != null) {
                    final Element valueElement = attrElement.addElement(new QName(elementValueName, ns));
                    valueElement.addText(value);
                    if (isBase64) {
                        valueElement.addAttribute("encoding", "base64");
                    }
                }
            }
        }
    }

    return attrElement;
}

From source file:edu.vt.middleware.ldap.dsml.Dsmlv1.java

License:Open Source License

/**
 * This will take the results of a prior LDAP query and convert it to a DSML
 * <code>Document</code>./*w w  w.java2  s . co  m*/
 *
 * @param  result  <code>LdapResult</code>
 *
 * @return  <code>Document</code>
 */
public Document createDsml(final LdapResult result) {
    final Namespace ns = new Namespace("dsml", "http://www.dsml.org/DSML");
    final Document doc = DocumentHelper.createDocument();
    final Element dsmlElement = doc.addElement(new QName("dsml", ns));
    final Element entriesElement = dsmlElement.addElement(new QName("directory-entries", ns));

    // build document object from result
    if (result != null) {
        for (LdapEntry le : result.getEntries()) {
            final Element entryElement = this.createDsmlEntry(new QName("entry", ns), le, ns);
            entriesElement.add(entryElement);
        }
    }

    return doc;
}

From source file:edu.vt.middleware.ldap.dsml.Dsmlv2.java

License:Open Source License

/**
 * This will take the results of a prior LDAP query and convert it to a DSML
 * <code>Document</code>.//from  ww w.  j av  a  2  s.  co m
 *
 * @param  result  <code>LdapResult</code>
 *
 * @return  <code>Document</code>
 */
public Document createDsml(final LdapResult result) {
    final Namespace ns = new Namespace("", "urn:oasis:names:tc:DSML:2:0:core");
    final Document doc = DocumentHelper.createDocument();
    final Element dsmlElement = doc.addElement(new QName("batchResponse", ns));
    final Element entriesElement = dsmlElement.addElement(new QName("searchResponse", ns));

    // build document object from results
    if (result != null) {
        for (LdapEntry le : result.getEntries()) {
            final Element entryElement = this.createDsmlEntry(new QName("searchResultEntry", ns), le, ns);
            entriesElement.add(entryElement);
        }
    }

    final Element doneElement = entriesElement.addElement(new QName("searchResultDone", ns));
    final Element codeElement = doneElement.addElement(new QName("resultCode", ns));
    codeElement.addAttribute("code", "0");

    return doc;
}

From source file:eu.planets_project.pp.plato.xml.LibraryExport.java

License:Open Source License

public Document exportToDocument(LibraryTree lib) {
    Document doc = DocumentHelper.createDocument();

    Element root = doc.addElement("library");

    root.add(xsi);//from   www.  ja  va  2s .c  o m
    root.add(platoLibNS);
    //        root.addAttribute(xsi.getPrefix()+":schemaLocation", "http://www.planets-project.eu/plato plato-2.1.xsd");
    //        root.addAttribute(xsi.getPrefix()+":noNamespaceSchemaLocation", "http://www.ifs.tuwien.ac.at/dp/plato/schemas/plato-2.1.xsd");
    root.addAttribute("name", lib.getName());

    Element rootReq = root.addElement(new QName("requirement", platoLibNS));
    addRequirementProperties(rootReq, lib.getRoot());

    return doc;

}

From source file:eu.planets_project.pp.plato.xml.ProjectExporter.java

License:Open Source License

/**
 * Adds the XML-representation of the given project to the parent <code>projectNode</code>
 *
 * @param p//from   www.  jav  a2 s .  c om
 * @param projectNode
 */
public void addProject(Plan p, Document projectsDoc, List<Integer> uploadIDs, List<Integer> recordIDs) {

    Element projectNode = projectsDoc.getRootElement().addElement(new QName("plan", platoNS));

    // Base64 encoder for binary data
    BASE64Encoder encoder = new BASE64Encoder();

    addChangeLog(p.getChangeLog(), projectNode);

    // Plan state
    projectNode.addElement("state").addAttribute("value", Integer.toString(p.getState().getValue()));

    Element properties = projectNode.addElement("properties");
    addUpload(p.getPlanProperties().getReportUpload(), properties, "report", encoder, uploadIDs);

    // Plan properties
    properties.addAttribute("author", p.getPlanProperties().getAuthor())
            .addAttribute("organization", p.getPlanProperties().getOrganization())
            .addAttribute("name", p.getPlanProperties().getName())
            .addAttribute("privateProject", Boolean.toString(p.getPlanProperties().isPrivateProject()))
            .addAttribute("reportPublic", Boolean.toString(p.getPlanProperties().isReportPublic()));
    addStringElement(properties, "description", p.getPlanProperties().getDescription());
    addStringElement(properties, "owner", p.getPlanProperties().getOwner());
    addChangeLog(p.getPlanProperties().getChangeLog(), properties);

    // Plan Basis
    Element basis = projectNode.addElement("basis");
    basis.addAttribute("identificationCode", p.getProjectBasis().getIdentificationCode());

    addStringElement(basis, "documentTypes", p.getProjectBasis().getDocumentTypes());
    addStringElement(basis, "applyingPolicies", p.getProjectBasis().getApplyingPolicies());
    addStringElement(basis, "designatedCommunity", p.getProjectBasis().getDesignatedCommunity());
    addStringElement(basis, "mandate", p.getProjectBasis().getMandate());
    addStringElement(basis, "organisationalProcedures", p.getProjectBasis().getOrganisationalProcedures());
    addStringElement(basis, "planningPurpose", p.getProjectBasis().getPlanningPurpose());
    addStringElement(basis, "planRelations", p.getProjectBasis().getPlanRelations());
    addStringElement(basis, "preservationRights", p.getProjectBasis().getPreservationRights());
    addStringElement(basis, "referenceToAgreements", p.getProjectBasis().getReferenceToAgreements());

    Element triggers = basis.addElement("triggers");
    if (p.getProjectBasis().getTriggers() != null) {
        addTrigger(triggers, p.getProjectBasis().getTriggers().getNewCollection());
        addTrigger(triggers, p.getProjectBasis().getTriggers().getPeriodicReview());
        addTrigger(triggers, p.getProjectBasis().getTriggers().getChangedEnvironment());
        addTrigger(triggers, p.getProjectBasis().getTriggers().getChangedObjective());
        addTrigger(triggers, p.getProjectBasis().getTriggers().getChangedCollectionProfile());
    }

    Element policyTree = basis.addElement("policyTree");

    addSubPolicyTree(p.getProjectBasis().getPolicyTree().getRoot(), policyTree);

    addChangeLog(p.getProjectBasis().getChangeLog(), basis);

    // Sample Records
    Element samplerecords = projectNode.addElement("sampleRecords");
    addStringElement(samplerecords, "samplesDescription",
            p.getSampleRecordsDefinition().getSamplesDescription());

    Element collectionProfile = samplerecords.addElement("collectionProfile");
    if (p.getSampleRecordsDefinition().getCollectionProfile() != null) {
        addStringElement(collectionProfile, "collectionID",
                p.getSampleRecordsDefinition().getCollectionProfile().getCollectionID());
        addStringElement(collectionProfile, "description",
                p.getSampleRecordsDefinition().getCollectionProfile().getDescription());
        addStringElement(collectionProfile, "expectedGrowthRate",
                p.getSampleRecordsDefinition().getCollectionProfile().getExpectedGrowthRate());
        addStringElement(collectionProfile, "numberOfObjects",
                p.getSampleRecordsDefinition().getCollectionProfile().getNumberOfObjects());
        addStringElement(collectionProfile, "typeOfObjects",
                p.getSampleRecordsDefinition().getCollectionProfile().getTypeOfObjects());
        addStringElement(collectionProfile, "retentionPeriod",
                p.getSampleRecordsDefinition().getCollectionProfile().getRetentionPeriod());

        for (SampleObject rec : p.getSampleRecordsDefinition().getRecords()) {
            Element sampleRecord = samplerecords.addElement("record")
                    .addAttribute("shortName", rec.getShortName()).addAttribute("fullname", rec.getFullname())
                    .addAttribute("contentType", rec.getContentType());

            Element data = sampleRecord.addElement("data");
            if (rec.isDataExistent()) {
                data.addAttribute("hasData", "true");
                data.addAttribute("encoding", "base64");
                if (recordIDs != null) {
                    data.setText("" + rec.getId());
                    recordIDs.add(rec.getId());
                } else {
                    data.setText(encoder.encode(rec.getData().getData()));
                }
                addUpload(rec.getXcdlDescription(), sampleRecord, "xcdlDescription", encoder, uploadIDs);
                addJhoveString(rec, encoder, sampleRecord);
                addFitsInfo(rec, encoder, sampleRecord);
            } else {
                data.addAttribute("hasData", "false");
            }

            Element formatInfo = sampleRecord.addElement("formatInfo")
                    .addAttribute("puid", rec.getFormatInfo().getPuid())
                    .addAttribute("name", rec.getFormatInfo().getName())
                    .addAttribute("version", rec.getFormatInfo().getVersion())
                    .addAttribute("mimeType", rec.getFormatInfo().getMimeType())
                    .addAttribute("defaultExtension", rec.getFormatInfo().getDefaultExtension());
            addChangeLog(rec.getFormatInfo().getChangeLog(), formatInfo);

            addChangeLog(rec.getChangeLog(), sampleRecord);

            addStringElement(sampleRecord, "description", rec.getDescription());
            addStringElement(sampleRecord, "originalTechnicalEnvironment",
                    rec.getOriginalTechnicalEnvironment());

        }
        addChangeLog(p.getSampleRecordsDefinition().getChangeLog(), samplerecords);

        // Requirementsdefinition
        Element rdef = projectNode.addElement("requirementsDefinition");
        addStringElement(rdef, "description", p.getRequirementsDefinition().getDescription());
        Element uploads = rdef.addElement("uploads");
        for (DigitalObject upload : p.getRequirementsDefinition().getUploads()) {
            addUpload(upload, uploads, "upload", encoder, uploadIDs);
        }
        addChangeLog(p.getRequirementsDefinition().getChangeLog(), rdef);

        // Alternatives
        Element alternatives = projectNode.addElement("alternatives");
        addStringElement(alternatives, "description", p.getAlternativesDefinition().getDescription());

        for (Alternative a : p.getAlternativesDefinition().getAlternatives()) {
            /*
             * Export all alternatives (also discarded ones)
             * Indices of the result-set reference only the considered alternatives!
             */
            Element alt = alternatives.addElement("alternative")
                    .addAttribute("discarded", Boolean.toString(a.isDiscarded()))
                    .addAttribute("name", a.getName());
            addStringElement(alt, "description", a.getDescription());
            if (a.getAction() != null) {
                Element action = alt.addElement("action");
                action.addAttribute("shortname", a.getAction().getShortname())
                        .addAttribute("url", a.getAction().getUrl())
                        .addAttribute("actionIdentifier", a.getAction().getActionIdentifier())
                        .addAttribute("info", a.getAction().getInfo())
                        .addAttribute("targetFormat", a.getAction().getTargetFormat())
                        .addAttribute("executable", String.valueOf(a.getAction().isExecutable()));
                addStringElement(action, "descriptor", a.getAction().getDescriptor());
                addStringElement(action, "parameterInfo", a.getAction().getParameterInfo());

                Element params = action.addElement("params");
                if (a.getAction().getParams() != null) {
                    for (Parameter param : a.getAction().getParams()) {
                        params.addElement("param").addAttribute("name", param.getName()).addAttribute("value",
                                param.getValue());
                    }
                }
                addChangeLog(a.getAction().getChangeLog(), action);
            }

            Element resourceDescr = alt.addElement("resourceDescription");
            addStringElement(resourceDescr, "necessaryResources",
                    a.getResourceDescription().getNecessaryResources());
            addStringElement(resourceDescr, "configSettings", a.getResourceDescription().getConfigSettings());
            addStringElement(resourceDescr, "reasonForConsidering",
                    a.getResourceDescription().getReasonForConsidering());
            addChangeLog(a.getResourceDescription().getChangeLog(), resourceDescr);

            Element experiment = alt.addElement("experiment");
            Experiment exp = a.getExperiment();
            addStringElement(experiment, "description", exp.getDescription());
            //addStringElement(experiment, "runDescription", exp.getRunDescription());
            addStringElement(experiment, "settings", exp.getSettings());
            uploads = experiment.addElement("results");
            for (SampleObject record : exp.getResults().keySet()) {
                DigitalObject up = exp.getResults().get(record);
                if (up != null) {
                    // only existing uploads are exported
                    Element upload = addUpload(up, uploads, "result", encoder, uploadIDs);
                    if (upload != null) {
                        upload.addAttribute("key", record.getShortName());
                    }
                }
            }
            //            // */experiment/xcdlDescriptions/xcdlDescription
            //            Element xcdls = experiment.addElement("xcdlDescriptions");
            //            for (SampleObject record : exp.getResults().keySet()) {
            //                DigitalObject result = exp.getResults().get(record);
            //                if (result != null) {
            //                    XcdlDescription x = result.getXcdlDescription();
            //                    if (x != null) {
            //                        // only existing xcdls are exported
            //                        Element upload = addUpload(x, xcdls, "xcdlDescription", encoder, uploadIDs);
            //                        if (upload != null) {
            //                           upload.addAttribute("key", record.getShortName());
            //                        }
            //                    }
            //                }
            //            }
            // export detailed experiment info's
            Element detailedInfos = experiment.addElement("detailedInfos");
            for (SampleObject record : exp.getDetailedInfo().keySet()) {
                DetailedExperimentInfo dinfo = exp.getDetailedInfo().get(record);
                Element detailedInfo = detailedInfos.addElement("detailedInfo")
                        .addAttribute("key", record.getShortName())
                        .addAttribute("successful", "" + dinfo.getSuccessful());
                addStringElement(detailedInfo, "programOutput", dinfo.getProgramOutput());
                addStringElement(detailedInfo, "cpr", dinfo.getCpr());

                Element measurements = detailedInfo.addElement("measurements");
                for (Measurement m : dinfo.getMeasurements().values()) {
                    Element measurement = measurements.addElement("measurement");
                    // measurement.value:
                    String typename = deriveElementname(m.getValue().getClass());

                    Element valueElem = measurement.addElement(typename);
                    //.addAttribute("value", m.getValue().toString());
                    addStringElement(valueElem, "value", m.getValue().toString());
                    addChangeLog(m.getValue().getChangeLog(), valueElem);

                    // measurement.property:
                    Element property = measurement.addElement("property").addAttribute("name",
                            m.getProperty().getName());
                    addScale(m.getProperty().getScale(), property);
                }
            }
            addChangeLog(a.getExperiment().getChangeLog(), experiment);

            addChangeLog(a.getChangeLog(), alt);
        }
        addChangeLog(p.getAlternativesDefinition().getChangeLog(), alternatives);

        // go-nogo - is created in the go-nogo step and need not exist
        if (p.getDecision() != null) {
            Element decision = projectNode.addElement("decision");
            addStringElement(decision, "reason", p.getDecision().getReason());
            addStringElement(decision, "actionNeeded", p.getDecision().getActionNeeded());
            decision.addElement("goDecision").addAttribute("value", p.getDecision().getDecision().name());
            addChangeLog(p.getDecision().getChangeLog(), decision);
        }
        // Evaluation
        Element evaluation = projectNode.addElement("evaluation");
        addStringElement(evaluation, "comment", p.getEvaluation().getComment());
        addChangeLog(p.getEvaluation().getChangeLog(), evaluation);

        // importance weighting
        Element importanceWeighting = projectNode.addElement("importanceWeighting");
        addStringElement(importanceWeighting, "comment", p.getImportanceWeighting().getComment());
        addChangeLog(p.getImportanceWeighting().getChangeLog(), importanceWeighting);

        // Recommendation
        Element recommendation = projectNode.addElement("recommendation");
        if (p.getRecommendation().getAlternative() != null) {
            recommendation.addAttribute("alternativeName", p.getRecommendation().getAlternative().getName());
        }
        addStringElement(recommendation, "reasoning", p.getRecommendation().getReasoning());
        addStringElement(recommendation, "effects", p.getRecommendation().getEffects());
        addChangeLog(p.getRecommendation().getChangeLog(), recommendation);

        // transformation
        Element trafo = projectNode.addElement("transformation");
        addStringElement(trafo, "comment", p.getTransformation().getComment());
        addChangeLog(p.getTransformation().getChangeLog(), trafo);

        // Objectivetree (including weights, evaluation values and transformers)
        Element tree = projectNode.addElement("tree");
        tree.addAttribute("weightsInitialized", "" + p.getTree().isWeightsInitialized());
        if (p.getTree().getRoot() != null)
            addSubTree(p.getTree().getRoot(), tree);
    }

    Element executablePlan = projectNode.addElement("executablePlan");

    try {
        if (p.getExecutablePlanDefinition().getExecutablePlan() != null) {
            Document execPlan = DocumentHelper.parseText(p.getExecutablePlanDefinition().getExecutablePlan());
            Element execPlanRoot = execPlan.getRootElement();
            if (execPlanRoot.hasContent()) {
                Element planWorkflow = executablePlan.addElement("planWorkflow");
                planWorkflow.add(execPlanRoot);
            }
        }

        if (p.getExecutablePlanDefinition().getEprintsExecutablePlan() != null) {
            Document execPlan = DocumentHelper
                    .parseText(p.getExecutablePlanDefinition().getEprintsExecutablePlan());
            Element execPlanRoot = execPlan.getRootElement();
            if (execPlanRoot.hasContent()) {
                //Element planWorkflow = executablePlan.addElement("eprintsPlan");
                executablePlan.add(execPlanRoot);
            }
        }

    } catch (DocumentException e) {
        // if the stored exec. plan is invalid for some reason, we leave the plan out.
        // TODO: HK this should no happen as we write the xml ourselves, but still, 
        // we need a mechanism here to prevent the export if the xml is invalid.
        PlatoLogger.getLogger(this.getClass()).error(e.getMessage(), e);
    }

    // TODO HK how does this here relate to the upper try-catch block and the exception??
    // Smells like a hack!
    ExecutablePlanDefinition plan = p.getExecutablePlanDefinition();
    addStringElement(executablePlan, "objectPath", plan.getObjectPath());
    addStringElement(executablePlan, "toolParameters", plan.getToolParameters());
    addStringElement(executablePlan, "triggersConditions", plan.getTriggersConditions());
    addStringElement(executablePlan, "validateQA", plan.getValidateQA());
    addChangeLog(plan.getChangeLog(), executablePlan);

    Element planDef = projectNode.addElement("planDefinition");
    PlanDefinition pdef = p.getPlanDefinition();
    planDef.addAttribute("currency", pdef.getCurrency());
    addStringElement(planDef, "costsIG", pdef.getCostsIG());
    addStringElement(planDef, "costsPA", pdef.getCostsPA());
    addStringElement(planDef, "costsPE", pdef.getCostsPE());
    addStringElement(planDef, "costsQA", pdef.getCostsQA());
    addStringElement(planDef, "costsREI", pdef.getCostsREI());
    addStringElement(planDef, "costsRemarks", pdef.getCostsRemarks());
    addStringElement(planDef, "costsRM", pdef.getCostsRM());
    addStringElement(planDef, "costsTCO", pdef.getCostsTCO());

    addStringElement(planDef, "responsibleExecution", pdef.getResponsibleExecution());
    addStringElement(planDef, "responsibleMonitoring", pdef.getResponsibleMonitoring());

    triggers = planDef.addElement("triggers");
    if (pdef.getTriggers() != null) {
        addTrigger(triggers, pdef.getTriggers().getNewCollection());
        addTrigger(triggers, pdef.getTriggers().getPeriodicReview());
        addTrigger(triggers, pdef.getTriggers().getChangedEnvironment());
        addTrigger(triggers, pdef.getTriggers().getChangedObjective());
        addTrigger(triggers, pdef.getTriggers().getChangedCollectionProfile());
    }

    addChangeLog(pdef.getChangeLog(), planDef);

}

From source file:eu.scape_project.planning.xml.C3POProfileParser.java

License:Apache License

/**
 * Gets a human readable text description of the most prominent formats in
 * the profile. Traverses the properties of the profile until it finds the
 * format distribution. Then it takes the first two most occurring formats
 * (if existing). It also appends the percentage of conflicted and unknown
 * formats if any.//from ww  w . ja v a 2  s  .c om
 * 
 * @return the human readable description.
 */
public String getTypeOfObjects() {
    int count = Integer.parseInt(this.getObjectsCountInPartition());
    QName name = new QName("format", this.namespace);
    List<Element> properties = this.profile.getRootElement().element("partition").element("properties")
            .elements("property");

    List<Element> items = new ArrayList<Element>();
    for (Element e : properties) {
        if (e.attributeValue("id").equals("format")) {
            items.addAll(e.elements());
            break;
        }
    }

    if (items.isEmpty()) {
        return MISSING;
    }

    StringBuffer response = new StringBuffer();
    String type;
    double tmp;
    double percent;
    if (items.size() >= 1) {
        Element item = items.remove(0);
        type = item.attributeValue("id");
        tmp = Double.parseDouble(item.attributeValue("value"));
        percent = Math.floor((tmp / count) * 100);
        response.append(TYPE_OF_OBJECTS_BEGIN.replace("{1}", percent + "").replace("{2}", type));
    }

    if (items.size() >= 1) {// already removed first
        Element item = items.remove(0);
        type = item.attributeValue("id");
        tmp = Double.parseDouble(item.attributeValue("value"));
        percent = Math.floor((tmp / count) * 100);
        response.append(TYPE_OF_OBJECTS_SECOND.replace("{1}", percent + "").replace("{2}", type));
    }

    for (Object o : items) {
        Element e = (Element) o;
        if (e.attributeValue("id").equals("Conflicted")) {
            tmp = Double.parseDouble(e.attributeValue("value"));
            percent = Math.floor((tmp / count) * 100);
            response.append(TYPE_OF_OBJECTS_CONFLICTS.replace("{1}", percent + ""));
        } else if (e.attributeValue("id").equals("Unknown")) {
            tmp = Double.parseDouble(e.attributeValue("value"));
            percent = Math.floor((tmp / count) * 100);
            response.append(TYPE_OF_OBJECTS_UNKNOWN.replace("{1}", percent + ""));
        }
    }

    return response.toString();
}

From source file:eu.scape_project.planning.xml.PreservationActionPlanGenerator.java

License:Apache License

/**
 * Creates a document for the preservation action plan.
 * //  w  ww .  ja  v a2s  .c  o  m
 * @return the document
 */
private Document createPapDoc() {
    Document doc = DocumentHelper.createDocument();

    Element root = doc.addElement(new QName("preservationActionPlan", platoNS));

    root.add(xsi);
    root.add(platoNS);
    root.addAttribute(xsi.getPrefix() + ":schemaLocation",
            PlanXMLConstants.PLATO_NS + " " + PlanXMLConstants.PAP_SCHEMA);

    // Set version of corresponding schema
    root.addAttribute("version", "1.0");

    return doc;
}

From source file:eu.scape_project.planning.xml.ProjectExporter.java

License:Apache License

/**
 * Adds the XML-representation of the given project to the parent
 * <code>projectNode</code>.
 * //w  ww  .  j  a  v a  2s  .  c o m
 * @param p
 *            the plan to add
 * @param projectsDoc
 *            the document where the plan should be added
 * @param addDigitalObjectData
 *            whether the digital object data should be added to the XML
 * @throws PlanningException
 *             if an error occured during export
 */
public void addProject(Plan p, Document projectsDoc, boolean addDigitalObjectData) throws PlanningException {

    Element projectNode = projectsDoc.getRootElement().addElement(new QName("plan", PLATO_NAMESPACE));

    addChangeLog(p.getChangeLog(), projectNode);

    Element properties = projectNode.addElement("properties");
    addUpload(p.getPlanProperties().getReportUpload(), properties, "report", addDigitalObjectData);

    // Plan state
    properties.addElement("state").addAttribute("value",
            Integer.toString(p.getPlanProperties().getState().getValue()));

    // Plan properties
    properties.addAttribute("author", p.getPlanProperties().getAuthor())
            .addAttribute("organization", p.getPlanProperties().getOrganization())
            .addAttribute("name", p.getPlanProperties().getName())
            .addAttribute("privateProject", Boolean.toString(p.getPlanProperties().isPrivateProject()))
            .addAttribute("reportPublic", Boolean.toString(p.getPlanProperties().isReportPublic()))
            .addAttribute("repositoryIdentifier", p.getPlanProperties().getRepositoryIdentifier())
            .addAttribute("playground", Boolean.toString(p.getPlanProperties().isPlayground()));
    addStringElement(properties, "description", p.getPlanProperties().getDescription());
    addStringElement(properties, "owner", p.getPlanProperties().getOwner());
    addChangeLog(p.getPlanProperties().getChangeLog(), properties);

    // Plan Basis
    Element basis = projectNode.addElement("basis");
    basis.addAttribute("identificationCode", p.getProjectBasis().getIdentificationCode());

    addStringElement(basis, "documentTypes", p.getProjectBasis().getDocumentTypes());
    addStringElement(basis, "applyingPolicies", p.getProjectBasis().getApplyingPolicies());
    addStringElement(basis, "designatedCommunity", p.getProjectBasis().getDesignatedCommunity());
    addStringElement(basis, "mandate", p.getProjectBasis().getMandate());
    addStringElement(basis, "organisationalProcedures", p.getProjectBasis().getOrganisationalProcedures());
    addStringElement(basis, "planningPurpose", p.getProjectBasis().getPlanningPurpose());
    addStringElement(basis, "planRelations", p.getProjectBasis().getPlanRelations());
    addStringElement(basis, "preservationRights", p.getProjectBasis().getPreservationRights());
    addStringElement(basis, "referenceToAgreements", p.getProjectBasis().getReferenceToAgreements());

    Element triggers = basis.addElement("triggers");
    if (p.getProjectBasis().getTriggers() != null) {
        addTrigger(p.getProjectBasis().getTriggers().getNewCollection(), triggers);
        addTrigger(p.getProjectBasis().getTriggers().getPeriodicReview(), triggers);
        addTrigger(p.getProjectBasis().getTriggers().getChangedEnvironment(), triggers);
        addTrigger(p.getProjectBasis().getTriggers().getChangedObjective(), triggers);
        addTrigger(p.getProjectBasis().getTriggers().getChangedCollectionProfile(), triggers);
    }

    Element policyTree = basis.addElement("policyTree");

    addSubPolicyTree(p.getProjectBasis().getPolicyTree().getRoot(), policyTree);

    addChangeLog(p.getProjectBasis().getChangeLog(), basis);

    // Sample Records
    Element samplerecords = projectNode.addElement("sampleRecords");
    addStringElement(samplerecords, "samplesDescription",
            p.getSampleRecordsDefinition().getSamplesDescription());

    Element collectionProfile = samplerecords.addElement("collectionProfile");
    if (p.getSampleRecordsDefinition().getCollectionProfile() != null) {
        addStringElement(collectionProfile, "collectionID",
                p.getSampleRecordsDefinition().getCollectionProfile().getCollectionID());
        addStringElement(collectionProfile, "description",
                p.getSampleRecordsDefinition().getCollectionProfile().getDescription());
        addStringElement(collectionProfile, "expectedGrowthRate",
                p.getSampleRecordsDefinition().getCollectionProfile().getExpectedGrowthRate());
        addStringElement(collectionProfile, "numberOfObjects",
                p.getSampleRecordsDefinition().getCollectionProfile().getNumberOfObjects());
        addStringElement(collectionProfile, "typeOfObjects",
                p.getSampleRecordsDefinition().getCollectionProfile().getTypeOfObjects());
        addStringElement(collectionProfile, "retentionPeriod",
                p.getSampleRecordsDefinition().getCollectionProfile().getRetentionPeriod());
        addUpload(p.getSampleRecordsDefinition().getCollectionProfile().getProfile(), collectionProfile,
                "profile", addDigitalObjectData);
    }

    for (SampleObject rec : p.getSampleRecordsDefinition().getRecords()) {
        Element sampleRecord = addEncodedDigitalObject(rec, samplerecords, "record", addDigitalObjectData);

        if (sampleRecord != null) {
            sampleRecord.addAttribute("shortName", rec.getShortName());
            addStringElement(sampleRecord, "description", rec.getDescription());
            addStringElement(sampleRecord, "originalTechnicalEnvironment",
                    rec.getOriginalTechnicalEnvironment());
        }
    }
    addChangeLog(p.getSampleRecordsDefinition().getChangeLog(), samplerecords);

    // Requirementsdefinition
    Element rdef = projectNode.addElement("requirementsDefinition");
    addStringElement(rdef, "description", p.getRequirementsDefinition().getDescription());
    Element uploads = rdef.addElement("uploads");
    for (DigitalObject upload : p.getRequirementsDefinition().getUploads()) {
        addUpload(upload, uploads, "upload", addDigitalObjectData);
    }
    addChangeLog(p.getRequirementsDefinition().getChangeLog(), rdef);

    // Alternatives
    Element alternatives = projectNode.addElement("alternatives");
    addStringElement(alternatives, "description", p.getAlternativesDefinition().getDescription());

    for (Alternative a : p.getAlternativesDefinition().getAlternatives()) {
        /*
         * Export all alternatives (also discarded ones) Indices of the
         * result-set reference only the considered alternatives!
         */
        Element alt = alternatives.addElement("alternative")
                .addAttribute("discarded", Boolean.toString(a.isDiscarded())).addAttribute("name", a.getName());
        addStringElement(alt, "description", a.getDescription());
        if (a.getAction() != null) {
            Element action = alt.addElement("action");
            action.addAttribute("shortname", a.getAction().getShortname())
                    .addAttribute("url", a.getAction().getUrl())
                    .addAttribute("actionIdentifier", a.getAction().getActionIdentifier())
                    .addAttribute("info", a.getAction().getInfo())
                    .addAttribute("targetFormat", a.getAction().getTargetFormat())
                    .addAttribute("executable", String.valueOf(a.getAction().isExecutable()));
            addStringElement(action, "descriptor", a.getAction().getDescriptor());
            addStringElement(action, "parameterInfo", a.getAction().getParameterInfo());

            Element params = action.addElement("params");
            if (a.getAction().getParams() != null) {
                for (Parameter param : a.getAction().getParams()) {
                    params.addElement("param").addAttribute("name", param.getName()).addAttribute("value",
                            param.getValue());
                }
            }
            addChangeLog(a.getAction().getChangeLog(), action);
        }

        Element resourceDescr = alt.addElement("resourceDescription");
        addStringElement(resourceDescr, "necessaryResources",
                a.getResourceDescription().getNecessaryResources());
        addStringElement(resourceDescr, "configSettings", a.getResourceDescription().getConfigSettings());
        addStringElement(resourceDescr, "reasonForConsidering",
                a.getResourceDescription().getReasonForConsidering());
        addChangeLog(a.getResourceDescription().getChangeLog(), resourceDescr);

        Element experiment = alt.addElement("experiment");
        Experiment exp = a.getExperiment();
        addStringElement(experiment, "description", exp.getDescription());
        addStringElement(experiment, "settings", exp.getSettings());
        addUpload(exp.getWorkflow(), experiment, "workflow", addDigitalObjectData);
        Element results = experiment.addElement("results");
        for (Entry<SampleObject, DigitalObject> entry : exp.getResults().entrySet()) {
            Element result = addUpload(entry.getValue(), results, "result", addDigitalObjectData);
            if (result != null) {
                result.addAttribute("key", entry.getKey().getShortName());
            }
        }

        // // */experiment/xcdlDescriptions/xcdlDescription
        // Element xcdls = experiment.addElement("xcdlDescriptions");
        // for (SampleObject record : exp.getResults().keySet()) {
        // DigitalObject result = exp.getResults().get(record);
        // if (result != null) {
        // XcdlDescription x = result.getXcdlDescription();
        // if (x != null) {
        // // only existing xcdls are exported
        // Element upload = addUpload(x, xcdls, "xcdlDescription",
        // encoder, uploadIDs);
        // if (upload != null) {
        // upload.addAttribute("key", record.getShortName());
        // }
        // }
        // }
        // }

        // export detailed experiment info's
        Element detailedInfos = experiment.addElement("detailedInfos");
        for (SampleObject record : exp.getDetailedInfo().keySet()) {
            DetailedExperimentInfo dinfo = exp.getDetailedInfo().get(record);
            Element detailedInfo = detailedInfos.addElement("detailedInfo")
                    .addAttribute("key", record.getShortName())
                    .addAttribute("successful", "" + dinfo.getSuccessful());
            addStringElement(detailedInfo, "programOutput", dinfo.getProgramOutput());
            addStringElement(detailedInfo, "cpr", dinfo.getCpr());

            Element measurements = detailedInfo.addElement("measurements");
            for (Measurement m : dinfo.getMeasurements().values()) {
                Element measurement = measurements.addElement("measurement");
                measurement.addAttribute("measureId", m.getMeasureId());

                // measurement.value:
                String typename = deriveElementname(m.getValue().getClass());

                Element valueElem = measurement.addElement(typename);
                // .addAttribute("value", m.getValue().toString());
                addStringElement(valueElem, "value", m.getValue().toString());
                addChangeLog(m.getValue().getChangeLog(), valueElem);
            }
        }
        addChangeLog(a.getExperiment().getChangeLog(), experiment);

        addChangeLog(a.getChangeLog(), alt);
    }
    addChangeLog(p.getAlternativesDefinition().getChangeLog(), alternatives);

    // go-nogo - is created in the go-nogo step and need not exist
    if (p.getDecision() != null) {
        Element decision = projectNode.addElement("decision");
        addStringElement(decision, "reason", p.getDecision().getReason());
        addStringElement(decision, "actionNeeded", p.getDecision().getActionNeeded());
        decision.addElement("goDecision").addAttribute("value", p.getDecision().getDecision().name());
        addChangeLog(p.getDecision().getChangeLog(), decision);
    }

    // Evaluation
    Element evaluation = projectNode.addElement("evaluation");
    addStringElement(evaluation, "comment", p.getEvaluation().getComment());
    addChangeLog(p.getEvaluation().getChangeLog(), evaluation);

    // importance weighting
    Element importanceWeighting = projectNode.addElement("importanceWeighting");
    addStringElement(importanceWeighting, "comment", p.getImportanceWeighting().getComment());
    addChangeLog(p.getImportanceWeighting().getChangeLog(), importanceWeighting);

    // Recommendation
    Element recommendation = projectNode.addElement("recommendation");
    if (p.getRecommendation().getAlternative() != null) {
        recommendation.addAttribute("alternativeName", p.getRecommendation().getAlternative().getName());
    }
    addStringElement(recommendation, "reasoning", p.getRecommendation().getReasoning());
    addStringElement(recommendation, "effects", p.getRecommendation().getEffects());
    addChangeLog(p.getRecommendation().getChangeLog(), recommendation);

    // transformation
    Element trafo = projectNode.addElement("transformation");
    addStringElement(trafo, "comment", p.getTransformation().getComment());
    addChangeLog(p.getTransformation().getChangeLog(), trafo);

    // Objectivetree (including weights, evaluation values and
    // transformers)
    Element tree = projectNode.addElement("tree");
    tree.addAttribute("weightsInitialized", "" + p.getTree().isWeightsInitialized());
    if (p.getTree().getRoot() != null) {
        addSubTree(p.getTree().getRoot(), tree);
    }

    // add ExecutablePlanDefinition
    Element executablePlanDef = projectNode.addElement("executablePlan");
    ExecutablePlanDefinition executablePlanDefinition = p.getExecutablePlanDefinition();
    addStringElement(executablePlanDef, "objectPath", executablePlanDefinition.getObjectPath());
    addStringElement(executablePlanDef, "toolParameters", executablePlanDefinition.getToolParameters());
    addStringElement(executablePlanDef, "triggersConditions", executablePlanDefinition.getTriggersConditions());
    addStringElement(executablePlanDef, "validateQA", executablePlanDefinition.getValidateQA());
    addUpload(executablePlanDefinition.getT2flowExecutablePlan(), executablePlanDef, "workflow",
            addDigitalObjectData);
    addChangeLog(executablePlanDefinition.getChangeLog(), executablePlanDef);

    // Export generated preservation action plan
    addPreservationActionPlan(p.getPreservationActionPlan(), projectNode, addDigitalObjectData);

    // Plan definition
    Element planDef = projectNode.addElement("planDefinition");
    PlanDefinition pdef = p.getPlanDefinition();
    planDef.addAttribute("currency", pdef.getCurrency());
    addStringElement(planDef, "costsIG", pdef.getCostsIG());
    addStringElement(planDef, "costsPA", pdef.getCostsPA());
    addStringElement(planDef, "costsPE", pdef.getCostsPE());
    addStringElement(planDef, "costsQA", pdef.getCostsQA());
    addStringElement(planDef, "costsREI", pdef.getCostsREI());
    addStringElement(planDef, "costsRemarks", pdef.getCostsRemarks());
    addStringElement(planDef, "costsRM", pdef.getCostsRM());
    addStringElement(planDef, "costsTCO", pdef.getCostsTCO());

    addStringElement(planDef, "responsibleExecution", pdef.getResponsibleExecution());
    addStringElement(planDef, "responsibleMonitoring", pdef.getResponsibleMonitoring());

    triggers = planDef.addElement("triggers");
    if (pdef.getTriggers() != null) {
        addTrigger(pdef.getTriggers().getNewCollection(), triggers);
        addTrigger(pdef.getTriggers().getPeriodicReview(), triggers);
        addTrigger(pdef.getTriggers().getChangedEnvironment(), triggers);
        addTrigger(pdef.getTriggers().getChangedObjective(), triggers);
        addTrigger(pdef.getTriggers().getChangedCollectionProfile(), triggers);
    }

    addChangeLog(pdef.getChangeLog(), planDef);
}

From source file:ie.cmrc.smtx.base.serialisation.rdfxml.RDFXMLSerialiser.java

License:Apache License

/**
 * Creates an RDF document containing the XML representation of the provided
 * resource/* w  w  w  .  ja  v  a2 s.  c  o  m*/
 * @param resource An {@link RDFXMLisable} instance
 * @param elementSet Specifies the level of information to serialise
 * (see {@link ElementSetName} for more details)
 * @param language Language code. Only annotations in this language will
 * be included in the XML.
 * @return XML document
 */
public static Document makeRDFXMLDocument(RDFXMLisable resource, ElementSetName elementSet, String language) {
    Element rdfElt = DocumentHelper.createElement(new QName("RDF", Namespaces.RDF));
    rdfElt.add(Namespaces.RDF);
    rdfElt.add(Namespaces.RDFS);
    rdfElt.add(Namespaces.OWL);
    rdfElt.add(Namespaces.SKOS);
    rdfElt.add(Namespaces.XSD);

    if (resource != null) {
        Element xmlElement = resource.toXMLElement(elementSet, language);
        if (xmlElement != null)
            rdfElt.add(xmlElement);
    }

    Document doc = DocumentHelper.createDocument(rdfElt);

    return doc;
}