Files
alfresco-community-repo/source/java/org/alfresco/web/forms/XMLUtil.java
Ariel Backenroth a25d85ee83 - moving generic xml parsing utilities out of FormsService and into their own class
- refactoring to generate and regenerate methods to make it easier to use project level overridden properties, and to at some point (soon) make it possible to make error handling for rendering engines more robust
- added a web project object to encapsulate web project properties and provide a central location for getting forms and rendering engines with web project level overridden properties
- made select default workflow screen match wireframes
- using the same workflowdefault type in the wcm model for web projects and forms.
- using outputpathpattern aspect consistently
- using commons.io to parse paths
- using form name rather than noderef as parameter for selected form from content forms dashlet
- fixed bug where rendition properties noderef wasn't being properly associated with renditions causing problems with regenerate
- using multivalued properties to track renditions
- remove weird registerRendition/registerFormInstanceData calls.  no longer necessary since generateRendition and regenerate are done within forminstancedata and rendition
- adding default workflow parameters as property of Form
- adding a unique name property to rendering engine templates to allow for looking one up by name


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4702 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2006-12-31 08:45:42 +00:00

165 lines
5.1 KiB
Java

/*
* 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.forms;
import java.io.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
/**
* XML utility functions.
*
* @author Ariel Backenroth
*/
public class XMLUtil
{
private static final Log LOGGER = LogFactory.getLog(XMLUtil.class);
private static DocumentBuilder documentBuilder;
/** utility function for creating a document */
public static Document newDocument()
{
return XMLUtil.getDocumentBuilder().newDocument();
}
/** utility function for serializing a node */
public static void print(final Node n, final Writer output)
{
try
{
final TransformerFactory tf = TransformerFactory.newInstance();
final Transformer t = tf.newTransformer();
t.setOutputProperty(OutputKeys.INDENT, "yes");
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("writing out a document for " +
(n instanceof Document
? ((Document)n).getDocumentElement()
: n).getNodeName() +
" to " + (output instanceof StringWriter
? "string"
: output));
}
t.transform(new DOMSource(n), new StreamResult(output));
}
catch (TransformerException te)
{
te.printStackTrace();
assert false : te.getMessage();
}
}
/** utility function for serializing a node */
public static void print(final Node n, final File output)
throws IOException
{
XMLUtil.print(n, new FileWriter(output));
}
/** utility function for serializing a node */
public static String toString(final Node n)
{
final StringWriter result = new StringWriter();
XMLUtil.print(n, result);
return result.toString();
}
/** utility function for parsing xml */
public static Document parse(final String source)
throws SAXException,
IOException
{
return XMLUtil.parse(new ByteArrayInputStream(source.getBytes()));
}
/** utility function for parsing xml */
public static Document parse(final NodeRef nodeRef,
final ContentService contentService)
throws SAXException,
IOException
{
final ContentReader contentReader =
contentService.getReader(nodeRef, ContentModel.TYPE_CONTENT);
final InputStream in = contentReader.getContentInputStream();
return XMLUtil.parse(in);
}
/** utility function for parsing xml */
public static Document parse(final File source)
throws SAXException,
IOException
{
return XMLUtil.parse(new FileInputStream(source));
}
/** utility function for parsing xml */
public static Document parse(final InputStream source)
throws SAXException,
IOException
{
final DocumentBuilder db = XMLUtil.getDocumentBuilder();
final Document result = db.parse(source);
source.close();
return result;
}
/** provides a document builder that is namespace aware but not validating by default */
public static DocumentBuilder getDocumentBuilder()
{
if (XMLUtil.documentBuilder == null)
{
XMLUtil.documentBuilder = XMLUtil.getDocumentBuilder(true, false);
}
return XMLUtil.documentBuilder;
}
public static DocumentBuilder getDocumentBuilder(final boolean namespaceAware,
final boolean validating)
try
{
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(namespaceAware);
dbf.setValidating(validating);
XMLUtil.documentBuilder = dbf.newDocumentBuilder();
}
catch (ParserConfigurationException pce)
{
LOGGER.error(pce);
}
}
return XMLUtil.documentBuilder;
}
}