Example usage for org.jdom2 Element addNamespaceDeclaration

List of usage examples for org.jdom2 Element addNamespaceDeclaration

Introduction

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

Prototype

public boolean addNamespaceDeclaration(final Namespace additionalNamespace) 

Source Link

Document

Adds a namespace declarations to this element.

Usage

From source file:org.artifactory.version.converter.NamespaceConverter.java

License:Open Source License

@Override
@SuppressWarnings({ "unchecked" })
public void convert(Document doc) {
    // change the xsd uri and schema location
    String currentXsdUri = ArtifactoryConfigVersion.getCurrent().getXsdUri();
    String currentXsdLocation = ArtifactoryConfigVersion.getCurrent().getXsdLocation();
    Namespace ns = Namespace.getNamespace(currentXsdUri);
    Element root = doc.getRootElement();
    // Check that schema instance namespace is there before adding schema location...
    Namespace schemaInstanceNS = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    List<Namespace> namespaces = root.getAdditionalNamespaces();
    boolean hasSchemaInstanceNS = false;
    for (Namespace namespace : namespaces) {
        // The equality is only on URI so hardcoded prefix does not impact
        if (namespace.equals(schemaInstanceNS)) {
            hasSchemaInstanceNS = true;//  w  w w .j  a  v a  2  s.  c o  m
        }
    }
    if (!hasSchemaInstanceNS) {
        root.addNamespaceDeclaration(schemaInstanceNS);
    }
    root.setAttribute("schemaLocation", currentXsdUri + " " + currentXsdLocation, schemaInstanceNS);

    changeNameSpace(root, ns);
}

From source file:org.goobi.production.export.ExportXmlLog.java

License:Open Source License

/**
 * This method creates a new xml document with process metadata
 * /*from  w  w w . ja va  2 s  .co  m*/
 * @param process the process to export
 * @return a new xml document
 * @throws ConfigurationException
 */
public Document createDocument(Process process, boolean addNamespace) {

    Element processElm = new Element("process");
    Document doc = new Document(processElm);

    processElm.setAttribute("processID", String.valueOf(process.getId()));

    Namespace xmlns = Namespace.getNamespace("http://www.goobi.io/logfile");
    processElm.setNamespace(xmlns);
    // namespace declaration
    if (addNamespace) {

        Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        processElm.addNamespaceDeclaration(xsi);
        Attribute attSchema = new Attribute("schemaLocation",
                "http://www.goobi.io/logfile" + " XML-logfile.xsd", xsi);
        processElm.setAttribute(attSchema);
    }
    // process information

    ArrayList<Element> processElements = new ArrayList<>();
    Element processTitle = new Element("title", xmlns);
    processTitle.setText(process.getTitel());
    processElements.add(processTitle);

    Element project = new Element("project", xmlns);
    project.setText(process.getProjekt().getTitel());
    processElements.add(project);

    Element date = new Element("time", xmlns);
    date.setAttribute("type", "creation date");
    date.setText(String.valueOf(process.getErstellungsdatum()));
    processElements.add(date);

    Element ruleset = new Element("ruleset", xmlns);
    ruleset.setText(process.getRegelsatz().getDatei());
    processElements.add(ruleset);

    Element comment = new Element("comments", xmlns);
    List<LogEntry> log = process.getProcessLog();
    for (LogEntry entry : log) {
        Element commentLine = new Element("comment", xmlns);
        commentLine.setAttribute("type", entry.getType().getTitle());
        commentLine.setAttribute("user", entry.getUserName());
        commentLine.setText(entry.getContent());
        if (StringUtils.isNotBlank(entry.getSecondContent())) {
            comment.setAttribute("secondField", entry.getSecondContent());
        }
        if (StringUtils.isNotBlank(entry.getThirdContent())) {
            comment.setAttribute("thirdField", entry.getThirdContent());
        }
        comment.addContent(commentLine);
    }

    processElements.add(comment);

    if (process.getBatch() != null) {
        Element batch = new Element("batch", xmlns);
        batch.setText(String.valueOf(process.getBatch().getBatchId()));
        if (StringUtils.isNotBlank(process.getBatch().getBatchName())) {
            batch.setAttribute("batchName", process.getBatch().getBatchName());
        }
        if (process.getBatch().getStartDate() != null) {
            batch.setAttribute("startDate", Helper.getDateAsFormattedString(process.getBatch().getStartDate()));
        }

        if (process.getBatch().getEndDate() != null) {
            batch.setAttribute("endDate", Helper.getDateAsFormattedString(process.getBatch().getEndDate()));
        }

        processElements.add(batch);
    }

    List<Element> processProperties = new ArrayList<>();
    List<ProcessProperty> propertyList = PropertyParser.getInstance().getPropertiesForProcess(process);
    for (ProcessProperty prop : propertyList) {
        Element property = new Element("property", xmlns);
        property.setAttribute("propertyIdentifier", prop.getName());
        if (prop.getValue() != null) {
            property.setAttribute("value", prop.getValue());
        } else {
            property.setAttribute("value", "");
        }

        Element label = new Element("label", xmlns);

        label.setText(prop.getName());
        property.addContent(label);
        processProperties.add(property);
    }
    if (processProperties.size() != 0) {
        Element properties = new Element("properties", xmlns);
        properties.addContent(processProperties);
        processElements.add(properties);
    }

    // step information
    Element steps = new Element("steps", xmlns);
    List<Element> stepElements = new ArrayList<>();
    for (Step s : process.getSchritteList()) {
        Element stepElement = new Element("step", xmlns);
        stepElement.setAttribute("stepID", String.valueOf(s.getId()));

        Element steptitle = new Element("title", xmlns);
        steptitle.setText(s.getTitel());
        stepElement.addContent(steptitle);

        Element state = new Element("processingstatus", xmlns);
        state.setText(s.getBearbeitungsstatusAsString());
        stepElement.addContent(state);

        Element begin = new Element("time", xmlns);
        begin.setAttribute("type", "start time");
        begin.setText(s.getBearbeitungsbeginnAsFormattedString());
        stepElement.addContent(begin);

        Element end = new Element("time", xmlns);
        end.setAttribute("type", "end time");
        end.setText(s.getBearbeitungsendeAsFormattedString());
        stepElement.addContent(end);

        if (s.getBearbeitungsbenutzer() != null && s.getBearbeitungsbenutzer().getNachVorname() != null) {
            Element user = new Element("user", xmlns);
            user.setText(s.getBearbeitungsbenutzer().getNachVorname());
            stepElement.addContent(user);
        }
        Element editType = new Element("edittype", xmlns);
        editType.setText(s.getEditTypeEnum().getTitle());
        stepElement.addContent(editType);

        stepElements.add(stepElement);
    }
    if (stepElements != null) {
        steps.addContent(stepElements);
        processElements.add(steps);
    }

    // template information
    Element templates = new Element("originals", xmlns);
    List<Element> templateElements = new ArrayList<>();
    for (Template v : process.getVorlagenList()) {
        Element template = new Element("original", xmlns);
        template.setAttribute("originalID", String.valueOf(v.getId()));

        List<Element> templateProperties = new ArrayList<>();
        for (Templateproperty prop : v.getEigenschaftenList()) {
            Element property = new Element("property", xmlns);
            property.setAttribute("propertyIdentifier", prop.getTitel());
            if (prop.getWert() != null) {
                property.setAttribute("value", prop.getWert());
            } else {
                property.setAttribute("value", "");
            }

            Element label = new Element("label", xmlns);

            label.setText(prop.getTitel());
            property.addContent(label);

            templateProperties.add(property);
            if (prop.getTitel().equals("Signatur")) {
                Element secondProperty = new Element("property", xmlns);
                secondProperty.setAttribute("propertyIdentifier", prop.getTitel() + "Encoded");
                if (prop.getWert() != null) {
                    secondProperty.setAttribute("value", "vorl:" + prop.getWert());
                    Element secondLabel = new Element("label", xmlns);
                    secondLabel.setText(prop.getTitel());
                    secondProperty.addContent(secondLabel);
                    templateProperties.add(secondProperty);
                }
            }
        }
        if (templateProperties.size() != 0) {
            Element properties = new Element("properties", xmlns);
            properties.addContent(templateProperties);
            template.addContent(properties);
        }
        templateElements.add(template);
    }
    if (templateElements != null) {
        templates.addContent(templateElements);
        processElements.add(templates);
    }

    // digital document information
    Element digdoc = new Element("digitalDocuments", xmlns);
    List<Element> docElements = new ArrayList<>();
    for (Masterpiece w : process.getWerkstueckeList()) {
        Element dd = new Element("digitalDocument", xmlns);
        dd.setAttribute("digitalDocumentID", String.valueOf(w.getId()));

        List<Element> docProperties = new ArrayList<>();
        for (Masterpieceproperty prop : w.getEigenschaftenList()) {
            Element property = new Element("property", xmlns);
            property.setAttribute("propertyIdentifier", prop.getTitel());
            if (prop.getWert() != null) {
                property.setAttribute("value", prop.getWert());
            } else {
                property.setAttribute("value", "");
            }

            Element label = new Element("label", xmlns);

            label.setText(prop.getTitel());
            property.addContent(label);
            docProperties.add(property);
        }
        if (docProperties.size() != 0) {
            Element properties = new Element("properties", xmlns);
            properties.addContent(docProperties);
            dd.addContent(properties);
        }
        docElements.add(dd);
    }
    if (docElements != null) {
        digdoc.addContent(docElements);
        processElements.add(digdoc);
    }
    // history
    List<HistoryEvent> eventList = HistoryManager.getHistoryEvents(process.getId());
    if (eventList != null && !eventList.isEmpty()) {
        List<Element> eventElementList = new ArrayList<>(eventList.size());

        for (HistoryEvent event : eventList) {
            Element element = new Element("historyEvent", xmlns);
            element.setAttribute("id", "" + event.getId());
            element.setAttribute("date", Helper.getDateAsFormattedString(event.getDate()));
            element.setAttribute("type", event.getHistoryType().getTitle());

            if (event.getNumericValue() != null) {
                element.setAttribute("numeric_value", "" + event.getNumericValue());
            }
            if (event.getStringValue() != null) {
                element.setText(event.getStringValue());
            }
            eventElementList.add(element);
        }

        if (!eventElementList.isEmpty()) {
            Element metadataElement = new Element("history", xmlns);
            metadataElement.addContent(eventElementList);
            processElements.add(metadataElement);
        }
    }

    // metadata
    List<StringPair> metadata = MetadataManager.getMetadata(process.getId());
    if (metadata != null && !metadata.isEmpty()) {
        List<Element> mdlist = new ArrayList<>();
        for (StringPair md : metadata) {
            String name = md.getOne();
            String value = md.getTwo();
            if (StringUtils.isNotBlank(value) && StringUtils.isNotBlank(name)) {
                Element element = new Element("metadata", xmlns);
                element.setAttribute("name", name);
                element.addContent(value);
                mdlist.add(element);
            }
        }
        if (!mdlist.isEmpty()) {
            Element metadataElement = new Element("metadatalist", xmlns);
            metadataElement.addContent(mdlist);
            processElements.add(metadataElement);
        }
    }
    // METS information
    Element metsElement = new Element("metsInformation", xmlns);
    List<Element> metadataElements = new ArrayList<>();

    try {
        String filename = process.getMetadataFilePath();
        Document metsDoc = new SAXBuilder().build(filename);
        Document anchorDoc = null;
        String anchorfilename = process.getMetadataFilePath().replace("meta.xml", "meta_anchor.xml");
        Path anchorFile = Paths.get(anchorfilename);
        if (StorageProvider.getInstance().isFileExists(anchorFile)
                && StorageProvider.getInstance().isReadable(anchorFile)) {
            anchorDoc = new SAXBuilder().build(anchorfilename);
        }

        List<Namespace> namespaces = getNamespacesFromConfig();

        HashMap<String, String> fields = getMetsFieldsFromConfig(false);
        for (String key : fields.keySet()) {
            List<Element> metsValues = getMetsValues(fields.get(key), metsDoc, namespaces);
            for (Element element : metsValues) {
                Element ele = new Element("property", xmlns);
                ele.setAttribute("name", key);
                ele.addContent(element.getTextTrim());
                metadataElements.add(ele);
            }
        }

        if (anchorDoc != null) {
            fields = getMetsFieldsFromConfig(true);
            for (String key : fields.keySet()) {
                List<Element> metsValues = getMetsValues(fields.get(key), anchorDoc, namespaces);
                for (Element element : metsValues) {
                    Element ele = new Element("property", xmlns);
                    ele.setAttribute("name", key);
                    ele.addContent(element.getTextTrim());
                    metadataElements.add(ele);
                }
            }
        }

        if (metadataElements != null) {
            metsElement.addContent(metadataElements);
            processElements.add(metsElement);
        }

    } catch (SwapException e) {
        logger.error(e);
    } catch (DAOException e) {
        logger.error(e);
    } catch (IOException e) {
        logger.error(e);
    } catch (InterruptedException e) {
        logger.error(e);
    } catch (JDOMException e) {
        logger.error(e);
    } catch (JaxenException e) {
        logger.error(e);
    }

    processElm.setContent(processElements);
    return doc;
}

From source file:org.goobi.production.export.ExportXmlLog.java

License:Open Source License

/**
 * This method exports the production metadata for al list of processes as a single file to a given stream.
 * //  www  .j  a  v a  2s  .co m
 * @param processList
 * @param outputStream
 * @param xslt
 */

public void startExport(List<Process> processList, OutputStream outputStream, String xslt) {
    Document answer = new Document();
    Element root = new Element("processes");
    answer.setRootElement(root);
    Namespace xmlns = Namespace.getNamespace("http://www.goobi.io/logfile");

    Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    root.addNamespaceDeclaration(xsi);
    root.setNamespace(xmlns);
    Attribute attSchema = new Attribute("schemaLocation", "http://www.goobi.io/logfile" + " XML-logfile.xsd",
            xsi);
    root.setAttribute(attSchema);
    for (Process p : processList) {
        Document doc = createDocument(p, false);
        Element processRoot = doc.getRootElement();
        processRoot.detach();
        root.addContent(processRoot);
    }

    XMLOutputter outp = new XMLOutputter();
    outp.setFormat(Format.getPrettyFormat());

    try {

        outp.output(answer, outputStream);
    } catch (IOException e) {

    } finally {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (IOException e) {
                outputStream = null;
            }
        }
    }

}

From source file:org.kitodo.docket.ExportXmlLog.java

License:Open Source License

/**
 * This method exports the production metadata for al list of processes as a
 * single file to a given stream./*from ww w  .  ja va 2s  .co m*/
 *
 * @param docketDataList
 *            a list of Docket data
 * @param outputStream
 *            The output stream, to write the docket to.
 */

void startMultipleExport(Iterable<DocketData> docketDataList, OutputStream outputStream) {
    Document answer = new Document();
    Element root = new Element("processes");
    answer.setRootElement(root);
    Namespace xmlns = Namespace.getNamespace(NAMESPACE);

    Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    root.addNamespaceDeclaration(xsi);
    root.setNamespace(xmlns);
    Attribute attSchema = new Attribute("schemaLocation", NAMESPACE + " XML-logfile.xsd", xsi);
    root.setAttribute(attSchema);
    for (DocketData docketData : docketDataList) {
        Document doc = createDocument(docketData, false);
        Element processRoot = doc.getRootElement();
        processRoot.detach();
        root.addContent(processRoot);
    }

    XMLOutputter outp = new XMLOutputter(Format.getPrettyFormat());

    try {
        outp.output(answer, outputStream);
    } catch (IOException e) {
        logger.error("Generating XML Output failed.", e);
    } finally {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (IOException e) {
                logger.error("Closing the output stream failed.", e);
            }
        }
    }

}

From source file:org.kitodo.docket.ExportXmlLog.java

License:Open Source License

/**
 * This method creates a new xml document with process metadata.
 *
 * @param docketData// w ww  .  j a v  a2  s.c om
 *            the docketData to export
 * @return a new xml document
 */
private Document createDocument(DocketData docketData, boolean addNamespace) {

    Element processElm = new Element("process");
    final Document doc = new Document(processElm);

    processElm.setAttribute("processID", String.valueOf(docketData.getProcessId()));

    Namespace xmlns = Namespace.getNamespace(NAMESPACE);
    processElm.setNamespace(xmlns);
    // namespace declaration
    if (addNamespace) {

        Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        processElm.addNamespaceDeclaration(xsi);
        Attribute attSchema = new Attribute("schemaLocation", NAMESPACE + " XML-logfile.xsd", xsi);
        processElm.setAttribute(attSchema);
    }
    // process information

    ArrayList<Element> processElements = new ArrayList<>();
    Element processTitle = new Element("title", xmlns);
    processTitle.setText(docketData.getProcessName());
    processElements.add(processTitle);

    Element project = new Element("project", xmlns);
    project.setText(docketData.getProjectName());
    processElements.add(project);

    Element date = new Element("time", xmlns);
    date.setAttribute("type", "creation date");
    date.setText(String.valueOf(docketData.getCreationDate()));
    processElements.add(date);

    Element ruleset = new Element("ruleset", xmlns);
    ruleset.setText(docketData.getRulesetName());
    processElements.add(ruleset);

    Element comment = new Element("comment", xmlns);
    comment.setText(docketData.getComment());
    processElements.add(comment);

    List<Element> processProperties = prepareProperties(docketData.getProcessProperties(), xmlns);

    if (!processProperties.isEmpty()) {
        Element properties = new Element(PROPERTIES, xmlns);
        properties.addContent(processProperties);
        processElements.add(properties);
    }

    // template information
    ArrayList<Element> templateElements = new ArrayList<>();
    Element template = new Element("original", xmlns);

    ArrayList<Element> templateProperties = new ArrayList<>();
    if (docketData.getTemplateProperties() != null) {
        for (Property prop : docketData.getTemplateProperties()) {
            Element property = new Element(PROPERTY, xmlns);
            property.setAttribute(PROPERTY_IDENTIFIER, prop.getTitle());
            if (prop.getValue() != null) {
                property.setAttribute(VALUE, replacer(prop.getValue()));
            } else {
                property.setAttribute(VALUE, "");
            }

            Element label = new Element(LABEL, xmlns);

            label.setText(prop.getTitle());
            property.addContent(label);

            templateProperties.add(property);
            if (prop.getTitle().equals("Signatur")) {
                Element secondProperty = new Element(PROPERTY, xmlns);
                secondProperty.setAttribute(PROPERTY_IDENTIFIER, prop.getTitle() + "Encoded");
                if (prop.getValue() != null) {
                    secondProperty.setAttribute(VALUE, "vorl:" + replacer(prop.getValue()));
                    Element secondLabel = new Element(LABEL, xmlns);
                    secondLabel.setText(prop.getTitle());
                    secondProperty.addContent(secondLabel);
                    templateProperties.add(secondProperty);
                }
            }
        }
    }
    if (!templateProperties.isEmpty()) {
        Element properties = new Element(PROPERTIES, xmlns);
        properties.addContent(templateProperties);
        template.addContent(properties);
    }
    templateElements.add(template);

    Element templates = new Element("originals", xmlns);
    templates.addContent(templateElements);
    processElements.add(templates);

    // digital document information
    ArrayList<Element> docElements = new ArrayList<>();
    Element dd = new Element("digitalDocument", xmlns);

    List<Element> docProperties = prepareProperties(docketData.getWorkpieceProperties(), xmlns);

    if (!docProperties.isEmpty()) {
        Element properties = new Element(PROPERTIES, xmlns);
        properties.addContent(docProperties);
        dd.addContent(properties);
    }
    docElements.add(dd);

    Element digdoc = new Element("digitalDocuments", xmlns);
    digdoc.addContent(docElements);
    processElements.add(digdoc);

    processElm.setContent(processElements);
    return doc;
}

From source file:org.mycore.datamodel.metadata.MCRBase.java

License:Open Source License

/**
 * This method create a XML stream for all object data.
 * /*  w  ww . j  a  va 2s  .  c o m*/
 * @exception MCRException
 *                if the content of this class is not valid
 * @return a JDOM Document with the XML data of the object as byte array
 */
public Document createXML() throws MCRException {
    validate();
    Element elm = new Element(getRootTagName());
    Document doc = new Document(elm);
    elm.addNamespaceDeclaration(XSI_NAMESPACE);
    elm.addNamespaceDeclaration(XLINK_NAMESPACE);
    elm.setAttribute("noNamespaceSchemaLocation", mcr_schema, XSI_NAMESPACE);
    elm.setAttribute("ID", mcr_id.toString());
    if (mcr_label != null) {
        elm.setAttribute("label", mcr_label);
    }
    elm.setAttribute("version", mcr_version);
    return doc;
}

From source file:org.mycore.datamodel.metadata.validator.MCREditorOutValidator.java

License:Open Source License

/**
 * @throws IOException /*ww w .  j ava2 s . c  om*/
 * @throws JDOMException 
 * 
 */
private void checkObject() throws JDOMException, IOException {
    // add the namespaces (this is a workaround)
    org.jdom2.Element root = input.getRootElement();
    root.addNamespaceDeclaration(XLINK_NAMESPACE);
    root.addNamespaceDeclaration(XSI_NAMESPACE);
    // set the schema
    String mcr_schema = "datamodel-" + id.getTypeId() + ".xsd";
    root.setAttribute("noNamespaceSchemaLocation", mcr_schema, XSI_NAMESPACE);
    // check the label
    String label = root.getAttributeValue("label");
    if (label == null || (label = label.trim()).length() == 0) {
        root.setAttribute("label", id.toString());
    }
    // remove the path elements from the incoming
    org.jdom2.Element pathes = root.getChild("pathes");
    if (pathes != null) {
        root.removeChildren("pathes");
    }
    org.jdom2.Element structure = root.getChild("structure");
    if (structure == null) {
        root.addContent(new Element("structure"));
    } else {
        checkObjectStructure(structure);
    }
    Element metadata = root.getChild("metadata");
    checkObjectMetadata(metadata);
    org.jdom2.Element service = root.getChild("service");
    checkObjectService(root, service);
}

From source file:org.mycore.frontend.cli.MCRAccessCommands.java

License:Open Source License

/**
 * This method just export the permissions to a file
 * //from   w ww .  j a va2s  .c o  m
 * @param filename
 *            the file written to
 */
@MCRCommand(syntax = "export all permissions to file {0}", help = "Export all permissions from the Access Control System to the file {0}.", order = 50)
public static void exportAllPermissionsToFile(String filename) throws Exception {
    MCRAccessInterface AI = MCRAccessManager.getAccessImpl();

    Element mcrpermissions = new Element("mcrpermissions");
    mcrpermissions.addNamespaceDeclaration(XSI_NAMESPACE);
    mcrpermissions.addNamespaceDeclaration(XLINK_NAMESPACE);
    mcrpermissions.setAttribute("noNamespaceSchemaLocation", "MCRPermissions.xsd", XSI_NAMESPACE);
    Document doc = new Document(mcrpermissions);
    Collection<String> permissions = AI.getPermissions();
    for (String permission : permissions) {
        Element mcrpermission = new Element("mcrpermission");
        mcrpermission.setAttribute("name", permission);
        String ruleDescription = AI.getRuleDescription(permission);
        if (!ruleDescription.equals("")) {
            mcrpermission.setAttribute("ruledescription", ruleDescription);
        }
        Element rule = AI.getRule(permission);
        mcrpermission.addContent(rule);
        mcrpermissions.addContent(mcrpermission);
    }
    File file = new File(filename);
    if (file.exists()) {
        LOGGER.warn("File " + filename + " yet exists, overwrite.");
    }
    FileOutputStream fos = new FileOutputStream(file);
    LOGGER.info("Writing to file " + filename + " ...");
    String mcr_encoding = CONFIG.getString("MCR.Metadata.DefaultEncoding", DEFAULT_ENCODING);
    XMLOutputter out = new XMLOutputter(Format.getPrettyFormat().setEncoding(mcr_encoding));
    out.output(doc, fos);
}

From source file:org.mycore.frontend.indexbrowser.MCRGoogleSitemapCommon.java

License:Open Source License

/**
 * The method build the sitemap_google.xml JDOM document over all items.
 * /*from ww w  .  j a v a  2  s . co  m*/
 * @return The sitemap_google.xml as JDOM document
 */
protected final Document buildSingleSitemap() throws Exception {
    LOGGER.debug("Build Google URL sitemap_google.xml for whole items.");
    // build document frame
    Element urlset = new Element("urlset", ns);
    urlset.addNamespaceDeclaration(XSI_NAMESPACE);
    urlset.setAttribute("noNamespaceSchemaLocation", SITEMAP_SCHEMA, XSI_NAMESPACE);
    Document jdom = new Document(urlset);
    // build over all types
    for (MCRObjectIDDate objectIDDate : objidlist) {
        urlset.addContent(buildURLElement(objectIDDate));
    }
    return jdom;
}

From source file:org.mycore.frontend.indexbrowser.MCRGoogleSitemapCommon.java

License:Open Source License

/**
 * The method call the database and build the sitemap_google.xml JDOM document.
 * //from  w  ww.  j  a  v a2s  . c  o m
 * @param number
 *            number of this file - '1' = sitemap_google.xml - '&gt; 1' sitemap_google_xxx.xml
 * @return The sitemap.xml as JDOM document
 */
protected final Document buildPartSitemap(int number) throws Exception {
    LOGGER.debug("Build Google URL sitemap list number " + Integer.toString(number));
    // build document frame
    Element urlset = new Element("urlset", ns);
    urlset.addNamespaceDeclaration(XSI_NAMESPACE);
    urlset.setAttribute("schemaLocation", SITEMAP_SCHEMA, XSI_NAMESPACE);
    Document jdom = new Document(urlset);

    // build over all types
    int start = numberOfURLs * (number);
    int stop = numberOfURLs * (number + 1);
    if (stop > objidlist.size())
        stop = objidlist.size();
    LOGGER.debug("Build Google URL in range from " + Integer.toString(start) + " to "
            + Integer.toString(stop - 1) + ".");
    for (int i = start; i < stop; i++) {
        MCRObjectIDDate objectIDDate = objidlist.get(i);
        urlset.addContent(buildURLElement(objectIDDate));

    }
    return jdom;
}