001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)SecurityInstallConfigWriter.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: /**
030: * SecurityInstallConfigWriter.java
031: *
032: * SUN PROPRIETARY/CONFIDENTIAL.
033: * This software is the proprietary information of Sun Microsystems, Inc.
034: * Use is subject to license terms.
035: *
036: * Created on December 16, 2004, 2:53 PM
037: */package com.sun.jbi.internal.security.config;
038:
039: import java.io.File;
040: import java.io.OutputStream;
041: import java.io.Writer;
042:
043: import javax.jbi.JBIException;
044: import javax.xml.transform.dom.DOMSource;
045: import javax.xml.transform.stream.StreamResult;
046: import javax.xml.transform.TransformerFactory;
047: import javax.xml.transform.Transformer;
048:
049: /**
050: *
051: * @author Sun Microsystems, Inc.
052: */
053: public class SecurityInstallConfigWriter {
054:
055: /** Creates a new instance of SecurityInstallConfigWriter. */
056: public SecurityInstallConfigWriter() {
057: }
058:
059: /**
060: * Write the contents of the Security Configuration out to a file.
061: *
062: * @param config is the source security configuration data.
063: * @param file is the file to write the output to.
064: * @throws JBIException on errors.
065: */
066: public static void write(SecurityConfiguration config, File file)
067: throws JBIException {
068: try {
069: Transformer xformer = TransformerFactory.newInstance()
070: .newTransformer();
071: xformer.setOutputProperty(
072: javax.xml.transform.OutputKeys.INDENT, "yes");
073: xformer.transform(new DOMSource(config.generateDocument()),
074: new StreamResult(file));
075: } catch (Exception ex) {
076: throw new JBIException(ex);
077: }
078: }
079:
080: /**
081: * Write the contents of the Security Configuration out to a outputstream.
082: *
083: * @param config is the source security configuration data.
084: * @param ostr is the OutputStream to write the contents out to.
085: * @throws JBIException on errors.
086: *
087: */
088: public static void write(SecurityConfiguration config,
089: OutputStream ostr) throws JBIException {
090: try {
091: Transformer xformer = TransformerFactory.newInstance()
092: .newTransformer();
093: xformer.setOutputProperty(
094: javax.xml.transform.OutputKeys.INDENT, "yes");
095: xformer.transform(new DOMSource(config.generateDocument()),
096: new StreamResult(ostr));
097: } catch (Exception ex) {
098: throw new JBIException(ex);
099: }
100: }
101:
102: /**
103: * Write the contents of the Security Configuration out to a String.
104: *
105: * @param config is the source security configuration data.
106: * @param writer is the output Writer to write the contents out to.
107: * @throws JBIException on errors.
108: */
109: public static void write(SecurityConfiguration config, Writer writer)
110: throws JBIException {
111: try {
112: Transformer xformer = TransformerFactory.newInstance()
113: .newTransformer();
114: xformer.setOutputProperty(
115: javax.xml.transform.OutputKeys.INDENT, "yes");
116: xformer.transform(new DOMSource(config.generateDocument()),
117: new StreamResult(writer));
118: } catch (Exception ex) {
119: throw new JBIException(ex);
120: }
121:
122: }
123: }
|