mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
removing temp file write in generating xform - instead passing a downloadable url to the schema (which includes the users ticket).
removing xmlbeans - replacing with a super simple and minimal implementation of default xml instance generation (which supports default values). git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3907 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -8,8 +8,6 @@
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Remote API"/>
|
||||
<classpathentry kind="lib" path="/3rd Party/lib/chiba/chiba-1.2.0.jar"/>
|
||||
<classpathentry kind="lib" path="/3rd Party/lib/commons/commons-httpclient-3.0.jar"/>
|
||||
<classpathentry kind="lib" path="/3rd Party/lib/xmlbeans/xbean.jar"/>
|
||||
<classpathentry kind="lib" path="/3rd Party/lib/xmlbeans/jsr173_1.0_api.jar"/>
|
||||
<classpathentry kind="lib" path="/3rd Party/lib/commons/commons-jxpath-1.2.jar"/>
|
||||
<classpathentry kind="lib" path="/3rd Party/lib/xerces-2.8.0/xml-apis.jar"/>
|
||||
<classpathentry kind="lib" path="/3rd Party/lib/xerces-2.8.0/xercesImpl.jar"/>
|
||||
|
@@ -42,7 +42,6 @@
|
||||
<fileset dir="${dir.common.lib}/swarmcache" includes="*.jar" />
|
||||
<fileset dir="${dir.common.lib}/jbpm" includes="*.jar" />
|
||||
<fileset dir="${dir.common.lib}/chiba" includes="*.jar" />
|
||||
<fileset dir="${dir.common.lib}/xmlbeans" includes="*.jar" />
|
||||
<fileset dir="${dir.project.core}/build/dist" includes="${dir.name.core}.jar" />
|
||||
<fileset dir="${dir.project.dependency}/build/dist" includes="${dir.name.dependency}.jar" />
|
||||
<fileset dir="${dir.project.repository}/build/dist" includes="${dir.name.repository}.jar" />
|
||||
|
@@ -18,6 +18,7 @@ package org.alfresco.web.templating;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import java.util.List;
|
||||
import java.net.URI;
|
||||
import java.io.Serializable;
|
||||
//import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
@@ -34,13 +35,12 @@ public interface TemplateType
|
||||
/** the xml schema for this template type */
|
||||
public Document getSchema();
|
||||
|
||||
public String /* URI */ getSchemaURI();
|
||||
|
||||
// public void setSchemaNodeRef(final NodeRef nodeRef);
|
||||
//
|
||||
// public NodeRef getSchemaNodeRef();
|
||||
|
||||
/** Provides a sample xml file for the schema */
|
||||
public Document getSampleXml(final String rootTagName);
|
||||
|
||||
//XXXarielb not used currently and not sure if it's necessary...
|
||||
// public void addInputMethod(final TemplateInputMethod in);
|
||||
|
||||
|
@@ -315,7 +315,9 @@ public final class TemplatingService implements Serializable
|
||||
(n instanceof Document
|
||||
? ((Document)n).getDocumentElement()
|
||||
: n).getNodeName() +
|
||||
" to " + output);
|
||||
" to " + (output instanceof StringWriter
|
||||
? "string"
|
||||
: output));
|
||||
final StringWriter sw = new StringWriter();
|
||||
t.transform(new DOMSource(n), new StreamResult(sw));
|
||||
LOGGER.debug(sw.toString());
|
||||
|
@@ -17,22 +17,16 @@
|
||||
package org.alfresco.web.templating.xforms;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.alfresco.web.templating.*;
|
||||
import org.alfresco.web.templating.xforms.schemabuilder.FormBuilderException;
|
||||
|
||||
import org.apache.xmlbeans.*;
|
||||
import org.apache.xmlbeans.impl.xsd2inst.SampleXmlUtil;
|
||||
|
||||
import org.w3c.dom.*;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.web.app.servlet.DownloadContentServlet;
|
||||
import org.alfresco.web.templating.*;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.*;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class TemplateTypeImpl
|
||||
implements TemplateType
|
||||
@@ -64,6 +58,21 @@ public class TemplateTypeImpl
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String /* URI */ getSchemaURI()
|
||||
{
|
||||
final javax.faces.context.FacesContext fc =
|
||||
javax.faces.context.FacesContext.getCurrentInstance();
|
||||
final javax.servlet.http.HttpSession session = (javax.servlet.http.HttpSession)
|
||||
fc.getExternalContext().getSession(true);
|
||||
|
||||
org.alfresco.web.bean.repository.User user = (org.alfresco.web.bean.repository.User)
|
||||
session.getAttribute(org.alfresco.web.app.servlet.AuthenticationHelper.AUTHENTICATION_USER);
|
||||
|
||||
String result = DownloadContentServlet.generateDownloadURL(this.schemaNodeRef, this.name + ".xsd");
|
||||
result += "?ticket=" + user.getTicket();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Document getSchema()
|
||||
{
|
||||
if (this.schema == null)
|
||||
@@ -81,108 +90,6 @@ public class TemplateTypeImpl
|
||||
return this.schema;
|
||||
}
|
||||
|
||||
public Document getSampleXml(final String rootTagName)
|
||||
{
|
||||
XmlOptions xmlOptions = new XmlOptions();
|
||||
xmlOptions = xmlOptions.setLoadLineNumbers().setLoadMessageDigest();
|
||||
final XmlObject[] schemas = new XmlObject[1];
|
||||
try
|
||||
{
|
||||
schemas[0] = XmlObject.Factory.parse(this.getSchema(), xmlOptions);
|
||||
}
|
||||
catch (XmlException xmle)
|
||||
{
|
||||
LOGGER.error(xmle);
|
||||
}
|
||||
|
||||
final XmlOptions compileOptions = new XmlOptions();
|
||||
compileOptions.setCompileDownloadUrls();
|
||||
compileOptions.setCompileNoPvrRule();
|
||||
compileOptions.setCompileNoUpaRule();
|
||||
|
||||
SchemaTypeSystem sts = null;
|
||||
try
|
||||
{
|
||||
sts = XmlBeans.compileXsd(schemas,
|
||||
XmlBeans.getBuiltinTypeSystem(),
|
||||
compileOptions);
|
||||
}
|
||||
catch (XmlException xmle)
|
||||
{
|
||||
LOGGER.error(xmle);
|
||||
}
|
||||
|
||||
if (sts == null)
|
||||
{
|
||||
throw new NullPointerException("No Schemas to process.");
|
||||
}
|
||||
final SchemaType[] globalElems = sts.documentTypes();
|
||||
SchemaType elem = null;
|
||||
for (int i = 0; i < globalElems.length; i++)
|
||||
{
|
||||
if (rootTagName.equals(globalElems[i].getDocumentElementName().getLocalPart()))
|
||||
{
|
||||
elem = globalElems[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (elem == null)
|
||||
throw new NullPointerException("Could not find a global element with name \"" + rootTagName + "\"");
|
||||
|
||||
final String xmlString = SampleXmlUtil.createSampleForType(elem);
|
||||
try
|
||||
{
|
||||
final TemplatingService ts = TemplatingService.getInstance();
|
||||
final Document d = ts.parseXML(new ByteArrayInputStream(xmlString.getBytes()));
|
||||
LOGGER.debug("sample xml:");
|
||||
LOGGER.debug(ts.writeXMLToString(d));
|
||||
|
||||
TemplateTypeImpl.cleanUpSampleXml(d.getDocumentElement());
|
||||
LOGGER.debug("cleaned up xml:");
|
||||
LOGGER.debug(ts.writeXMLToString(d));
|
||||
return d;
|
||||
}
|
||||
catch (ParserConfigurationException pce)
|
||||
{
|
||||
assert false : pce.getMessage();
|
||||
return null;
|
||||
}
|
||||
catch (SAXException saxe)
|
||||
{
|
||||
assert false : saxe.getMessage();
|
||||
return null;
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
assert false : ioe.getMessage();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void cleanUpSampleXml(final Node n)
|
||||
{
|
||||
if (n instanceof CharacterData)
|
||||
{
|
||||
// System.out.println("replacing data " + ((CharacterData)n).getData());
|
||||
((CharacterData)n).setData(" ");
|
||||
}
|
||||
else if (n instanceof Element)
|
||||
{
|
||||
final NamedNodeMap attrs = n.getAttributes();
|
||||
for (int i = 0; i < attrs.getLength(); i++)
|
||||
{
|
||||
// System.out.println("not replacing data " + ((Attr)n).getValue());
|
||||
// ((Attr)attrs.item(i)).setValue("");
|
||||
}
|
||||
}
|
||||
final NodeList nl = n.getChildNodes();
|
||||
for (int i = 0; i < nl.getLength(); i++)
|
||||
{
|
||||
TemplateTypeImpl.cleanUpSampleXml(nl.item(i));
|
||||
}
|
||||
}
|
||||
|
||||
public List<TemplateInputMethod> getInputMethods()
|
||||
{
|
||||
return INPUT_METHODS;
|
||||
|
@@ -119,32 +119,27 @@ public class XFormsInputMethod
|
||||
public Document getXForm(Document xmlContent, final TemplateType tt)
|
||||
throws FormBuilderException
|
||||
{
|
||||
if (xmlContent == null)
|
||||
xmlContent = tt.getSampleXml(tt.getName());
|
||||
final TemplatingService ts = TemplatingService.getInstance();
|
||||
final FacesContext fc = FacesContext.getCurrentInstance();
|
||||
final HttpServletRequest request = (HttpServletRequest)
|
||||
fc.getExternalContext().getRequest();
|
||||
final String baseUrl = (request.getScheme() + "://" +
|
||||
request.getServerName() + ':' +
|
||||
request.getServerPort());
|
||||
request.getServerPort() +
|
||||
request.getContextPath());
|
||||
LOGGER.debug("using baseUrl " + baseUrl + " for schemaformbuilder");
|
||||
|
||||
final SchemaFormBuilder builder =
|
||||
new BaseSchemaFormBuilder(tt.getName(),
|
||||
xmlContent,
|
||||
request.getContextPath() + "/ajax/invoke/XFormsBean.handleAction",
|
||||
"/ajax/invoke/XFormsBean.handleAction",
|
||||
SchemaFormBuilder.SUBMIT_METHOD_POST,
|
||||
new XHTMLWrapperElementsBuilder(),
|
||||
null,
|
||||
baseUrl,
|
||||
true);
|
||||
baseUrl);
|
||||
LOGGER.debug("building xform for schema " + tt.getName());
|
||||
final Document result = builder.buildForm(tt); //schemaFile.getPath());
|
||||
LOGGER.debug("generated xform:");
|
||||
LOGGER.debug(ts.writeXMLToString(result));
|
||||
// xmlContentFile.delete();
|
||||
// schemaFile.delete();
|
||||
final Document result = builder.buildForm(tt);
|
||||
LOGGER.debug("generated xform: " + result);
|
||||
// LOGGER.debug(ts.writeXMLToString(result));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -51,24 +51,20 @@ public class BaseSchemaFormBuilder
|
||||
* @param action __UNDOCUMENTED__
|
||||
* @param submitMethod __UNDOCUMENTED__
|
||||
* @param wrapper __UNDOCUMENTED__
|
||||
* @param stylesheet __UNDOCUMENTED__
|
||||
*/
|
||||
public BaseSchemaFormBuilder(String rootTagName,
|
||||
Document instanceDocument,
|
||||
String action,
|
||||
String submitMethod,
|
||||
WrapperElementsBuilder wrapper,
|
||||
String stylesheet,
|
||||
String base,
|
||||
boolean userSchemaTypes) {
|
||||
public BaseSchemaFormBuilder(final String rootTagName,
|
||||
final Document instanceDocument,
|
||||
final String action,
|
||||
final String submitMethod,
|
||||
final WrapperElementsBuilder wrapper,
|
||||
final String base)
|
||||
{
|
||||
super(rootTagName,
|
||||
instanceDocument,
|
||||
action,
|
||||
submitMethod,
|
||||
wrapper,
|
||||
stylesheet,
|
||||
base,
|
||||
userSchemaTypes);
|
||||
base);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -493,8 +489,9 @@ public class BaseSchemaFormBuilder
|
||||
* @param maxOccurs __UNDOCUMENTED__
|
||||
* @return __UNDOCUMENTED__
|
||||
*/
|
||||
public Element startBindElement(Element bindElement,
|
||||
XSTypeDefinition controlType,
|
||||
public Element startBindElement(final Element bindElement,
|
||||
final XSModel schema,
|
||||
final XSTypeDefinition controlType,
|
||||
final Occurs o)
|
||||
{
|
||||
// START WORKAROUND
|
||||
@@ -507,7 +504,7 @@ public class BaseSchemaFormBuilder
|
||||
if (!"anyType".equals(controlType.getName()))
|
||||
{
|
||||
Element enveloppe = bindElement.getOwnerDocument().getDocumentElement();
|
||||
String typeName = this.getXFormsTypeName(enveloppe, controlType);
|
||||
String typeName = this.getXFormsTypeName(enveloppe, schema, controlType);
|
||||
if (typeName != null && typeName.length() != 0)
|
||||
bindElement.setAttributeNS(XFORMS_NS,
|
||||
SchemaFormBuilder.XFORMS_NS_PREFIX + "type",
|
||||
@@ -567,11 +564,6 @@ public class BaseSchemaFormBuilder
|
||||
public Element startFormGroup(Element groupElement,
|
||||
XSElementDeclaration schemaElement)
|
||||
{
|
||||
//groupElement.setAttributeNS(CHIBA_NS,getChibaNSPrefix() + "box-align",getProperty(GROUP_BOX_ALIGN_PROP));
|
||||
//groupElement.setAttributeNS(CHIBA_NS,getChibaNSPrefix() + "box-orient",getProperty(GROUP_BOX_ORIENT_PROP));
|
||||
//groupElement.setAttributeNS(CHIBA_NS,getChibaNSPrefix() + "caption-width",getProperty(GROUP_CAPTION_WIDTH_PROP));
|
||||
//groupElement.setAttributeNS(CHIBA_NS,getChibaNSPrefix() + "width",getProperty(GROUP_WIDTH_PROP));
|
||||
//groupElement.setAttributeNS(CHIBA_NS,getChibaNSPrefix() + "border",getProperty(GROUP_BORDER_PROP));
|
||||
return groupElement;
|
||||
}
|
||||
}
|
||||
|
@@ -96,7 +96,7 @@ public interface SchemaFormBuilder
|
||||
"http://www.w3.org/2001/XMLSchema-instance";
|
||||
|
||||
/**
|
||||
* XMLSchema instance prefix *
|
||||
* XMLSchema instance prefix
|
||||
*/
|
||||
public static final String XMLSCHEMA_INSTANCE_NS_PREFIX = "xsi:";
|
||||
|
||||
@@ -180,20 +180,6 @@ public interface SchemaFormBuilder
|
||||
public static final String SUBMIT_METHOD_URLENCODED_POST =
|
||||
"urlencoded-post";
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*
|
||||
* @return __UNDOCUMENTED__
|
||||
*/
|
||||
public String getAction();
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*
|
||||
* @return __UNDOCUMENTED__
|
||||
*/
|
||||
public Document getInstanceDocument();
|
||||
|
||||
/**
|
||||
* Get the current set of properties used by implementations of SchemaFormBuilder.
|
||||
*
|
||||
@@ -226,24 +212,6 @@ public interface SchemaFormBuilder
|
||||
*/
|
||||
public String getProperty(String key, String defaultValue);
|
||||
|
||||
/**
|
||||
* Properties choosed by the user
|
||||
*/
|
||||
public String getRootTagName();
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*
|
||||
* @return __UNDOCUMENTED__
|
||||
*/
|
||||
public String getStylesheet();
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*
|
||||
* @return __UNDOCUMENTED__
|
||||
*/
|
||||
public String getSubmitMethod();
|
||||
|
||||
/**
|
||||
* Generate the XForm based on a user supplied XML Schema.
|
||||
@@ -440,6 +408,7 @@ public interface SchemaFormBuilder
|
||||
* @return The bind Element to use in the XForm - bindElement or a replacement.
|
||||
*/
|
||||
public Element startBindElement(Element bindElement,
|
||||
XSModel schema,
|
||||
XSTypeDefinition controlType,
|
||||
Occurs occurs);
|
||||
|
||||
|
Reference in New Issue
Block a user