mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
initial checkin of wcm forms management using xforms implemented by chiba. this currently uses chiba-web but will soon be replaced by our own uigenerator implemented by dojo!
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3444 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
125
source/java/org/alfresco/web/templating/TemplatingService.java
Normal file
125
source/java/org/alfresco/web/templating/TemplatingService.java
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.alfresco.web.templating;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.parsers.*;
|
||||
|
||||
import javax.xml.transform.*;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import org.alfresco.web.templating.xforms.*;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class TemplatingService
|
||||
{
|
||||
private final static TemplatingService INSTANCE = new TemplatingService();
|
||||
|
||||
private ArrayList<TemplateType> templateTypes =
|
||||
new ArrayList<TemplateType>();
|
||||
|
||||
private TemplatingService()
|
||||
{
|
||||
}
|
||||
|
||||
public static TemplatingService getInstance()
|
||||
{
|
||||
return TemplatingService.INSTANCE;
|
||||
}
|
||||
|
||||
public List<TemplateType> getTemplateTypes()
|
||||
{
|
||||
return this.templateTypes;
|
||||
}
|
||||
|
||||
public TemplateType getTemplateType(final String name)
|
||||
{
|
||||
final Iterator it = this.templateTypes.iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
final TemplateType tt = (TemplateType)it.next();
|
||||
if (tt.getName().equals(name))
|
||||
return tt;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void registerTemplateType(final TemplateType tt)
|
||||
{
|
||||
this.templateTypes.add(tt);
|
||||
}
|
||||
|
||||
public TemplateType newTemplateType(final String name,
|
||||
final Document schema)
|
||||
{
|
||||
return new TemplateTypeImpl(name, schema);
|
||||
}
|
||||
|
||||
public void writeXML(final Node d, final File output)
|
||||
{
|
||||
try
|
||||
{
|
||||
System.out.println("writing out a document for " + d.getNodeName() +
|
||||
" to " + output);
|
||||
final TransformerFactory tf = TransformerFactory.newInstance();
|
||||
final Transformer t = tf.newTransformer();
|
||||
t.transform(new DOMSource(d), new StreamResult(output));
|
||||
}
|
||||
catch (TransformerException te)
|
||||
{
|
||||
te.printStackTrace();
|
||||
assert false : te.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public Document parseXML(final String source)
|
||||
throws ParserConfigurationException,
|
||||
SAXException,
|
||||
IOException
|
||||
{
|
||||
return this.parseXML(new ByteArrayInputStream(source.getBytes()));
|
||||
}
|
||||
|
||||
public Document parseXML(final File source)
|
||||
throws ParserConfigurationException,
|
||||
SAXException,
|
||||
IOException
|
||||
{
|
||||
return this.parseXML(new FileInputStream(source));
|
||||
}
|
||||
|
||||
public Document parseXML(final InputStream source)
|
||||
throws ParserConfigurationException,
|
||||
SAXException,
|
||||
IOException
|
||||
{
|
||||
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setNamespaceAware(true);
|
||||
dbf.setValidating(false);
|
||||
final DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
final Document result = db.parse(source);
|
||||
source.close();
|
||||
return result;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user