Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

java / Lab5ecl_1 / lab5das / src / Main

.java
Скачиваний:
80
Добавлен:
17.04.2018
Размер:
6.8 Кб
Скачать
import java.io.File;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Main {
public static void main(String[] args) throws Exception {

String lang = "en";
String country = "EN";
Locale l = new Locale(lang, country);

ResourceBundle r = ResourceBundle.getBundle("Bundle", l);

DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, l);

NumberFormat currFormat = NumberFormat.getInstance(l);

DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();

Document document = documentBuilder.newDocument();

Element recipes = document.createElement("recipes");
document.appendChild(recipes);

//блюдо 1
Element recipe1 = document.createElement("recipe");
recipes.appendChild(recipe1);
recipe1.setAttribute("name", document.createTextNode("\u0411\u043b\u0438\u043d\u044b"));
recipe1.setAttribute("pretime", currFormat.format(5));
recipe1.setAttribute("cooktime", currFormat.format(180));
recipe1.setAttribute("editDate", fmt.format(new Date(116, 01, 30, 12, 44)));

//ингредиенты
Element ingredient1 = document.createElement("ingredient");
recipe1.appendChild(ingredient1);
ingredient1.setAttribute("amount", currFormat.format(5000));
ingredient1.setAttribute("unit", r.getString("str1"));
ingredient1.appendChild(document.createTextNode("\u041c\u0443\u043a\u0430 \u0431\u043b\u0438\u043d\u043d\u0430\u044f"));

Element ingredient2 = document.createElement("ingredient");
recipe1.appendChild(ingredient2);
ingredient2.setAttribute("amount", currFormat.format(5));
ingredient2.setAttribute("unit", r.getString("str2"));
ingredient2.appendChild(document.createTextNode("\u042f\u0439\u0446\u043e \u043a\u0443\u0440\u0438\u043d\u043e\u0435"));

Element ingredient3 = document.createElement("ingredient");
recipe1.appendChild(ingredient3);
ingredient3.setAttribute("amount", currFormat.format(1));
ingredient3.setAttribute("unit", r.getString("str3"));
ingredient3.appendChild(document.createTextNode("\u041c\u043e\u043b\u043e\u043a\u043e"));


Element ingredient4 = document.createElement("ingredient");
recipe1.appendChild(ingredient4);
ingredient4.setAttribute("amount", currFormat.format(1));
ingredient4.setAttribute("unit", r.getString("str4"));
ingredient4.appendChild(document.createTextNode("\u0421\u043e\u043b\u044c"));


//Приборы
Element dishes1= document.createElement("dishes");
recipe1.appendChild(dishes1);
dishes1.appendChild(document.createTextNode("\u041c\u0438\u0441\u043a\u0430"));

Element dishes2= document.createElement("dishes");
recipe1.appendChild(dishes2);
dishes2.appendChild(document.createTextNode("\u0421\u043a\u043e\u0432\u043e\u0440\u043e\u0434\u043a\u0430"));

Element dishes3= document.createElement("dishes");
recipe1.appendChild(dishes3);
dishes3.appendChild(document.createTextNode("\u041c\u0438\u043a\u0441\u0435\u0440"));

//Пошаговая инструкция
Element instructions1= document.createElement("instructions");
recipe1.appendChild(instructions1);

Element step1= document.createElement("step");
instructions1.appendChild(step1);
step1.appendChild(document.createTextNode("\u041f\u0440\u043e\u0441\u0435\u044f\u0442\u044c \u043c\u0443\u043a\u0443 \u0438 \u0441\u043e\u043b\u044c \u0432 \u043c\u0438\u0441\u043a\u0443\u002e"));

Element step2= document.createElement("step");
instructions1.appendChild(step2);
step2.appendChild(document.createTextNode("\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u043e\u043b\u043e\u043a\u0430 \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0448\u0430\u0442\u044c\u002e"));

Element step3= document.createElement("step");
instructions1.appendChild(step3);
step3.appendChild(document.createTextNode("\u041f\u0435\u0440\u0435\u043c\u0435\u0448\u0430\u0442\u044c\u002c \u043f\u043e\u043a\u0430 \u0442\u0435\u0441\u0442\u043e \u043d\u0435 \u0441\u0442\u0430\u043d\u0435\u0442 \u043e\u0434\u043d\u043e\u0440\u043e\u0434\u043d\u044b\u043c\u002e"));

Element step4= document.createElement("step");
instructions1.appendChild(step4);
step4.appendChild(document.createTextNode("\u0420\u0430\u0437\u043e\u0433\u0440\u0435\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u043b\u0430 \u043d\u0430 \u0441\u043a\u043e\u0432\u043e\u0440\u043e\u0434\u043a\u0435\u002e \u0412\u043b\u0438\u0442\u044c \u043d\u0430 \u0441\u043a\u043e\u0432\u043e\u0440\u043e\u0434\u043a\u0443 \u0032\u002d\u0033 \u0441\u0442\u002e\u043b\u043e\u0436\u043a\u0438 \u0442\u0435\u0441\u0442\u0430\u002e"));

Element step5= document.createElement("step");
instructions1.appendChild(step5);
step5.appendChild(document.createTextNode("\u041e\u0431\u0436\u0430\u0440\u0438\u0442\u044c \u0441 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0434\u043e \u0437\u043e\u043b\u043e\u0442\u0438\u0441\u0442\u043e\u0439 \u043a\u043e\u0440\u043e\u0447\u043a\u0438\u002e"));

Element step6= document.createElement("step");
instructions1.appendChild(step6);
step6.appendChild(document.createTextNode("\u041f\u0435\u0440\u0435\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0438 \u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043e\u043a\u043e\u043b\u043e\u043e \u0033\u0030 \u0441\u0435\u043a\u0443\u043d\u0434\u002e"));

StreamResult streamResult = new StreamResult(new File("ska.xml"));
transformer.transform(source, streamResult);

TransformerFactory factory = TransformerFactory.newInstance();

//StreamSource xsltStream = new StreamSource("ska.xslt");
StreamSource xsltStream = new StreamSource("ska_en.xslt");

Transformer transformer1 = factory.newTransformer(xsltStream);
StreamSource in = new StreamSource("ska.xml");
StreamResult out = new StreamResult("ska.html");
transformer1.transform(in, out);
System.out.println("The generated HTML file is: ska.html");

}
}
Соседние файлы в папке src
  • #
    17.04.2018175 б80Bundle.properties
  • #
    17.04.201850 б81Bundle_en_EN.properties
  • #
    17.04.20186.8 Кб80Main.java