List of usage examples for org.xml.sax ContentHandler startElement
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException;
From source file:nl.architolk.ldt.processors.HttpClientProcessor.java
public void generateData(PipelineContext context, ContentHandler contentHandler) throws SAXException { try {/*from w w w .ja v a2 s . c o m*/ CloseableHttpClient httpclient = HttpClientProperties.createHttpClient(); try { // Read content of config pipe Document configDocument = readInputAsDOM4J(context, INPUT_CONFIG); Node configNode = configDocument.selectSingleNode("//config"); URL theURL = new URL(configNode.valueOf("url")); if (configNode.valueOf("auth-method").equals("basic")) { HttpHost targetHost = new HttpHost(theURL.getHost(), theURL.getPort(), theURL.getProtocol()); //Authentication support CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials( configNode.valueOf("username"), configNode.valueOf("password"))); // logger.info("Credentials: "+configNode.valueOf("username")+"/"+configNode.valueOf("password")); // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); authCache.put(targetHost, new BasicScheme()); // Add AuthCache to the execution context httpContext = HttpClientContext.create(); httpContext.setCredentialsProvider(credsProvider); httpContext.setAuthCache(authCache); } else if (configNode.valueOf("auth-method").equals("form")) { //Sign in. Cookie will be remembered bij httpclient HttpPost authpost = new HttpPost(configNode.valueOf("auth-url")); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("userName", configNode.valueOf("username"))); nameValuePairs.add(new BasicNameValuePair("password", configNode.valueOf("password"))); authpost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); CloseableHttpResponse httpResponse = httpclient.execute(authpost); // logger.info("Signin response:"+Integer.toString(httpResponse.getStatusLine().getStatusCode())); } CloseableHttpResponse response; if (configNode.valueOf("method").equals("post")) { // POST HttpPost httpRequest = new HttpPost(configNode.valueOf("url")); setBody(httpRequest, context, configNode); response = executeRequest(httpRequest, httpclient); } else if (configNode.valueOf("method").equals("put")) { // PUT HttpPut httpRequest = new HttpPut(configNode.valueOf("url")); setBody(httpRequest, context, configNode); response = executeRequest(httpRequest, httpclient); } else if (configNode.valueOf("method").equals("delete")) { //DELETE HttpDelete httpRequest = new HttpDelete(configNode.valueOf("url")); response = executeRequest(httpRequest, httpclient); } else if (configNode.valueOf("method").equals("head")) { //HEAD HttpHead httpRequest = new HttpHead(configNode.valueOf("url")); response = executeRequest(httpRequest, httpclient); } else if (configNode.valueOf("method").equals("options")) { //OPTIONS HttpOptions httpRequest = new HttpOptions(configNode.valueOf("url")); response = executeRequest(httpRequest, httpclient); } else { //Default = GET HttpGet httpRequest = new HttpGet(configNode.valueOf("url")); String acceptHeader = configNode.valueOf("accept"); if (!acceptHeader.isEmpty()) { httpRequest.addHeader("accept", configNode.valueOf("accept")); } //Add proxy route if needed HttpClientProperties.setProxy(httpRequest, theURL.getHost()); response = executeRequest(httpRequest, httpclient); } try { contentHandler.startDocument(); int status = response.getStatusLine().getStatusCode(); AttributesImpl statusAttr = new AttributesImpl(); statusAttr.addAttribute("", "status", "status", "CDATA", Integer.toString(status)); contentHandler.startElement("", "response", "response", statusAttr); if (status >= 200 && status < 300) { HttpEntity entity = response.getEntity(); Header contentType = response.getFirstHeader("Content-Type"); if (entity != null && contentType != null) { //logger.info("Contenttype: " + contentType.getValue()); //Read content into inputstream InputStream inStream = entity.getContent(); // output-type = json means: response is json, convert to xml if (configNode.valueOf("output-type").equals("json")) { //TODO: net.sf.json.JSONObject might nog be the correct JSONObject. javax.json.JsonObject might be better!!! //javax.json contains readers to read from an inputstream StringWriter writer = new StringWriter(); IOUtils.copy(inStream, writer, "UTF-8"); JSONObject json = JSONObject.fromObject(writer.toString()); parseJSONObject(contentHandler, json); // output-type = xml means: response is xml, keep it } else if (configNode.valueOf("output-type").equals("xml")) { try { XMLReader saxParser = XMLParsing .newXMLReader(new XMLParsing.ParserConfiguration(false, false, false)); saxParser.setContentHandler(new ParseHandler(contentHandler)); saxParser.parse(new InputSource(inStream)); } catch (Exception e) { throw new OXFException(e); } // output-type = jsonld means: reponse is json-ld, (a) convert to nquads; (b) convert to xml } else if (configNode.valueOf("output-type").equals("jsonld")) { try { Object jsonObject = JsonUtils.fromInputStream(inStream, "UTF-8"); //TODO: UTF-8 should be read from response! Object nquads = JsonLdProcessor.toRDF(jsonObject, new NQuadTripleCallback()); Any23 runner = new Any23(); DocumentSource source = new StringDocumentSource((String) nquads, configNode.valueOf("url")); ByteArrayOutputStream out = new ByteArrayOutputStream(); TripleHandler handler = new RDFXMLWriter(out); try { runner.extract(source, handler); } finally { handler.close(); } ByteArrayInputStream inJsonStream = new ByteArrayInputStream(out.toByteArray()); XMLReader saxParser = XMLParsing .newXMLReader(new XMLParsing.ParserConfiguration(false, false, false)); saxParser.setContentHandler(new ParseHandler(contentHandler)); saxParser.parse(new InputSource(inJsonStream)); } catch (Exception e) { throw new OXFException(e); } // output-type = rdf means: response is some kind of rdf (except json-ld...), convert to xml } else if (configNode.valueOf("output-type").equals("rdf")) { try { Any23 runner = new Any23(); DocumentSource source; //If contentType = text/html than convert from html to xhtml to handle non-xml style html! logger.info("Contenttype: " + contentType.getValue()); if (configNode.valueOf("tidy").equals("yes") && contentType.getValue().startsWith("text/html")) { org.jsoup.nodes.Document doc = Jsoup.parse(inStream, "UTF-8", configNode.valueOf("url")); //TODO UTF-8 should be read from response! RDFCleaner cleaner = new RDFCleaner(); org.jsoup.nodes.Document cleandoc = cleaner.clean(doc); cleandoc.outputSettings().escapeMode(Entities.EscapeMode.xhtml); cleandoc.outputSettings() .syntax(org.jsoup.nodes.Document.OutputSettings.Syntax.xml); cleandoc.outputSettings().charset("UTF-8"); source = new StringDocumentSource(cleandoc.html(), configNode.valueOf("url"), contentType.getValue()); } else { source = new ByteArrayDocumentSource(inStream, configNode.valueOf("url"), contentType.getValue()); } ByteArrayOutputStream out = new ByteArrayOutputStream(); TripleHandler handler = new RDFXMLWriter(out); try { runner.extract(source, handler); } finally { handler.close(); } ByteArrayInputStream inAnyStream = new ByteArrayInputStream(out.toByteArray()); XMLReader saxParser = XMLParsing .newXMLReader(new XMLParsing.ParserConfiguration(false, false, false)); saxParser.setContentHandler(new ParseHandler(contentHandler)); saxParser.parse(new InputSource(inAnyStream)); } catch (Exception e) { throw new OXFException(e); } } else { CharArrayWriter writer = new CharArrayWriter(); IOUtils.copy(inStream, writer, "UTF-8"); contentHandler.characters(writer.toCharArray(), 0, writer.size()); } } } contentHandler.endElement("", "response", "response"); contentHandler.endDocument(); } finally { response.close(); } } finally { httpclient.close(); } } catch (Exception e) { throw new OXFException(e); } }
From source file:org.apache.cocoon.components.notification.Notifier.java
/** * Generate notification information in XML format. *///from w ww . j av a2 s.c om public static void notify(Notifying n, ContentHandler ch, String mimetype) throws SAXException { final String PREFIX = Constants.ERROR_NAMESPACE_PREFIX; final String URI = Constants.ERROR_NAMESPACE_URI; // Start the document ch.startDocument(); ch.startPrefixMapping(PREFIX, URI); // Root element. AttributesImpl atts = new AttributesImpl(); atts.addAttribute(URI, "type", PREFIX + ":type", "CDATA", n.getType()); atts.addAttribute(URI, "sender", PREFIX + ":sender", "CDATA", n.getSender()); ch.startElement(URI, "notify", PREFIX + ":notify", atts); ch.startElement(URI, "title", PREFIX + ":title", new AttributesImpl()); ch.characters(n.getTitle().toCharArray(), 0, n.getTitle().length()); ch.endElement(URI, "title", PREFIX + ":title"); ch.startElement(URI, "source", PREFIX + ":source", new AttributesImpl()); ch.characters(n.getSource().toCharArray(), 0, n.getSource().length()); ch.endElement(URI, "source", PREFIX + ":source"); ch.startElement(URI, "message", PREFIX + ":message", new AttributesImpl()); if (n.getMessage() != null) { ch.characters(n.getMessage().toCharArray(), 0, n.getMessage().length()); } ch.endElement(URI, "message", PREFIX + ":message"); ch.startElement(URI, "description", PREFIX + ":description", XMLUtils.EMPTY_ATTRIBUTES); ch.characters(n.getDescription().toCharArray(), 0, n.getDescription().length()); ch.endElement(URI, "description", PREFIX + ":description"); Map extraDescriptions = n.getExtraDescriptions(); for (Iterator i = extraDescriptions.entrySet().iterator(); i.hasNext();) { final Map.Entry me = (Map.Entry) i.next(); String key = (String) me.getKey(); String value = String.valueOf(me.getValue()); atts = new AttributesImpl(); atts.addAttribute(URI, "description", PREFIX + ":description", "CDATA", key); ch.startElement(URI, "extra", PREFIX + ":extra", atts); ch.characters(value.toCharArray(), 0, value.length()); ch.endElement(URI, "extra", PREFIX + ":extra"); } // End root element. ch.endElement(URI, "notify", PREFIX + ":notify"); // End the document. ch.endPrefixMapping(PREFIX); ch.endDocument(); }
From source file:org.apache.cocoon.components.source.impl.QDoxSource.java
/** * Method saxStartElement./*from ww w . ja v a2 s .co m*/ * * @param handler * @param localName */ private void saxStartElement(ContentHandler handler, String localName) throws SAXException { handler.startElement(NS_URI, localName, NS_PREFIX + ':' + localName, XMLUtils.EMPTY_ATTRIBUTES); }
From source file:org.apache.cocoon.components.source.impl.QDoxSource.java
/** * Method saxStartElement.//from ww w . j a va 2s .c o m * * @param handler * @param localName * @param attrs */ private void saxStartElement(ContentHandler handler, String localName, String[][] attrs) throws SAXException { AttributesImpl saxAttrs = new AttributesImpl(); for (int i = 0; i < attrs.length; i++) { if (attrs[i].length == 2) { saxAttrs.addAttribute("", attrs[i][0], attrs[i][0], ATTR_TYPE, attrs[i][1]); } else if (attrs[i].length == 5) { saxAttrs.addAttribute(attrs[i][0], attrs[i][1], attrs[i][2], attrs[i][3], attrs[i][4]); } } handler.startElement(NS_URI, localName, NS_PREFIX + ':' + localName, saxAttrs); }
From source file:org.apache.cocoon.components.source.impl.WebDAVSource.java
private void resourcesToSax(WebdavResource[] resources, ContentHandler handler) throws SAXException { for (int i = 0; i < resources.length; i++) { if (getLogger().isDebugEnabled()) { final String message = "RESOURCE: " + resources[i].getDisplayName(); getLogger().debug(message);//from w w w .j a v a 2s .c om } if (resources[i].isCollection()) { try { WebdavResource[] childs = resources[i].listWebdavResources(); AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute(NAMESPACE, COLLECTION_NAME, PREFIX + ":name", "CDATA", resources[i].getDisplayName()); handler.startElement(NAMESPACE, COLLECTION_NAME, PREFIX + ":" + COLLECTION_NAME, attrs); this.resourcesToSax(childs, handler); handler.endElement(NAMESPACE, COLLECTION_NAME, PREFIX + ":" + COLLECTION_NAME); } catch (HttpException e) { if (getLogger().isDebugEnabled()) { final String message = "Unable to get WebDAV children. Server responded " + e.getReasonCode() + " (" + e.getReason() + ") - " + e.getMessage(); getLogger().debug(message); } } catch (SAXException e) { if (getLogger().isDebugEnabled()) { final String message = "Unable to get WebDAV children: " + e.getMessage(); getLogger().debug(message, e); } } catch (IOException e) { if (getLogger().isDebugEnabled()) { final String message = "Unable to get WebDAV children: " + e.getMessage(); getLogger().debug(message, e); } } catch (Exception e) { if (getLogger().isDebugEnabled()) { final String message = "Unable to get WebDAV children: " + e.getMessage(); getLogger().debug(message, e); } } } else { AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute(NAMESPACE, "name", PREFIX + ":name", "CDATA", resources[i].getDisplayName()); handler.startElement(NAMESPACE, RESOURCE_NAME, PREFIX + ":" + RESOURCE_NAME, attrs); handler.endElement(NAMESPACE, RESOURCE_NAME, PREFIX + ":" + RESOURCE_NAME); } } }
From source file:org.apache.cocoon.forms.datatype.EnumSelectionList.java
public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { try {/*from w w w . ja va 2 s. c o m*/ contentHandler.startElement(FormsConstants.INSTANCE_NS, SELECTION_LIST_EL, FormsConstants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL, XMLUtils.EMPTY_ATTRIBUTES); // Create void element if (nullable) { AttributesImpl voidAttrs = new AttributesImpl(); voidAttrs.addCDATAAttribute("value", ""); contentHandler.startElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL, voidAttrs); if (this.nullText != null) { contentHandler.startElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL, XMLUtils.EMPTY_ATTRIBUTES); contentHandler.startElement(FormsConstants.I18N_NS, TEXT_EL, FormsConstants.I18N_PREFIX_COLON + TEXT_EL, XMLUtils.EMPTY_ATTRIBUTES); contentHandler.characters(nullText.toCharArray(), 0, nullText.length()); contentHandler.endElement(FormsConstants.I18N_NS, TEXT_EL, FormsConstants.I18N_PREFIX_COLON + TEXT_EL); contentHandler.endElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL); } contentHandler.endElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL); } // Test if we have an apache enum class boolean apacheEnumDone = false; if (Enum.class.isAssignableFrom(clazz)) { Iterator iter = EnumUtils.iterator(clazz); if (iter != null) { apacheEnumDone = true; while (iter.hasNext()) { Enum element = (Enum) iter.next(); String stringValue = clazz.getName() + "." + element.getName(); generateItem(contentHandler, stringValue); } } } // If it's not an apache enum or we didn't manage to read the enum list, then proceed with common method. if (!apacheEnumDone) { Field fields[] = clazz.getDeclaredFields(); for (int i = 0; i < fields.length; ++i) { int mods = fields[i].getModifiers(); if (Modifier.isPublic(mods) && Modifier.isStatic(mods) && Modifier.isFinal(mods) && fields[i].get(null).getClass().equals(clazz)) { String stringValue = clazz.getName() + "." + fields[i].getName(); generateItem(contentHandler, stringValue); } } } // End the selection-list contentHandler.endElement(FormsConstants.INSTANCE_NS, SELECTION_LIST_EL, FormsConstants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL); } catch (Exception e) { throw new SAXException("Got exception trying to get enum's values", e); } }
From source file:org.apache.cocoon.forms.datatype.EnumSelectionList.java
/** * Generates a single selection list item. * @param contentHandler The content handler we are streaming sax events to. * @param stringValue The string name of the item, composed by FQN and enum item. * @throws SAXException/*from w w w . j a va 2s. c o m*/ */ private void generateItem(ContentHandler contentHandler, String stringValue) throws SAXException { // Output this item AttributesImpl itemAttrs = new AttributesImpl(); itemAttrs.addCDATAAttribute("value", stringValue); contentHandler.startElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL, itemAttrs); contentHandler.startElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL, XMLUtils.EMPTY_ATTRIBUTES); // TODO: make i18n element optional contentHandler.startElement(FormsConstants.I18N_NS, TEXT_EL, FormsConstants.I18N_PREFIX_COLON + TEXT_EL, XMLUtils.EMPTY_ATTRIBUTES); contentHandler.characters(stringValue.toCharArray(), 0, stringValue.length()); contentHandler.endElement(FormsConstants.I18N_NS, TEXT_EL, FormsConstants.I18N_PREFIX_COLON + TEXT_EL); contentHandler.endElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL); contentHandler.endElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL); }
From source file:org.apache.cocoon.forms.datatype.FlowJXPathSelectionList.java
public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { JXPathContext ctx = null;/*from ww w . j a v a2 s . co m*/ Iterator iter = null; if (model == null) { Object flowData = FlowHelper.getContextObject(ContextHelper.getObjectModel(this.context)); if (flowData == null) { throw new SAXException("No flow data to produce selection list"); } // Move to the list location ctx = JXPathContext.newContext(flowData); // Iterate on all elements of the list iter = ctx.iteratePointers(this.listPath); } else { // Move to the list location ctx = JXPathContext.newContext(model); // Iterate on all elements of the list iter = ctx.iteratePointers("."); } // Start the selection-list contentHandler.startElement(FormsConstants.INSTANCE_NS, SELECTION_LIST_EL, FormsConstants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL, XMLUtils.EMPTY_ATTRIBUTES); if (this.nullable) { final AttributesImpl voidAttrs = new AttributesImpl(); voidAttrs.addCDATAAttribute("value", ""); contentHandler.startElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL, voidAttrs); if (this.nullText != null) { contentHandler.startElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL, XMLUtils.EMPTY_ATTRIBUTES); if (this.nullTextIsI18nKey) { if ((this.i18nCatalog != null) && (this.i18nCatalog.trim().length() > 0)) { new I18nMessage(this.nullText, this.i18nCatalog).toSAX(contentHandler); } else { new I18nMessage(this.nullText).toSAX(contentHandler); } } else { contentHandler.characters(this.nullText.toCharArray(), 0, this.nullText.length()); } contentHandler.endElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL); } contentHandler.endElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL); } while (iter.hasNext()) { String stringValue = ""; Object label = null; // Get a context on the current item Pointer ptr = (Pointer) iter.next(); if (ptr.getValue() != null) { JXPathContext itemCtx = ctx.getRelativeContext(ptr); // Get the value as a string Object value = itemCtx.getValue(this.valuePath); // List may contain null value, and (per contract with convertors), // convertors are not invoked on nulls. if (value != null) { stringValue = this.datatype.convertToString(value, locale); } // Get the label (can be ommitted) itemCtx.setLenient(true); label = itemCtx.getValue(this.labelPath); if (label == null) { label = stringValue; } } // Output this item AttributesImpl itemAttrs = new AttributesImpl(); itemAttrs.addCDATAAttribute("value", stringValue); contentHandler.startElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL, itemAttrs); if (label != null) { contentHandler.startElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL, XMLUtils.EMPTY_ATTRIBUTES); if (label instanceof XMLizable) { ((XMLizable) label).toSAX(contentHandler); } else if (this.labelIsI18nKey) { String stringLabel = label.toString(); if ((this.i18nCatalog != null) && (this.i18nCatalog.trim().length() > 0)) { new I18nMessage(stringLabel, this.i18nCatalog).toSAX(contentHandler); } else { new I18nMessage(stringLabel).toSAX(contentHandler); } } else { String stringLabel = label.toString(); contentHandler.characters(stringLabel.toCharArray(), 0, stringLabel.length()); } contentHandler.endElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL); } contentHandler.endElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL); } // End the selection-list contentHandler.endElement(FormsConstants.INSTANCE_NS, SELECTION_LIST_EL, FormsConstants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL); }
From source file:org.apache.cocoon.forms.formmodel.BooleanField.java
public void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { // value element contentHandler.startElement(FormsConstants.INSTANCE_NS, VALUE_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALUE_EL, XMLUtils.EMPTY_ATTRIBUTES); String stringValue = BooleanUtils.toBoolean(value) ? definition.getTrueParamValue() : "false"; contentHandler.characters(stringValue.toCharArray(), 0, stringValue.length()); contentHandler.endElement(FormsConstants.INSTANCE_NS, VALUE_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALUE_EL); // validation message element: only present if the value is not valid if (validationError != null) { contentHandler.startElement(FormsConstants.INSTANCE_NS, VALIDATION_MSG_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALIDATION_MSG_EL, XMLUtils.EMPTY_ATTRIBUTES); validationError.generateSaxFragment(contentHandler); contentHandler.endElement(FormsConstants.INSTANCE_NS, VALIDATION_MSG_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALIDATION_MSG_EL); }//from w w w. j a v a 2s .c om }
From source file:org.apache.cocoon.forms.formmodel.Field.java
public void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { if (locale == null) { locale = getForm().getLocale();//from ww w. j a v a 2s . c om } if (enteredValue != null || value != null) { contentHandler.startElement(FormsConstants.INSTANCE_NS, VALUE_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALUE_EL, XMLUtils.EMPTY_ATTRIBUTES); String stringValue; if (value != null) { stringValue = getDatatype().convertToString(value, locale); } else { stringValue = enteredValue; } contentHandler.characters(stringValue.toCharArray(), 0, stringValue.length()); contentHandler.endElement(FormsConstants.INSTANCE_NS, VALUE_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALUE_EL); } // Suggested label, if any String suggestedLabel = getSuggestionLabel(); if (suggestedLabel != null) { contentHandler.startElement(FormsConstants.INSTANCE_NS, "suggestion", FormsConstants.INSTANCE_PREFIX_COLON + "suggestion", XMLUtils.EMPTY_ATTRIBUTES); contentHandler.characters(suggestedLabel.toCharArray(), 0, suggestedLabel.length()); contentHandler.endElement(FormsConstants.INSTANCE_NS, "suggestion", FormsConstants.INSTANCE_PREFIX_COLON + "suggestion"); } // validation message element: only present if the value is not valid if (validationError != null && (this.valueState == VALUE_DISPLAY_VALIDATION || this.valueState == VALUE_DISPLAY_PARSE_ERROR)) { contentHandler.startElement(FormsConstants.INSTANCE_NS, VALIDATION_MSG_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALIDATION_MSG_EL, XMLUtils.EMPTY_ATTRIBUTES); validationError.generateSaxFragment(contentHandler); contentHandler.endElement(FormsConstants.INSTANCE_NS, VALIDATION_MSG_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALIDATION_MSG_EL); } // generate selection list, if any if (selectionList != null) { selectionList.generateSaxFragment(contentHandler, locale); } // include some info about the datatype fieldDefinition.getDatatype().generateSaxFragment(contentHandler, locale); }