Files
alfresco-community-repo/source/java/org/alfresco/web/forms/XMLUtil.java
Ariel Backenroth 7e22f28905 beginning to implement linton's updates to xforms screen.
- added ViewRoot which presents a title, rather than a bounding root group.  made the xform generator place all components within a single root group to support this.

- adding highlighting for the currently selected repeat item.  found a bunch of bugs in how the current repeat item is being set.  only dispatching the origin repeat select index for nested repeats.  correctly setting the repeat index after move operation

- updated css to match latest css changes to the product.

began implementing support for inherited complex schema types.
- adding support for xf:switch and xf:toggle in xforms.js.

- refactored and cleaned up a particularly hard to understand part of the xform generator which handles inherited complex types.

- not pretty printing the resulting xml from create web content or edit as it introduces unwanted text nodes which can confuse chiba when xsi:nil is used (i'm using xsi:nil to disable validation when i use xsi:type since otherwise there's a NullPointerException in chiba because it doesn't understand complex type definitions).

- need to think about the design a bit more before continuing with this.  chiba has limitations with how it handles xsi:type which makes it difficult to figure out the correct case to select at schema generation time, especially if the item is repeated.  also, currently the generator emits a select1 to select the type which controls the switch.  i'm not sure whether i actually want a separate select control to manage the switch...

added a test for date types and removed the old one.

added a test for inherited types.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4886 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2007-01-20 00:42:49 +00:00

178 lines
5.4 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)
{
XMLUtil.print(n, output, true);
}
/** utility function for serializing a node */
public static void print(final Node n, final Writer output, final boolean indent)
{
try
{
final TransformerFactory tf = TransformerFactory.newInstance();
final Transformer t = tf.newTransformer();
t.setOutputProperty(OutputKeys.INDENT, indent ? "yes" : "no");
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)
{
return XMLUtil.toString(n, true);
}
/** utility function for serializing a node */
public static String toString(final Node n, final boolean indent)
{
final StringWriter result = new StringWriter();
XMLUtil.print(n, result, indent);
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);
return dbf.newDocumentBuilder();
}
catch (ParserConfigurationException pce)
{
LOGGER.error(pce);
return null;
}
}
}