Skip to content
Snippets Groups Projects
Commit c76bf032 authored by Quit Phuong Bui's avatar Quit Phuong Bui
Browse files

added transformation

parent 2c90e035
Branches master
No related tags found
No related merge requests found
Showing
with 906 additions and 163 deletions
/**
*/
package coursePage.impl;
import coursePage.CoursePagePackage;
import coursePage.credits;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>credits</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* </p>
* <ul>
* <li>{@link coursePage.impl.creditsImpl#getPoints <em>Points</em>}</li>
* </ul>
*
* @generated
*/
public class creditsImpl extends MinimalEObjectImpl.Container implements credits {
/**
* The default value of the '{@link #getPoints() <em>Points</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getPoints()
* @generated
* @ordered
*/
protected static final double POINTS_EDEFAULT = 0.0;
/**
* The cached value of the '{@link #getPoints() <em>Points</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getPoints()
* @generated
* @ordered
*/
protected double points = POINTS_EDEFAULT;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected creditsImpl() {
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return CoursePagePackage.Literals.CREDITS;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public double getPoints() {
return points;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setPoints(double newPoints) {
double oldPoints = points;
points = newPoints;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, CoursePagePackage.CREDITS__POINTS, oldPoints, points));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case CoursePagePackage.CREDITS__POINTS:
return getPoints();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case CoursePagePackage.CREDITS__POINTS:
setPoints((Double)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case CoursePagePackage.CREDITS__POINTS:
setPoints(POINTS_EDEFAULT);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case CoursePagePackage.CREDITS__POINTS:
return points != POINTS_EDEFAULT;
}
return super.eIsSet(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public String toString() {
if (eIsProxy()) return super.toString();
StringBuilder result = new StringBuilder(super.toString());
result.append(" (points: ");
result.append(points);
result.append(')');
return result.toString();
}
} //creditsImpl
/**
*/
package coursePage.util;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl;
/**
* <!-- begin-user-doc -->
* The <b>Resource Factory</b> associated with the package.
* <!-- end-user-doc -->
* @see coursePage.util.CoursePageResourceImpl
* @generated
*/
public class CoursePageResourceFactoryImpl extends ResourceFactoryImpl {
/**
* Creates an instance of the resource factory.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public CoursePageResourceFactoryImpl() {
super();
}
/**
* Creates an instance of the resource.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Resource createResource(URI uri) {
Resource result = new CoursePageResourceImpl(uri);
return result;
}
} //CoursePageResourceFactoryImpl
/**
*/
package coursePage.util;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
/**
* <!-- begin-user-doc -->
* The <b>Resource </b> associated with the package.
* <!-- end-user-doc -->
* @see coursePage.util.CoursePageResourceFactoryImpl
* @generated
*/
public class CoursePageResourceImpl extends XMIResourceImpl {
/**
* Creates an instance of the resource.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param uri the URI of the new resource.
* @generated
*/
public CoursePageResourceImpl(URI uri) {
super(uri);
}
CoursePageResourceImpl() {
throw new UnsupportedOperationException("TODO: auto-generated method stub");
}
} //CoursePageResourceImpl
<?xml version="1.0" encoding="UTF-8"?>
<coursePage:Course
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:coursePage="platform:/resource/tdt4250.web/model/coursePage.ecore"
code="TDT4100"
name="OOP"
content="content"
credits="7.5">
<timetable>
<table starteTime="1415"
endTime="1600"
hours="5.0"/>
<table day="Tuesday"
room="EL6"
lectureType="lecture"
starteTime="1215"
endTime="1400"
hours="5.0"/>
</timetable>
<relation
creditsReduction="3.0"/>
<grading points="70.0"/>
<courseWork
lectureHours="5.0"
labHours="5.0"/>
<hasBeenTaught
semester="V16"
credits="7.5"/>
<courseStaff>
<inTheStaff
name="Hallvard Trætteberg">
<role/>
<isCC/>
</inTheStaff>
<inTheStaff
name="Alf Inge">
<role
role="assistant"/>
</inTheStaff>
</courseStaff>
</coursePage:Course>
package tdt4250.transformation
import org.w3c.xhtml1.util.Xhtml1ResourceFactoryImpl
import org.w3c.xhtml1.Xhtml1Factory
import coursePage.Course
import org.w3c.xhtml1.HtmlType
import org.eclipse.emf.ecore.xmi.XMLResource
import java.io.ByteArrayOutputStream
import org.eclipse.emf.common.util.URI
import java.io.IOException
import java.util.Arrays
import org.eclipse.emf.ecore.xml.namespace.XMLNamespaceFactory
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
import coursePage.CoursePagePackage
import org.eclipse.emf.ecore.EObject
import coursePage.util.CoursePageResourceImpl
import coursePage.util.CoursePageResourceFactoryImpl
class Course2HTML {
Xhtml1ResourceFactoryImpl xhtml1ResourceFactoryImpl = new Xhtml1ResourceFactoryImpl
def String generateHtml(Course course) {
val encoding = "UTF-8"
val html = generateHtmlType(course);
val root = XMLNamespaceFactory.eINSTANCE.createXMLNamespaceDocumentRoot += html
//val fileName = (if (course.name !== null) course.name.replace('.', '/') else "quiz")+ '.html'
val fileName = "Course" + '.html'
val resource = xhtml1ResourceFactoryImpl.createResource(URI.createFileURI(fileName)) as XMLResource
resource.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODING, encoding);
resource.contents += html
val outputStream = new ByteArrayOutputStream(4096)
resource.save(outputStream, null)
val originalOutput = outputStream.toString(encoding)
originalOutput.cleanHtml
}
def cleanHtml(String html) {
html
.replace("xhtml:", "")
.replace("html_._type", "html")
.replace("xmlns:xhtml=", "xmlns=")
.replace("&lt;", "<")
.replace("&gt;", ">")
.replace("&amp;", "&")
.replace("&quot;", "'")
}
extension Xhtml1Factory xhtml1Factory = Xhtml1Factory.eINSTANCE
extension XhtmlUtil xhtmlUtil = new XhtmlUtil
def HtmlType generateHtmlType(Course course) {
val html = createHtmlType => [
head = createHeadType => [
title = createTitleType => [
it += ("TITLE")
]
meta += createMetaType => [
httpEquiv = "content-type"
content = "text/html; charset=UTF-8"
]
]
body = createBodyType => [
it +=createH1Type => [
it += course.code + " " + course.name
]
it += createPType => [
it += "This page contains all information about this course"
]
it += createPType => [
it += "name: " + course.code + " " + course.name
]
it += createPType => [
it += "credits: " + course.credits
]
it += createH2Type => [
it += "TimeTable"
]
for(slot: course.timetable.table){
it += createPType =>[
it += slot.day.toString + " " + slot.room.toString + " " +slot.starteTime + "-" +slot.endTime
+ " " + slot.lectureType
]
}
it += createH2Type => [
it += "Evaluation"
]
it += createPType => [
for(evaluation : course.grading){
it += evaluation.evaluation.toString
+ " " + evaluation.points+ "/" + "100"
}
]
it += createH2Type => [
it += "Course Work"
]
it += createPType => [
it += "Lecture Hours" + " " + course.courseWork.lectureHours.toString
]
it += createPType => [
it += "Lab Hours" + " " + course.courseWork.labHours.toString
]
it += createH2Type => [
it += "Course Reduction"
]
for(ocourse :course.relation ){
it += createPType =>[
it+= ocourse.course.toString + " " + "Reduction:" + ocourse.creditsReduction.toString
]
}
it += createH2Type => [
it += "Course Staff"
]
for(person: course.courseStaff.get(0).inTheStaff){
it += createPType =>[
it += person.name + " " + person.role
]
}
]
]
html
// fsa.generateFile(quiz.name.replace('.', '/') + '.html', stringBuilder);
}
def static void main(String[] args) throws IOException {
val argsAsList = Arrays.asList(args)
val course = if (argsAsList.size > 0) getCourse(argsAsList.get(0)) else getSampleCourse();
val html = new Course2HTML().generateHtml(course);
System.out.println(html);
}
def static Course getSampleCourse() {
try {
return getCourse(Course2HTML.getResource("Course.xmi").toString());
}
catch (IOException e) {
println();
System.err.println(e);
return null;
}
}
def static Course getCourse(String uriString) throws IOException {
val resSet = new ResourceSetImpl();
resSet.getPackageRegistry().put(CoursePagePackage.eNS_URI, CoursePagePackage.eINSTANCE);
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new CoursePageResourceFactoryImpl());
val resource = resSet.getResource(URI.createURI(uriString), true);
for (EObject eObject : resource.getContents()) {
if (eObject instanceof Course) {
return eObject as Course;
}
}
return null;
}
}
\ No newline at end of file
package tdt4250.transformation
import org.eclipse.emf.ecore.EClass
import org.eclipse.emf.ecore.EDataType
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.EcorePackage
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.emf.ecore.util.FeatureMap
import org.eclipse.emf.ecore.util.FeatureMapUtil
import org.w3c.xhtml1.Xhtml1Package
class XhtmlUtil {
def tag(String tagName) {
val typeName = tagName + "Type"
for (eClass : Xhtml1Package.eINSTANCE.EClassifiers.filter(EClass)) {
val className = eClass.name
if (className.equalsIgnoreCase(tagName) || className.equalsIgnoreCase(typeName)) {
return eClass
}
}
}
def create(EClass tag) {
EcoreUtil.create(tag)
}
def create(String tagName) {
val tag = tag(tagName)
if (tag !== null) {
create(tag)
}
}
def attr(EObject eObject, String attrName) {
eObject.eClass.EAllStructuralFeatures.findFirst[name == attrName]
}
def operator_add(EObject eObject, Pair<String, String> attr) {
val feature = attr(eObject, attr.key)
if (feature !== null) {
val featureType = feature.EType as EDataType
val value = featureType.EPackage.EFactoryInstance.createFromString(featureType, attr.value)
if (feature.many) {
// (eObject.eGet(feature) as EList<?>).add(value)
} else {
eObject.eSet(feature, value)
}
}
}
def featureMap(EObject featureMapOwner) {
for (feature : featureMapOwner.eClass.EAllStructuralFeatures) {
if (feature.EType == EcorePackage.eINSTANCE.EFeatureMapEntry) {
return featureMapOwner.eGet(feature) as FeatureMap
}
}
}
def operator_add(EObject featureMapOwner, EObject eObject) {
val featureMap = featureMap(featureMapOwner)
if (featureMap !== null) {
for (feature : featureMapOwner.eClass.EAllStructuralFeatures) {
if (feature.EType.isInstance(eObject)) {
featureMap.add(feature, eObject)
return featureMapOwner
}
}
System.err.println("Didn't find feature for " + eObject.eClass.name + " in " + featureMapOwner.eClass.name)
}
featureMapOwner
}
def operator_add(EObject featureMapOwner, Iterable<? extends EObject> eObjects) {
for (eObject : eObjects) {
featureMapOwner += eObject
}
featureMapOwner
}
def operator_add(FeatureMap featureMap, CharSequence text) {
if (featureMap !== null) {
FeatureMapUtil.addText(featureMap, if (text !== null) text.toString else "")
}
featureMap
}
def operator_add(EObject featureMapOwner, CharSequence text) {
val featureMap = featureMap(featureMapOwner)
if (featureMap !== null) {
featureMap += text
}
featureMapOwner
}
// def operator_add(Block block, EObject eObject) {
// add(block, block.group, eObject)
// }
// def operator_add(Block block, Iterable<? extends EObject> eObjects) {
// for (eObject : eObjects) {
// add(block, block.group, eObject)
// }
// }
//
// def operator_add(FormContent form, EObject eObject) {
// add(form, form.group, eObject)
// }
// def operator_add(FormContent form, Iterable<? extends EObject> eObjects) {
// for (eObject : eObjects) {
// add(form, form.group, eObject)
// }
// }
//
// def operator_add(Flow flow, EObject eObject) {
// add(flow, flow.group, eObject)
// }
// def operator_add(Inline inline, EObject eObject) {
// add(inline, inline.group, eObject)
// }
// def operator_add(ScriptType script, CharSequence text) {
// script.mixed += text
// }
// def operator_add(ButtonContent button, CharSequence text) {
// button.mixed += text
// }
// def operator_add(SelectType select, EObject eObject) {
// add(select, select.group, eObject)
// }
//
def StringBuilder operator_doubleLessThan(StringBuilder stringBuilder, Object o) {
return stringBuilder.append(o);
}
}
File added
File added
File added
File added
package tdt4250.transformation;
import coursePage.Course;
import coursePage.CoursePagePackage;
import coursePage.Employee;
import coursePage.Evaluation;
import coursePage.LectureType;
import coursePage.Lecturer;
import coursePage.RelationToCourse;
import coursePage.Slot;
import coursePage.util.CoursePageResourceFactoryImpl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xml.namespace.XMLNamespaceDocumentRoot;
import org.eclipse.emf.ecore.xml.namespace.XMLNamespaceFactory;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.w3c.xhtml1.BodyType;
import org.w3c.xhtml1.H1Type;
import org.w3c.xhtml1.H2Type;
import org.w3c.xhtml1.HeadType;
import org.w3c.xhtml1.HtmlType;
import org.w3c.xhtml1.MetaType;
import org.w3c.xhtml1.PType;
import org.w3c.xhtml1.TitleType;
import org.w3c.xhtml1.Xhtml1Factory;
import org.w3c.xhtml1.util.Xhtml1ResourceFactoryImpl;
import tdt4250.transformation.XhtmlUtil;
@SuppressWarnings("all")
public class Course2HTML {
private Xhtml1ResourceFactoryImpl xhtml1ResourceFactoryImpl = new Xhtml1ResourceFactoryImpl();
public String generateHtml(final Course course) {
try {
String _xblockexpression = null;
{
final String encoding = "UTF-8";
final HtmlType html = this.generateHtmlType(course);
XMLNamespaceDocumentRoot _createXMLNamespaceDocumentRoot = XMLNamespaceFactory.eINSTANCE.createXMLNamespaceDocumentRoot();
final EObject root = this.xhtmlUtil.operator_add(_createXMLNamespaceDocumentRoot, html);
final String fileName = ("Course" + ".html");
Resource _createResource = this.xhtml1ResourceFactoryImpl.createResource(URI.createFileURI(fileName));
final XMLResource resource = ((XMLResource) _createResource);
resource.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODING, encoding);
EList<EObject> _contents = resource.getContents();
_contents.add(html);
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(4096);
resource.save(outputStream, null);
final String originalOutput = outputStream.toString(encoding);
_xblockexpression = this.cleanHtml(originalOutput);
}
return _xblockexpression;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
public String cleanHtml(final String html) {
return html.replace("xhtml:", "").replace("html_._type", "html").replace("xmlns:xhtml=", "xmlns=").replace("&lt;", "<").replace("&gt;", ">").replace("&amp;", "&").replace("&quot;", "\'");
}
@Extension
private Xhtml1Factory xhtml1Factory = Xhtml1Factory.eINSTANCE;
@Extension
private XhtmlUtil xhtmlUtil = new XhtmlUtil();
public HtmlType generateHtmlType(final Course course) {
HtmlType _xblockexpression = null;
{
HtmlType _createHtmlType = this.xhtml1Factory.createHtmlType();
final Procedure1<HtmlType> _function = (HtmlType it) -> {
HeadType _createHeadType = this.xhtml1Factory.createHeadType();
final Procedure1<HeadType> _function_1 = (HeadType it_1) -> {
TitleType _createTitleType = this.xhtml1Factory.createTitleType();
final Procedure1<TitleType> _function_2 = (TitleType it_2) -> {
this.xhtmlUtil.operator_add(it_2, "TITLE");
};
TitleType _doubleArrow = ObjectExtensions.<TitleType>operator_doubleArrow(_createTitleType, _function_2);
it_1.setTitle(_doubleArrow);
EList<MetaType> _meta = it_1.getMeta();
MetaType _createMetaType = this.xhtml1Factory.createMetaType();
final Procedure1<MetaType> _function_3 = (MetaType it_2) -> {
it_2.setHttpEquiv("content-type");
it_2.setContent("text/html; charset=UTF-8");
};
MetaType _doubleArrow_1 = ObjectExtensions.<MetaType>operator_doubleArrow(_createMetaType, _function_3);
_meta.add(_doubleArrow_1);
};
HeadType _doubleArrow = ObjectExtensions.<HeadType>operator_doubleArrow(_createHeadType, _function_1);
it.setHead(_doubleArrow);
BodyType _createBodyType = this.xhtml1Factory.createBodyType();
final Procedure1<BodyType> _function_2 = (BodyType it_1) -> {
H1Type _createH1Type = this.xhtml1Factory.createH1Type();
final Procedure1<H1Type> _function_3 = (H1Type it_2) -> {
String _code = course.getCode();
String _plus = (_code + " ");
String _name = course.getName();
String _plus_1 = (_plus + _name);
this.xhtmlUtil.operator_add(it_2, _plus_1);
};
H1Type _doubleArrow_1 = ObjectExtensions.<H1Type>operator_doubleArrow(_createH1Type, _function_3);
this.xhtmlUtil.operator_add(it_1, _doubleArrow_1);
PType _createPType = this.xhtml1Factory.createPType();
final Procedure1<PType> _function_4 = (PType it_2) -> {
this.xhtmlUtil.operator_add(it_2, "This page contains all information about this course");
};
PType _doubleArrow_2 = ObjectExtensions.<PType>operator_doubleArrow(_createPType, _function_4);
this.xhtmlUtil.operator_add(it_1, _doubleArrow_2);
PType _createPType_1 = this.xhtml1Factory.createPType();
final Procedure1<PType> _function_5 = (PType it_2) -> {
String _code = course.getCode();
String _plus = ("name: " + _code);
String _plus_1 = (_plus + " ");
String _name = course.getName();
String _plus_2 = (_plus_1 + _name);
this.xhtmlUtil.operator_add(it_2, _plus_2);
};
PType _doubleArrow_3 = ObjectExtensions.<PType>operator_doubleArrow(_createPType_1, _function_5);
this.xhtmlUtil.operator_add(it_1, _doubleArrow_3);
PType _createPType_2 = this.xhtml1Factory.createPType();
final Procedure1<PType> _function_6 = (PType it_2) -> {
double _credits = course.getCredits();
String _plus = ("credits: " + Double.valueOf(_credits));
this.xhtmlUtil.operator_add(it_2, _plus);
};
PType _doubleArrow_4 = ObjectExtensions.<PType>operator_doubleArrow(_createPType_2, _function_6);
this.xhtmlUtil.operator_add(it_1, _doubleArrow_4);
H2Type _createH2Type = this.xhtml1Factory.createH2Type();
final Procedure1<H2Type> _function_7 = (H2Type it_2) -> {
this.xhtmlUtil.operator_add(it_2, "TimeTable");
};
H2Type _doubleArrow_5 = ObjectExtensions.<H2Type>operator_doubleArrow(_createH2Type, _function_7);
this.xhtmlUtil.operator_add(it_1, _doubleArrow_5);
EList<Slot> _table = course.getTimetable().getTable();
for (final Slot slot : _table) {
PType _createPType_3 = this.xhtml1Factory.createPType();
final Procedure1<PType> _function_8 = (PType it_2) -> {
String _string = slot.getDay().toString();
String _plus = (_string + " ");
String _string_1 = slot.getRoom().toString();
String _plus_1 = (_plus + _string_1);
String _plus_2 = (_plus_1 + " ");
String _starteTime = slot.getStarteTime();
String _plus_3 = (_plus_2 + _starteTime);
String _plus_4 = (_plus_3 + "-");
String _endTime = slot.getEndTime();
String _plus_5 = (_plus_4 + _endTime);
String _plus_6 = (_plus_5 + " ");
LectureType _lectureType = slot.getLectureType();
String _plus_7 = (_plus_6 + _lectureType);
this.xhtmlUtil.operator_add(it_2, _plus_7);
};
PType _doubleArrow_6 = ObjectExtensions.<PType>operator_doubleArrow(_createPType_3, _function_8);
this.xhtmlUtil.operator_add(it_1, _doubleArrow_6);
}
H2Type _createH2Type_1 = this.xhtml1Factory.createH2Type();
final Procedure1<H2Type> _function_9 = (H2Type it_2) -> {
this.xhtmlUtil.operator_add(it_2, "Evaluation");
};
H2Type _doubleArrow_7 = ObjectExtensions.<H2Type>operator_doubleArrow(_createH2Type_1, _function_9);
this.xhtmlUtil.operator_add(it_1, _doubleArrow_7);
PType _createPType_4 = this.xhtml1Factory.createPType();
final Procedure1<PType> _function_10 = (PType it_2) -> {
EList<Evaluation> _grading = course.getGrading();
for (final Evaluation evaluation : _grading) {
String _string = evaluation.getEvaluation().toString();
String _plus = (_string + " ");
double _points = evaluation.getPoints();
String _plus_1 = (_plus + Double.valueOf(_points));
String _plus_2 = (_plus_1 + "/");
String _plus_3 = (_plus_2 + "100");
this.xhtmlUtil.operator_add(it_2, _plus_3);
}
};
PType _doubleArrow_8 = ObjectExtensions.<PType>operator_doubleArrow(_createPType_4, _function_10);
this.xhtmlUtil.operator_add(it_1, _doubleArrow_8);
H2Type _createH2Type_2 = this.xhtml1Factory.createH2Type();
final Procedure1<H2Type> _function_11 = (H2Type it_2) -> {
this.xhtmlUtil.operator_add(it_2, "Course Work");
};
H2Type _doubleArrow_9 = ObjectExtensions.<H2Type>operator_doubleArrow(_createH2Type_2, _function_11);
this.xhtmlUtil.operator_add(it_1, _doubleArrow_9);
PType _createPType_5 = this.xhtml1Factory.createPType();
final Procedure1<PType> _function_12 = (PType it_2) -> {
String _string = Double.valueOf(course.getCourseWork().getLectureHours()).toString();
String _plus = (("Lecture Hours" + " ") + _string);
this.xhtmlUtil.operator_add(it_2, _plus);
};
PType _doubleArrow_10 = ObjectExtensions.<PType>operator_doubleArrow(_createPType_5, _function_12);
this.xhtmlUtil.operator_add(it_1, _doubleArrow_10);
PType _createPType_6 = this.xhtml1Factory.createPType();
final Procedure1<PType> _function_13 = (PType it_2) -> {
String _string = Double.valueOf(course.getCourseWork().getLabHours()).toString();
String _plus = (("Lab Hours" + " ") + _string);
this.xhtmlUtil.operator_add(it_2, _plus);
};
PType _doubleArrow_11 = ObjectExtensions.<PType>operator_doubleArrow(_createPType_6, _function_13);
this.xhtmlUtil.operator_add(it_1, _doubleArrow_11);
H2Type _createH2Type_3 = this.xhtml1Factory.createH2Type();
final Procedure1<H2Type> _function_14 = (H2Type it_2) -> {
this.xhtmlUtil.operator_add(it_2, "Course Reduction");
};
H2Type _doubleArrow_12 = ObjectExtensions.<H2Type>operator_doubleArrow(_createH2Type_3, _function_14);
this.xhtmlUtil.operator_add(it_1, _doubleArrow_12);
EList<RelationToCourse> _relation = course.getRelation();
for (final RelationToCourse ocourse : _relation) {
PType _createPType_7 = this.xhtml1Factory.createPType();
final Procedure1<PType> _function_15 = (PType it_2) -> {
String _string = ocourse.getCourse().toString();
String _plus = (_string + " ");
String _plus_1 = (_plus + "Reduction:");
String _string_1 = Double.valueOf(ocourse.getCreditsReduction()).toString();
String _plus_2 = (_plus_1 + _string_1);
this.xhtmlUtil.operator_add(it_2, _plus_2);
};
PType _doubleArrow_13 = ObjectExtensions.<PType>operator_doubleArrow(_createPType_7, _function_15);
this.xhtmlUtil.operator_add(it_1, _doubleArrow_13);
}
H2Type _createH2Type_4 = this.xhtml1Factory.createH2Type();
final Procedure1<H2Type> _function_16 = (H2Type it_2) -> {
this.xhtmlUtil.operator_add(it_2, "Course Staff");
};
H2Type _doubleArrow_14 = ObjectExtensions.<H2Type>operator_doubleArrow(_createH2Type_4, _function_16);
this.xhtmlUtil.operator_add(it_1, _doubleArrow_14);
EList<Employee> _inTheStaff = course.getCourseStaff().get(0).getInTheStaff();
for (final Employee person : _inTheStaff) {
PType _createPType_8 = this.xhtml1Factory.createPType();
final Procedure1<PType> _function_17 = (PType it_2) -> {
String _name = person.getName();
String _plus = (_name + " ");
EList<Lecturer> _role = person.getRole();
String _plus_1 = (_plus + _role);
this.xhtmlUtil.operator_add(it_2, _plus_1);
};
PType _doubleArrow_15 = ObjectExtensions.<PType>operator_doubleArrow(_createPType_8, _function_17);
this.xhtmlUtil.operator_add(it_1, _doubleArrow_15);
}
};
BodyType _doubleArrow_1 = ObjectExtensions.<BodyType>operator_doubleArrow(_createBodyType, _function_2);
it.setBody(_doubleArrow_1);
};
final HtmlType html = ObjectExtensions.<HtmlType>operator_doubleArrow(_createHtmlType, _function);
_xblockexpression = html;
}
return _xblockexpression;
}
public static void main(final String[] args) throws IOException {
final List<String> argsAsList = Arrays.<String>asList(args);
Course _xifexpression = null;
int _size = argsAsList.size();
boolean _greaterThan = (_size > 0);
if (_greaterThan) {
_xifexpression = Course2HTML.getCourse(argsAsList.get(0));
} else {
_xifexpression = Course2HTML.getSampleCourse();
}
final Course course = _xifexpression;
final String html = new Course2HTML().generateHtml(course);
System.out.println(html);
}
public static Course getSampleCourse() {
try {
return Course2HTML.getCourse(Course2HTML.class.getResource("Course.xmi").toString());
} catch (final Throwable _t) {
if (_t instanceof IOException) {
final IOException e = (IOException)_t;
InputOutput.println();
System.err.println(e);
return null;
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}
public static Course getCourse(final String uriString) throws IOException {
final ResourceSetImpl resSet = new ResourceSetImpl();
resSet.getPackageRegistry().put(CoursePagePackage.eNS_URI, CoursePagePackage.eINSTANCE);
Map<String, Object> _extensionToFactoryMap = resSet.getResourceFactoryRegistry().getExtensionToFactoryMap();
CoursePageResourceFactoryImpl _coursePageResourceFactoryImpl = new CoursePageResourceFactoryImpl();
_extensionToFactoryMap.put("xmi", _coursePageResourceFactoryImpl);
final Resource resource = resSet.getResource(URI.createURI(uriString), true);
EList<EObject> _contents = resource.getContents();
for (final EObject eObject : _contents) {
if ((eObject instanceof Course)) {
return ((Course) eObject);
}
}
return null;
}
}
package tdt4250.transformation;
import com.google.common.base.Objects;
import com.google.common.collect.Iterables;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.FeatureMap;
import org.eclipse.emf.ecore.util.FeatureMapUtil;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Pair;
import org.w3c.xhtml1.Xhtml1Package;
@SuppressWarnings("all")
public class XhtmlUtil {
public EClass tag(final String tagName) {
final String typeName = (tagName + "Type");
Iterable<EClass> _filter = Iterables.<EClass>filter(Xhtml1Package.eINSTANCE.getEClassifiers(), EClass.class);
for (final EClass eClass : _filter) {
{
final String className = eClass.getName();
if ((className.equalsIgnoreCase(tagName) || className.equalsIgnoreCase(typeName))) {
return eClass;
}
}
}
return null;
}
public EObject create(final EClass tag) {
return EcoreUtil.create(tag);
}
public EObject create(final String tagName) {
EObject _xblockexpression = null;
{
final EClass tag = this.tag(tagName);
EObject _xifexpression = null;
if ((tag != null)) {
_xifexpression = this.create(tag);
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
public EStructuralFeature attr(final EObject eObject, final String attrName) {
final Function1<EStructuralFeature, Boolean> _function = (EStructuralFeature it) -> {
String _name = it.getName();
return Boolean.valueOf(Objects.equal(_name, attrName));
};
return IterableExtensions.<EStructuralFeature>findFirst(eObject.eClass().getEAllStructuralFeatures(), _function);
}
public Object operator_add(final EObject eObject, final Pair<String, String> attr) {
Object _xblockexpression = null;
{
final EStructuralFeature feature = this.attr(eObject, attr.getKey());
Object _xifexpression = null;
if ((feature != null)) {
Object _xblockexpression_1 = null;
{
EClassifier _eType = feature.getEType();
final EDataType featureType = ((EDataType) _eType);
final Object value = featureType.getEPackage().getEFactoryInstance().createFromString(featureType, attr.getValue());
Object _xifexpression_1 = null;
boolean _isMany = feature.isMany();
if (_isMany) {
_xifexpression_1 = null;
} else {
eObject.eSet(feature, value);
}
_xblockexpression_1 = _xifexpression_1;
}
_xifexpression = _xblockexpression_1;
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
public FeatureMap featureMap(final EObject featureMapOwner) {
EList<EStructuralFeature> _eAllStructuralFeatures = featureMapOwner.eClass().getEAllStructuralFeatures();
for (final EStructuralFeature feature : _eAllStructuralFeatures) {
EClassifier _eType = feature.getEType();
EDataType _eFeatureMapEntry = EcorePackage.eINSTANCE.getEFeatureMapEntry();
boolean _equals = Objects.equal(_eType, _eFeatureMapEntry);
if (_equals) {
Object _eGet = featureMapOwner.eGet(feature);
return ((FeatureMap) _eGet);
}
}
return null;
}
public EObject operator_add(final EObject featureMapOwner, final EObject eObject) {
EObject _xblockexpression = null;
{
final FeatureMap featureMap = this.featureMap(featureMapOwner);
if ((featureMap != null)) {
EList<EStructuralFeature> _eAllStructuralFeatures = featureMapOwner.eClass().getEAllStructuralFeatures();
for (final EStructuralFeature feature : _eAllStructuralFeatures) {
boolean _isInstance = feature.getEType().isInstance(eObject);
if (_isInstance) {
featureMap.add(feature, eObject);
return featureMapOwner;
}
}
String _name = eObject.eClass().getName();
String _plus = ("Didn\'t find feature for " + _name);
String _plus_1 = (_plus + " in ");
String _name_1 = featureMapOwner.eClass().getName();
String _plus_2 = (_plus_1 + _name_1);
System.err.println(_plus_2);
}
_xblockexpression = featureMapOwner;
}
return _xblockexpression;
}
public EObject operator_add(final EObject featureMapOwner, final Iterable<? extends EObject> eObjects) {
EObject _xblockexpression = null;
{
for (final EObject eObject : eObjects) {
this.operator_add(featureMapOwner, eObject);
}
_xblockexpression = featureMapOwner;
}
return _xblockexpression;
}
public FeatureMap operator_add(final FeatureMap featureMap, final CharSequence text) {
FeatureMap _xblockexpression = null;
{
if ((featureMap != null)) {
String _xifexpression = null;
if ((text != null)) {
_xifexpression = text.toString();
} else {
_xifexpression = "";
}
FeatureMapUtil.addText(featureMap, _xifexpression);
}
_xblockexpression = featureMap;
}
return _xblockexpression;
}
public EObject operator_add(final EObject featureMapOwner, final CharSequence text) {
EObject _xblockexpression = null;
{
final FeatureMap featureMap = this.featureMap(featureMapOwner);
if ((featureMap != null)) {
this.operator_add(featureMap, text);
}
_xblockexpression = featureMapOwner;
}
return _xblockexpression;
}
public StringBuilder operator_doubleLessThan(final StringBuilder stringBuilder, final Object o) {
return stringBuilder.append(o);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment