| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.kew.routeheader; |
| 18 | |
|
| 19 | |
import java.io.StringWriter; |
| 20 | |
import java.util.Iterator; |
| 21 | |
import java.util.List; |
| 22 | |
|
| 23 | |
import javax.xml.parsers.DocumentBuilder; |
| 24 | |
import javax.xml.parsers.DocumentBuilderFactory; |
| 25 | |
import javax.xml.transform.OutputKeys; |
| 26 | |
import javax.xml.transform.Result; |
| 27 | |
import javax.xml.transform.Source; |
| 28 | |
import javax.xml.transform.Transformer; |
| 29 | |
import javax.xml.transform.TransformerConfigurationException; |
| 30 | |
import javax.xml.transform.TransformerException; |
| 31 | |
import javax.xml.transform.TransformerFactory; |
| 32 | |
import javax.xml.transform.dom.DOMSource; |
| 33 | |
import javax.xml.transform.stream.StreamResult; |
| 34 | |
|
| 35 | |
import org.kuali.rice.kew.engine.RouteContext; |
| 36 | |
import org.kuali.rice.kew.exception.InvalidXmlException; |
| 37 | |
import org.kuali.rice.kew.exception.WorkflowRuntimeException; |
| 38 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 39 | |
import org.w3c.dom.Document; |
| 40 | |
import org.w3c.dom.Element; |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
public class PartialAttributeContent implements DocumentContent { |
| 49 | |
|
| 50 | |
private static final long serialVersionUID = -7710201192800150123L; |
| 51 | |
|
| 52 | |
private Document document; |
| 53 | |
private Element attributeContent; |
| 54 | |
private RouteContext routeContext; |
| 55 | |
|
| 56 | |
public PartialAttributeContent(List attributeContents) throws InvalidXmlException { |
| 57 | 0 | this(attributeContents, null); |
| 58 | 0 | } |
| 59 | |
|
| 60 | 0 | public PartialAttributeContent(List attributeContents, RouteContext routeContext) throws InvalidXmlException { |
| 61 | |
try { |
| 62 | 0 | this.routeContext = routeContext; |
| 63 | 0 | DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
| 64 | 0 | this.document = documentBuilder.newDocument(); |
| 65 | 0 | Element rootElement = document.createElement(KEWConstants.DOCUMENT_CONTENT_ELEMENT); |
| 66 | 0 | this.attributeContent = document.createElement(KEWConstants.ATTRIBUTE_CONTENT_ELEMENT); |
| 67 | 0 | rootElement.appendChild(attributeContent); |
| 68 | 0 | for (Iterator iterator = attributeContents.iterator(); iterator.hasNext();) { |
| 69 | 0 | Element element = (Element) iterator.next(); |
| 70 | 0 | element = (Element)document.importNode(element, true); |
| 71 | 0 | attributeContent.appendChild(element); |
| 72 | 0 | } |
| 73 | 0 | document.appendChild(rootElement); |
| 74 | 0 | } catch (Exception e) { |
| 75 | 0 | throw new InvalidXmlException(e); |
| 76 | 0 | } |
| 77 | 0 | } |
| 78 | |
|
| 79 | |
public Document getDocument() { |
| 80 | 0 | return document; |
| 81 | |
} |
| 82 | |
|
| 83 | |
public Element getApplicationContent() { |
| 84 | 0 | return null; |
| 85 | |
} |
| 86 | |
|
| 87 | |
public Element getAttributeContent() { |
| 88 | 0 | return attributeContent; |
| 89 | |
} |
| 90 | |
|
| 91 | |
public Element getSearchableContent() { |
| 92 | 0 | return null; |
| 93 | |
} |
| 94 | |
|
| 95 | |
public String getDocContent() { |
| 96 | |
try { |
| 97 | 0 | Source source = new DOMSource(document); |
| 98 | 0 | StringWriter writer = new StringWriter(); |
| 99 | 0 | Result result = new StreamResult(writer); |
| 100 | 0 | Transformer transformer = TransformerFactory.newInstance().newTransformer(); |
| 101 | 0 | transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); |
| 102 | 0 | transformer.transform(source, result); |
| 103 | 0 | return writer.toString(); |
| 104 | 0 | } catch (TransformerConfigurationException e) { |
| 105 | 0 | throw new WorkflowRuntimeException("Error configuring transformer to write doc content.", e); |
| 106 | 0 | } catch (TransformerException e) { |
| 107 | 0 | throw new WorkflowRuntimeException("Error transforming DOM into doc content.", e); |
| 108 | |
} |
| 109 | |
} |
| 110 | |
|
| 111 | |
public RouteContext getRouteContext() { |
| 112 | 0 | return this.routeContext; |
| 113 | |
} |
| 114 | |
|
| 115 | |
} |