Run Application View Source Code

Orbeon Forms Apps

Orbeon Forms Source Code Viewer

Loading...
An error has occurred

You may want to try one of the following:

  • Close this dialog and continue to use this page.
  • Reload this page. Note that you will lose any unsaved changes.
  • If the above does not work, try reloading the page yourself. Note that you will lose any unsaved changes:

    • With Firefox and Safari: hold down the shift key and click the Reload button in your browser toolbar.
    • With Internet Explorer: hold down the control key and click the Reload button in your browser toolbar.
  • Return home.
Help
View as text View as text View as formatted XML View as formatted XML Download Download
init-database/ListInitializedTables.java 2,925
init-database/generic-init-database.xpl 1,754
init-database/init-address-book.xpl 2,424
init-database/init-database.xpl 1,346
page-flow.xml 1,176
service-add.xpl 2,146
service-delete.xpl 1,887
service-get.xpl 2,988
view.xhtml 5,825
$xforms-template-label$
/*
    Copyright 2004 Orbeon, Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/
import org.orbeon.oxf.common.OXFException;
import org.orbeon.oxf.pipeline.api.PipelineContext;
import org.orbeon.oxf.processor.DatabaseContext;
import org.orbeon.oxf.processor.Datasource;
import org.orbeon.oxf.processor.ProcessorInputOutputInfo;
import org.orbeon.oxf.processor.SimpleProcessor;
import org.orbeon.oxf.xml.ContentHandlerHelper;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;

/**
 * This processor takes a datasource as input and generates a document containing all the tables
 * starting with "ORBEON_".
 */
public class ListInitializedTables extends SimpleProcessor {

    private static final String INPUT_DATASOURCE = "datasource";

    public ListInitializedTables() {
        addInputInfo(new ProcessorInputOutputInfo(INPUT_DATASOURCE));
        addOutputInfo(new ProcessorInputOutputInfo(OUTPUT_DATA));
    }

    public void generateData(PipelineContext pipelineContext, ContentHandler contentHandler) throws SAXException {
        try {
            // Get connection
            Datasource datasource = Datasource.getDatasource(pipelineContext, this, getInputByName(INPUT_DATASOURCE));
            Connection connection = DatabaseContext.getConnection(pipelineContext, datasource);

            // Determine if we have tables in the database
            DatabaseMetaData metaData = connection.getMetaData();
            ResultSet tables = metaData.getTables(null, null, "ORBEON_%", null);

            // Send the result as XML, outputting one row per table
            ContentHandlerHelper contentHandlerHelper = new ContentHandlerHelper(contentHandler);
            contentHandlerHelper.startDocument();
            contentHandlerHelper.startElement("tables");
            while (tables.next()) {
                contentHandlerHelper.startElement("table");
                contentHandlerHelper.startElement("name");
                contentHandlerHelper.text(tables.getString("TABLE_NAME"));
                contentHandlerHelper.endElement();
                contentHandlerHelper.endElement();
            }
            contentHandlerHelper.endElement();
            contentHandlerHelper.endDocument();
        } catch (Exception e) {
            throw new OXFException(e);
        }
    }
}

Orbeon Forms 3.7.0beta1.200808260135