use of de.pdark.decentxml.Document in project sling by apache.
the class JcrNode method pasteFromClipboard.
/**
* Paste from the clipboard to this (container) node.
* <p>
* Copyright Note: The code of this method was ported from eclipse'
* PasteAction, which due to visibility restrictions was not reusable.
* <p>
* @param clipboard
*/
public void pasteFromClipboard(Clipboard clipboard) {
if (!canBePastedTo(clipboard)) {
// should not occur due to 'canBePastedTo' check done by
// corresponding action - checking here nevertheless
MessageDialog.openInformation(null, "Cannot paste", "No applicable node (type) for pasting found.");
return;
}
Repository repository = ServerUtil.getDefaultRepository(getProject());
NodeTypeRegistry ntManager = (repository == null) ? null : repository.getNodeTypeRegistry();
if (ntManager == null) {
MessageDialog.openWarning(null, "Cannot paste", "Cannot paste if corresponding server is not started");
return;
}
// try the resource transfer
IResource[] resourceData = (IResource[]) clipboard.getContents(ResourceTransfer.getInstance());
if (resourceData != null && resourceData.length > 0) {
if (resourceData[0].getType() == IResource.PROJECT) {
// do not support project pasting onto a jcr node
MessageDialog.openInformation(null, "Cannot paste project(s)", "Pasting of a project onto a (JCR) node is not possible");
return;
} else {
CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(null);
operation.copyResources(resourceData, getDropContainer());
}
return;
}
// try the file transfer
String[] fileData = (String[]) clipboard.getContents(FileTransfer.getInstance());
if (fileData != null) {
CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(null);
operation.copyFiles(fileData, getDropContainer());
return;
}
// then try the text transfer
String text = (String) clipboard.getContents(TextTransfer.getInstance());
if ((text != null) && (this.domElement != null)) {
try {
Document document = TolerantXMLParser.parse(text, "pasted from clipboard");
this.domElement.addNode(document.getRootElement());
this.underlying.save();
} catch (IOException e) {
MessageDialog.openError(null, "Could not paste from clipboard", "Exception encountered while pasting from clipboard: " + e);
Activator.getDefault().getPluginLogger().error("Error pasting from clipboard: " + e, e);
}
}
}
use of de.pdark.decentxml.Document in project fabric8 by jboss-fuse.
the class RouteXml method marshalToDoc.
/**
* Marshals the model to XML and updates the model's doc property to contain the
* new marshalled model
*
* @param model
*/
public void marshalToDoc(XmlModel model) throws JAXBException {
Marshaller marshaller = jaxbContext().createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, java.lang.Boolean.TRUE);
try {
marshaller.setProperty("com.sun.xml.bind.indentString", " ");
} catch (Exception e) {
LOG.debug("Property not supported: {}", e);
}
Object value = model.marshalRootElement();
Document doc = model.getDoc();
Element docElem = doc.getRootElement();
// JAXB only seems to do nice whitespace/namespace stuff when writing to stream
// rather than DOM directly
// marshaller.marshal(value, docElem);
StringWriter buffer = new StringWriter();
marshaller.marshal(value, buffer);
// now lets parse the XML and insert the root element into the doc
String xml = buffer.toString();
if (!model.getNs().equals(springNS)) {
// !!!
xml = xml.replaceAll(springNS, model.getNs());
}
Document camelDoc = parse(new XMLStringSource(xml));
Node camelElem = camelDoc.getRootElement();
if (model.isRoutesContext() && camelDoc.getRootElement().getName().equals("camelContext")) {
camelDoc.getRootElement().setName("routeContext");
}
if (model.isJustRoutes()) {
replaceChild(doc, camelElem, docElem);
} else {
if (model.getNode() != null) {
replaceCamelElement(docElem, camelElem, model.getNode());
} else {
docElem.addNode(camelElem);
}
}
}
use of de.pdark.decentxml.Document in project fabric8 by jboss-fuse.
the class RouteXml method createExemplarDoc.
protected Document createExemplarDoc() throws IOException {
String exemplar = "io/fabric8/camel/tooling/exemplar.xml";
URL url = findResource(exemplar, null);
if (url != null) {
return parse(new XMLIOSource(url));
} else {
LOG.warn("Could not find file {} on the class path", exemplar);
Document d = new Document();
d.addNode(new Element("beans", springNamespace));
return d;
}
}
use of de.pdark.decentxml.Document in project tycho by eclipse.
the class ProductConfiguration method write.
public static void write(ProductConfiguration product, File file) throws IOException {
OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
Document document = product.document;
try {
String enc = document.getEncoding() != null ? document.getEncoding() : "UTF-8";
Writer w = new OutputStreamWriter(os, enc);
XMLWriter xw = new XMLWriter(w);
try {
document.toXML(xw);
} finally {
xw.flush();
}
} finally {
IOUtil.close(os);
}
}
use of de.pdark.decentxml.Document in project tycho by eclipse.
the class UpdateSite method write.
public static void write(UpdateSite site, File file) throws IOException {
OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
Document document = site.document;
try {
String enc = document.getEncoding() != null ? document.getEncoding() : "UTF-8";
Writer w = new OutputStreamWriter(os, enc);
XMLWriter xw = new XMLWriter(w);
try {
document.toXML(xw);
} finally {
xw.flush();
}
} finally {
IOUtil.close(os);
}
}
Aggregations