Example usage for org.jdom2 Document Document

List of usage examples for org.jdom2 Document Document

Introduction

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

Prototype

public Document(List<? extends Content> content) 

Source Link

Document

This will create a new Document, with the supplied list of content, and a DocType declaration only if the content contains a DocType instance.

Usage

From source file:delfos.configuration.ConfigurationScope.java

License:Open Source License

protected void loadConfigurationScope() {
    if (document == null) {
        File configurationFile = ConfigurationManager.getConfigurationFile(this);
        SAXBuilder builder = new SAXBuilder();
        try {/*  w  ww .  ja v  a 2  s. co  m*/
            document = builder.build(configurationFile);
        } catch (JDOMException | IOException ex) {
            Global.showWarning("Cannot load xml from " + configurationFile.getAbsolutePath());

            if (configurationFile.exists()) {
                File erroneousFile = new File(
                        configurationFile.getParentFile().getAbsolutePath() + "cannot-parse.xml");
                configurationFile.renameTo(erroneousFile);
            }

            document = new Document(new Element(scopeName));
        }
    }
}

From source file:delfos.rs.output.RecommendationsOutputFileXML.java

License:Open Source License

@Override
public void writeRecommendations(Recommendations recommendationsToUser) {

    Element recommendationsElement = RecommendationsToXML.getRecommendationsElement(recommendationsToUser);

    String idTarget = recommendationsToUser.getTargetIdentifier();

    Document doc = new Document(recommendationsElement);
    XMLOutputter outputter = new XMLOutputter(Constants.getXMLFormat());

    File file = getCompleteFile(idTarget);

    FileUtilities.createDirectoriesForFile(file);

    try (FileWriter fileWriter = new FileWriter(file)) {
        outputter.output(doc, fileWriter);
    } catch (IOException ex) {
        ERROR_CODES.CANNOT_WRITE_RECOMMENDATIONS.exit(ex);
    }/* ww w . j  a v a  2 s. c om*/
}

From source file:delfos.rs.output.RecommendationsOutputStandardXML.java

License:Open Source License

@Override
public void writeRecommendations(Recommendations recommendations) {
    List<Recommendation> topNrecommendations = new ArrayList<>(recommendations.getRecommendations());

    if (getNumberOfRecommendations() > 0) {
        Collections.sort(topNrecommendations);
        topNrecommendations = topNrecommendations.subList(0,
                Math.min(topNrecommendations.size(), getNumberOfRecommendations()));
    }//from w  ww .j  a  v  a2s  . c  o  m

    Recommendations recommendationsWithNewRanking = RecommendationsFactory
            .copyRecommendationsWithNewRanking(recommendations, topNrecommendations);

    Element recommendationsElement = RecommendationsToXML
            .getRecommendationsElement(recommendationsWithNewRanking);

    Document doc = new Document(recommendationsElement);
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat().setEncoding("ISO-8859-1"));
    try {
        outputter.output(doc, System.out);
    } catch (IOException ex) {
        ERROR_CODES.CANNOT_WRITE_RECOMMENDATIONS.exit(ex);
    }
}

From source file:devicemodel.conversions.XmlConversions.java

public static String element2XmlString(final Element element) throws IOException {
    return document2XmlStringNoHeader(new Document(element.clone()));
}

From source file:domainapp.app.services.export.ExportToWordMenu.java

License:Apache License

private Document asInputDocument(final List<QuickObject> quickObjects) {

    final Element html = new Element("html");
    final Document document = new Document(html);

    final Element body = new Element("body");
    html.addContent(body);/*  w w w . j a v a 2 s.co m*/

    addPara(body, "ExportedOn", "date", clockService.nowAsLocalDateTime().toString("dd-MMM-yyyy"));

    final Element table = addTable(body, "SimpleObjects");
    for (final QuickObject quickObject : quickObjects) {
        addTableRow(table, new String[] { quickObject.getName() });
    }
    return document;
}

From source file:domainapp.app.services.export.PublishContributionsForMenu.java

License:Apache License

private Document asInputDocument(final Menu menu) {

    final Collection<MenuItem> menuItems = menu.getItems();

    final Element html = new Element("html");
    final Document document = new Document(html);

    final Element body = new Element("body");
    html.addContent(body);//from w ww  .  java2s .  com

    addPara(body, "EventName", "rich", menu.getEvent().getName());
    addPara(body, "ExportedOn", "date", clockService.nowAsLocalDateTime().toString("dd-MMM-yyyy"));

    final Element table = addTable(body, "MenuItems");

    addTableRow(table, new String[] { "", "" });
    for (final MenuItem item : menuItems) {

        final String name = item.getName();

        addTableRow(table, new String[] { name, item.getMemberPrice().toString() });

        final SortedSet<Ingredient> ingredients = item.getIngredients();

        final String ingredientSummary = Joiner.on(", ")
                .join(Iterables.transform(ingredients, new Function<Ingredient, String>() {
                    @Nullable
                    @Override
                    public String apply(final Ingredient input) {
                        return input.getName();
                    }
                }));

        addTableRow(table, new String[] { "       " + ingredientSummary, "" });
        addTableRow(table, new String[] { "", "" });
    }
    addTableRow(table, new String[] { "", "" });

    return document;
}

From source file:domainapp.app.services.export.PublishContributionsForOrder.java

License:Apache License

private Document asInputDocument(final Order order) {

    final Element html = new Element("html");
    final Document document = new Document(html);

    final Element body = new Element("body");
    html.addContent(body);/*from www  .ja  v  a 2  s  .c o  m*/

    addPara(body, "EventName", "rich", order.getEvent().getName());

    final String personName = order.getPerson().getFirstName() + order.getPerson().getLastName();
    addPara(body, "PersonName", "rich", personName);

    addPara(body, "ExportedOn", "date", clockService.nowAsLocalDateTime().toString("dd-MMM-yyyy"));

    final Element table = addTable(body, "Ingredients");

    addTableRow(table, new String[] { "", "" });

    for (final OrderItem orderItem : order.getItems()) {

        final MenuItem menuItem = orderItem.getMenuItem();
        final int quantity = orderItem.getQuantity();
        final BigDecimal memberPrice = menuItem.getMemberPrice();

        final String quantityOfMenuItem = "" + quantity + " x " + container.titleOf(menuItem);
        final BigDecimal cost = memberPrice.multiply(BigDecimal.valueOf(quantity));

        addTableRow(table, new String[] { quantityOfMenuItem, cost.toString() });

    }
    addTableRow(table, new String[] { "", "", "" });

    return document;
}

From source file:domainapp.app.services.export.PublishContributionsForSupplier.java

License:Apache License

private Document asInputDocument(final Supplier supplier, Event event) {

    final Map<String, Integer> quantitiesByIngredient = supplierReportCreator.reportItemsFor(supplier, event);

    final Element html = new Element("html");
    final Document document = new Document(html);

    final Element body = new Element("body");
    html.addContent(body);/*from  w w  w. jav  a2 s  .  c o m*/

    addPara(body, "SupplierName", "rich", supplier.getName());
    addPara(body, "EventName", "rich", event.getName());
    addPara(body, "ExportedOn", "date", clockService.nowAsLocalDateTime().toString("dd-MMM-yyyy"));

    final Element table = addTable(body, "Ingredients");

    addTableRow(table, new String[] { "", "" });
    for (final String ingredientName : quantitiesByIngredient.keySet()) {

        final Integer integer = quantitiesByIngredient.get(ingredientName);
        addTableRow(table, new String[] { ingredientName, integer.toString() });

    }
    addTableRow(table, new String[] { "", "" });

    return document;
}

From source file:edu.unc.lib.dl.cdr.services.rest.DepositController.java

License:Apache License

@RequestMapping(value = { "{uuid}/events" }, method = RequestMethod.GET)
public @ResponseBody Document getEvents(@PathVariable String uuid) throws Exception {
    LOG.debug("getEvents( {} )", uuid);
    Jedis jedis = getJedisPool().getResource();
    String bagDirectory = jedis.hget(RedisWorkerConstants.DEPOSIT_STATUS_PREFIX + uuid,
            RedisWorkerConstants.DepositField.directory.name());
    getJedisPool().returnResource(jedis);
    File bagFile = new File(bagDirectory);
    if (!bagFile.exists())
        return null;
    File eventsFile = new File(bagDirectory, DepositConstants.EVENTS_FILE);
    if (!eventsFile.exists())
        return null;
    Element events = new Element("events", JDOMNamespaceUtil.PREMIS_V2_NS);
    Document result = new Document(events);
    XMLInputFactory factory = XMLInputFactory.newInstance();
    try (FileInputStream fis = new FileInputStream(eventsFile)) {
        XMLStreamReader reader = factory.createXMLStreamReader(fis);
        StAXStreamBuilder builder = new StAXStreamBuilder();
        List<Content> list = builder.buildFragments(reader, new DefaultStAXFilter());
        events.addContent(list);// w  ww  . ja  va  2  s. co  m
        return result;
    }
}

From source file:edu.utep.cs.jasg.apiGenerator.APIGenerator.java

License:Open Source License

/** Generates a XML document using JDom */
public void generateXMLDocument() {
    Element parserAPI = new Element("parser_api");
    parserAPI.addContent(new Element("parser_name").setText(fileName));
    doc = new Document(parserAPI);

    createTerminalElements();//from  w ww  .  ja v a  2 s  .  co  m
    createRuleElements();

    createXMLFileWithXSLLink();
}