From 54aa4703e3d66c5b1a63b8d925fd4c9c1766687c Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 28 Jan 2009 19:40:11 +0000 Subject: activation git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@291 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../slcommands/impl/InfoboxReadResultFileImpl.java | 197 +++++++++++---------- 1 file changed, 100 insertions(+), 97 deletions(-) (limited to 'bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java') diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java index d8295227..75e44afa 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java @@ -14,8 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.bku.slcommands.impl; - +package at.gv.egiz.bku.slcommands.impl; + +import at.gv.egiz.marshal.NamespacePrefixMapperImpl; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; @@ -40,86 +41,88 @@ import at.gv.egiz.bku.slcommands.InfoboxReadResult; import at.gv.egiz.bku.slcommands.SLCommand; import at.gv.egiz.bku.slcommands.SLCommandFactory; import at.gv.egiz.bku.slexceptions.SLRuntimeException; - -/** - * This class implements the result of the security layer command InfoboxReadRequest. - * - * @author mcentner - */ -public class InfoboxReadResultFileImpl extends SLResultImpl implements - InfoboxReadResult { - - /** - * Logging facility. - */ - protected static Log log = LogFactory.getLog(InfoboxReadResultFileImpl.class); - - /** - * The XML document containing the infobox content. - */ - protected Document xmlDocument; - - /** - * Creates the response document from the given binaryContent. - * - * @param binaryContent the infobox content - * @param preserveSpace the value of the preserveSpace parameter - * - * @return the created response document - */ - private Document createResponseDocument(byte[] binaryContent, boolean preserveSpace) { - - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - Document doc; - try { - doc = dbf.newDocumentBuilder().newDocument(); - } catch (ParserConfigurationException e) { - // it should always be possible to create a new Document - log.error("Failed to create XML document.", e); - throw new SLRuntimeException(e); - } - - ObjectFactory factory = new ObjectFactory(); - - Base64XMLContentType base64XMLContentType = factory.createBase64XMLContentType(); - if (binaryContent == null) { - XMLContentType xmlContentType = factory.createXMLContentType(); - if (preserveSpace) { - xmlContentType.setSpace("preserve"); - } - base64XMLContentType.setXMLContent(xmlContentType); - } else { - base64XMLContentType.setBase64Content(binaryContent); - } - InfoboxReadResponseType infoboxReadResponseType = factory.createInfoboxReadResponseType(); - infoboxReadResponseType.setBinaryFileData(base64XMLContentType); - - JAXBElement infoboxReadResponse = factory.createInfoboxReadResponse(infoboxReadResponseType); - - JAXBContext context = SLCommandFactory.getInstance().getJaxbContext(); - try { - Marshaller marshaller = context.createMarshaller(); - marshaller.marshal(infoboxReadResponse, doc); - } catch (JAXBException e) { - log.error("Failed to marshal 'InfoboxReadResponse' document.", e); - throw new SLRuntimeException(e); - } - - return doc; - - } - - - /** - * @return an XMLResult for marshalling the infobox to - */ - public Result getXmlResult(boolean preserveSpace) { - - xmlDocument = createResponseDocument(null, preserveSpace); - - NodeList nodeList = xmlDocument.getElementsByTagNameNS(SLCommand.NAMESPACE_URI, "XMLContent"); - return new DOMResult(nodeList.item(0)); - +import at.gv.egiz.marshal.MarshallerFactory; +import javax.xml.bind.PropertyException; + +/** + * This class implements the result of the security layer command InfoboxReadRequest. + * + * @author mcentner + */ +public class InfoboxReadResultFileImpl extends SLResultImpl implements + InfoboxReadResult { + + /** + * Logging facility. + */ + protected static Log log = LogFactory.getLog(InfoboxReadResultFileImpl.class); + + /** + * The XML document containing the infobox content. + */ + protected Document xmlDocument; + + /** + * Creates the response document from the given binaryContent. + * + * @param binaryContent the infobox content + * @param preserveSpace the value of the preserveSpace parameter + * + * @return the created response document + */ + private Document createResponseDocument(byte[] binaryContent, boolean preserveSpace) { + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + Document doc; + try { + doc = dbf.newDocumentBuilder().newDocument(); + } catch (ParserConfigurationException e) { + // it should always be possible to create a new Document + log.error("Failed to create XML document.", e); + throw new SLRuntimeException(e); + } + + ObjectFactory factory = new ObjectFactory(); + + Base64XMLContentType base64XMLContentType = factory.createBase64XMLContentType(); + if (binaryContent == null) { + XMLContentType xmlContentType = factory.createXMLContentType(); + if (preserveSpace) { + xmlContentType.setSpace("preserve"); + } + base64XMLContentType.setXMLContent(xmlContentType); + } else { + base64XMLContentType.setBase64Content(binaryContent); + } + InfoboxReadResponseType infoboxReadResponseType = factory.createInfoboxReadResponseType(); + infoboxReadResponseType.setBinaryFileData(base64XMLContentType); + + JAXBElement infoboxReadResponse = factory.createInfoboxReadResponse(infoboxReadResponseType); + + JAXBContext context = SLCommandFactory.getInstance().getJaxbContext(); + try { + Marshaller marshaller = MarshallerFactory.createMarshaller(context); + marshaller.marshal(infoboxReadResponse, doc); + } catch (JAXBException e) { + log.error("Failed to marshal 'InfoboxReadResponse' document.", e); + throw new SLRuntimeException(e); + } + + return doc; + + } + + + /** + * @return an XMLResult for marshalling the infobox to + */ + public Result getXmlResult(boolean preserveSpace) { + + xmlDocument = createResponseDocument(null, preserveSpace); + + NodeList nodeList = xmlDocument.getElementsByTagNameNS(SLCommand.NAMESPACE_URI, "XMLContent"); + return new DOMResult(nodeList.item(0)); + } /** @@ -142,21 +145,21 @@ public class InfoboxReadResultFileImpl extends SLResultImpl implements } - /** - * Creates a new result document for this InfoboxReadResult - * and sets the given resultBytes as content. - * - * @param resultBytes - */ - public void setResultBytes(byte[] resultBytes) { - - xmlDocument = createResponseDocument(resultBytes, false); - - } - + /** + * Creates a new result document for this InfoboxReadResult + * and sets the given resultBytes as content. + * + * @param resultBytes + */ + public void setResultBytes(byte[] resultBytes) { + + xmlDocument = createResponseDocument(resultBytes, false); + + } + @Override public void writeTo(Result result, Templates templates) { writeTo(xmlDocument, result, templates); - } - -} + } + +} -- cgit v1.2.3