Example usage for org.w3c.dom Element setUserData

List of usage examples for org.w3c.dom Element setUserData

Introduction

In this page you can find the example usage for org.w3c.dom Element setUserData.

Prototype

public Object setUserData(String key, Object data, UserDataHandler handler);

Source Link

Document

Associate an object to a key on this node.

Usage

From source file:pl.psnc.ep.rt.web.servlets.CollXMLServlet.java

private static Element createMetadata(Document doc, Publication pub, MetadataServer ms, String repoURL)
        throws RemoteException, DLibraException {

    Element metadata = element(doc, Namespace.COL, "metadata", null);
    metadata.setAttribute("mdml-version", "1.2");

    AttributeValueSet avs = ms.getElementMetadataManager().getAttributeValueSet(pub.getId(),
            AttributeValue.AV_ASSOC_ALL);
    metadata.setUserData(KEY_AVS, avs, null);
    List<AbstractAttributeValue> rootId = getValues(avs, ms, "RootID");
    String contentId = rootId.isEmpty() ? pub.getId().toString() : rootId.get(0).getValue();
    metadata.appendChild(element(doc, Namespace.MD, "content-id", contentId));
    metadata.appendChild(element(doc, Namespace.MD, "repository", repoURL));
    String version = versionCache.get() != null ? versionCache.get().toString()
            : Versioning.whichVersion(pub.getId(), rootId, ms) + "";
    metadata.appendChild(element(doc, Namespace.MD, "version", version));

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm 'CET'");
    String modTime = df.format(pub.getModificationTime());
    metadata.appendChild(element(doc, Namespace.MD, TAG_CREATED, modTime));
    metadata.appendChild(element(doc, Namespace.MD, TAG_REVISED, modTime));

    List<AbstractAttributeValue> languageAV = getValues(avs, ms, "Jezyk");
    metadata.appendChild(element(doc, Namespace.MD, "language",
            languageAV.isEmpty() ? "pl-PL" : languageAV.get(0).getValue()));

    Element license = element(doc, Namespace.MD, "license", null);
    license.setAttribute("url", "http://creativecommons.org/licenses/by/3.0/pl/legalcode");
    metadata.appendChild(license);/* w  w  w  .  j  av a2 s. co  m*/

    List<AbstractAttributeValue> titleAV = getValues(avs, ms, "Tytul");
    metadata.appendChild(
            element(doc, Namespace.MD, "title", titleAV.isEmpty() ? "" : titleAV.get(0).getValue()));

    List<AbstractAttributeValue> subtitleAV = getValues(avs, ms, "Podtytul");
    if (!subtitleAV.isEmpty())
        metadata.appendChild(element(doc, Namespace.MD, "subtitle", subtitleAV.get(0).getValue()));

    List<AbstractAttributeValue> educationLevelListVals = getValues(avs, ms, "EtapEdukacyjny");
    Element educationLevelList = element(doc, Namespace.MD, "education-levellist", null);
    educationLevelList.appendChild(element(doc, Namespace.MD, "education-level",
            educationLevelListVals.isEmpty() ? "" : educationLevelListVals.get(0).getValue()));
    metadata.appendChild(educationLevelList);

    List<AbstractAttributeValue> subjectAV = getValues(avs, ms, "Przedmiot");
    Element subjectlist = element(doc, Namespace.MD, "subjectlist", null);
    for (AbstractAttributeValue subject : subjectAV)
        subjectlist.appendChild(element(doc, Namespace.MD, "subject", subject.getValue()));
    metadata.appendChild(subjectlist);

    List<AbstractAttributeValue> abstractAV = getValues(avs, ms, "Abstrakt");
    metadata.appendChild(
            element(doc, Namespace.MD, "abstract", abstractAV.isEmpty() ? "" : abstractAV.get(0).getValue()));

    Element textbook = element(doc, Namespace.EP, "e-textbook", null);
    textbook.setAttribute("ep:version", EP_VERSION);
    List<AbstractAttributeValue> recipientAV = getValues(avs, ms, "Odbiorca");
    List<AbstractAttributeValue> statusAV = getValues(avs, ms, "StatusTresci");
    List<AbstractAttributeValue> classAV = getValues(avs, ms, "Klasa");
    List<AbstractAttributeValue> volumeAV = getValues(avs, ms, "Tom");
    List<AbstractAttributeValue> stylesheetAV = getValues(avs, ms, "ArkuszStylow");
    List<AbstractAttributeValue> environmentTypeAV = getValues(avs, ms, "SrodowiskoPodrecznika");
    List<AbstractAttributeValue> pubDateAV = getValues(avs, ms, "DataPublikacji");
    List<AbstractAttributeValue> signatureAV = getValues(avs, ms, "Sygnatura");
    List<AbstractAttributeValue> showTechRemarksAV = getValues(avs, ms, "PokazujUwagiTechniczne");
    List<AbstractAttributeValue> learningObjectivesAV = getValues(avs, ms, "CeleKsztalcenia");
    List<AbstractAttributeValue> referencesAV = getValues(avs, ms, "Referencje");
    List<AbstractAttributeValue> editorTypeAV = getValues(avs, ms, "TrybEdytora");

    String recipient = recipientAV.isEmpty() ? null : recipientAV.get(0).getValue();
    String status = statusAV.isEmpty() ? null : statusAV.get(0).getValue();
    textbook.setAttribute("ep:recipient", "Nauczyciel".equals(recipient) ? "teacher" : "student");
    textbook.setAttribute("ep:content-status", "Rozszerzaj\u0105ca".equals(status) ? "expanding"
            : "Uzupe\u0142niaj\u0105ca".equals(status) ? "supplemental" : "canon");
    if (!referencesAV.isEmpty())
        textbook.appendChild(createXMLNode(referencesAV.get(0).getValue(), textbook));
    textbook.appendChild(
            element(doc, Namespace.EP, "class", classAV.isEmpty() ? "" : classAV.get(0).getValue()));
    if (!volumeAV.isEmpty())
        textbook.appendChild(element(doc, Namespace.EP, "volume", volumeAV.get(0).getValue()));
    textbook.appendChild(element(doc, Namespace.EP, "stylesheet",
            stylesheetAV.isEmpty() ? "" : stylesheetAV.get(0).getValue()));
    textbook.appendChild(element(doc, Namespace.EP, "environment-type",
            environmentTypeAV.isEmpty() ? "normal" : environmentTypeAV.get(0).getValue()));
    if (!pubDateAV.isEmpty())
        textbook.appendChild(
                element(doc, Namespace.EP, "publication-date", pubDateAV.get(0).getValue() + " 12:00 CET"));
    textbook.appendChild(createXMLNode(
            "<ep:signature>" + (signatureAV.isEmpty() ? "" : signatureAV.get(0).getValue()) + "</ep:signature>",
            textbook));
    textbook.appendChild(createCover(doc, avs, ms));
    boolean showTechRemarks = showTechRemarksAV.isEmpty() || !"Nie".equals(showTechRemarksAV.get(0).getValue());
    textbook.appendChild(element(doc, Namespace.EP, "show-technical-remarks", "" + showTechRemarks));
    if (!learningObjectivesAV.isEmpty())
        textbook.appendChild(createLearningObjectives(learningObjectivesAV, doc));
    if (!editorTypeAV.isEmpty())
        textbook.appendChild(element(doc, Namespace.EP, "editor", editorTypeAV.get(0).getValue()));

    metadata.appendChild(textbook);
    return metadata;
}