use of org.dom4j.io.OutputFormat in project openolat by klemens.
the class FilePersister method createResultsReporting.
/**
* Persist results for this user/aiid as an XML document. dlPointer is aiid in
* this case.
*
* @param doc
* @param type
* @param info
*/
public static void createResultsReporting(Document doc, Identity subj, String type, long aiid) {
File fUserdataRoot = new File(WebappHelper.getUserDataRoot());
String path = RES_REPORTING + File.separator + subj.getName() + File.separator + type;
File fReportingDir = new File(fUserdataRoot, path);
try {
fReportingDir.mkdirs();
OutputStream os = new FileOutputStream(new File(fReportingDir, aiid + ".xml"));
Element element = doc.getRootElement();
XMLWriter xw = new XMLWriter(os, new OutputFormat(" ", true));
xw.write(element);
// closing steams
xw.close();
os.close();
} catch (Exception e) {
throw new OLATRuntimeException(FilePersister.class, "Error persisting results reporting for subject: '" + subj.getName() + "'; assessment id: '" + aiid + "'", e);
}
}
use of org.dom4j.io.OutputFormat in project openolat by klemens.
the class QTIExportProcessor method assembleTest.
/**
* <li>List all items
* <li>Rewrite path
* <li>Assemble qti.xml
* <li>Write files at new path
* @param fullItems
* @param zout
*/
public void assembleTest(List<QuestionItemFull> fullItems, ZipOutputStream zout) {
ItemsAndMaterials itemAndMaterials = new ItemsAndMaterials();
for (QuestionItemFull fullItem : fullItems) {
collectMaterials(fullItem, itemAndMaterials);
}
try {
byte[] buffer = new byte[FileUtils.BSIZE];
// write qti.xml
Element sectionEl = createSectionBasedAssessment("Assessment");
for (Element itemEl : itemAndMaterials.getItemEls()) {
// generate new ident per item
String ident = getAttributeValue(itemEl, "ident");
String exportIdent = QTIEditHelper.generateNewIdent(ident);
itemEl.addAttribute("ident", exportIdent);
sectionEl.add(itemEl);
}
zout.putNextEntry(new ZipEntry("qti.xml"));
XMLWriter xw = new XMLWriter(zout, new OutputFormat(" ", true));
xw.write(sectionEl.getDocument());
zout.closeEntry();
// write materials
for (ItemMaterial material : itemAndMaterials.getMaterials()) {
String exportPath = material.getExportUri();
zout.putNextEntry(new ZipEntry(exportPath));
InputStream in = material.getLeaf().getInputStream();
int c;
while ((c = in.read(buffer, 0, buffer.length)) != -1) {
zout.write(buffer, 0, c);
}
IOUtils.closeQuietly(in);
zout.closeEntry();
}
} catch (IOException e) {
log.error("", e);
}
}
use of org.dom4j.io.OutputFormat in project zm-mailbox by Zimbra.
the class MailItemResource method patchProperties.
/* Modifies the set of dead properties saved for this resource.
* Properties in the parameter 'set' are added to the existing properties.
* Properties in 'remove' are removed.
*/
@Override
public void patchProperties(DavContext ctxt, java.util.Collection<Element> set, java.util.Collection<QName> remove) throws DavException, IOException {
List<QName> reqProps = new ArrayList<QName>();
for (QName n : remove) {
mDeadProps.remove(n);
reqProps.add(n);
}
for (Element e : set) {
QName name = e.getQName();
if (name.equals(DavElements.E_DISPLAYNAME) && (type == MailItem.Type.FOLDER || type == MailItem.Type.MOUNTPOINT)) {
// rename folder
try {
String val = e.getText();
String uri = getUri();
Mailbox mbox = getMailbox(ctxt);
mbox.rename(ctxt.getOperationContext(), mId, type, val, mFolderId);
setProperty(DavElements.P_DISPLAYNAME, val);
UrlNamespace.addToRenamedResource(getOwner(), uri, this);
UrlNamespace.addToRenamedResource(getOwner(), uri.substring(0, uri.length() - 1), this);
} catch (ServiceException se) {
ctxt.getResponseProp().addPropError(DavElements.E_DISPLAYNAME, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY));
}
mDeadProps.remove(name);
continue;
} else if (name.equals(DavElements.E_CALENDAR_COLOR) && (type == MailItem.Type.FOLDER || type == MailItem.Type.MOUNTPOINT)) {
// change color
String colorStr = e.getText();
Color color = new Color(colorStr.substring(0, 7));
byte col = (byte) COLOR_LIST.indexOf(colorStr);
if (col >= 0)
color.setColor(col);
try {
Mailbox mbox = getMailbox(ctxt);
mbox.setColor(ctxt.getOperationContext(), new int[] { mId }, type, color);
} catch (ServiceException se) {
ctxt.getResponseProp().addPropError(DavElements.E_CALENDAR_COLOR, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY));
}
mDeadProps.remove(name);
continue;
} else if (name.equals(DavElements.E_SUPPORTED_CALENDAR_COMPONENT_SET)) {
// change default view
@SuppressWarnings("unchecked") List<Element> elements = e.elements(DavElements.E_COMP);
boolean isTodo = false;
boolean isEvent = false;
for (Element element : elements) {
Attribute attr = element.attribute(DavElements.P_NAME);
if (attr != null && CalComponent.VTODO.name().equals(attr.getValue())) {
isTodo = true;
} else if (attr != null && CalComponent.VEVENT.name().equals(attr.getValue())) {
isEvent = true;
}
}
if (isEvent ^ isTodo) {
// we support a calendar collection of type event or todo, not both or none.
Type type = (isEvent) ? Type.APPOINTMENT : Type.TASK;
try {
Mailbox mbox = getMailbox(ctxt);
mbox.setFolderDefaultView(ctxt.getOperationContext(), mId, type);
// See UrlNamespace.addToRenamedResource()
if (this instanceof Collection) {
((Collection) this).view = type;
}
} catch (ServiceException se) {
ctxt.getResponseProp().addPropError(name, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY));
}
} else {
ctxt.getResponseProp().addPropError(name, new DavException.CannotModifyProtectedProperty(name));
}
continue;
}
mDeadProps.put(name, e);
reqProps.add(name);
}
String configVal = "";
if (mDeadProps.size() > 0) {
org.dom4j.Document doc = org.dom4j.DocumentHelper.createDocument();
Element top = doc.addElement(CONFIG_KEY);
for (Map.Entry<QName, Element> entry : mDeadProps.entrySet()) top.add(entry.getValue().detach());
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputFormat format = OutputFormat.createCompactFormat();
XMLWriter writer = new XMLWriter(out, format);
writer.write(doc);
configVal = new String(out.toByteArray(), "UTF-8");
if (configVal.length() > PROP_LENGTH_LIMIT)
for (Map.Entry<QName, Element> entry : mDeadProps.entrySet()) ctxt.getResponseProp().addPropError(entry.getKey(), new DavException("prop length exceeded", DavProtocol.STATUS_INSUFFICIENT_STORAGE));
}
Mailbox mbox = null;
try {
mbox = getMailbox(ctxt);
mbox.lock.lock();
Metadata data = mbox.getConfig(ctxt.getOperationContext(), CONFIG_KEY);
if (data == null) {
data = new Metadata();
}
data.put(Integer.toString(mId), configVal);
mbox.setConfig(ctxt.getOperationContext(), CONFIG_KEY, data);
} catch (ServiceException se) {
for (QName qname : reqProps) ctxt.getResponseProp().addPropError(qname, new DavException(se.getMessage(), HttpServletResponse.SC_FORBIDDEN));
} finally {
if (mbox != null)
mbox.lock.release();
}
}
use of org.dom4j.io.OutputFormat in project zm-mailbox by Zimbra.
the class DavRequest method getRequestMessageString.
public String getRequestMessageString() throws IOException {
if (mDoc != null) {
OutputFormat format = OutputFormat.createPrettyPrint();
format.setTrimText(false);
format.setOmitEncoding(false);
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(out, format);
writer.write(mDoc);
return new String(out.toByteArray(), "UTF-8");
}
return "";
}
use of org.dom4j.io.OutputFormat in project hibernate-orm by hibernate.
the class AdditionalJaxbMappingProducerImpl method dump.
private static void dump(Document document) {
if (!log.isTraceEnabled()) {
return;
}
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final Writer w = new PrintWriter(baos);
try {
final XMLWriter xw = new XMLWriter(w, new OutputFormat(" ", true));
xw.write(document);
w.flush();
} catch (IOException e1) {
e1.printStackTrace();
}
log.tracef("Envers-generate entity mapping -----------------------------\n%s", baos.toString());
log.trace("------------------------------------------------------------");
}
Aggregations