List of usage examples for java.lang StringBuffer insert
@Override public StringBuffer insert(int offset, double d)
From source file:com.microsoft.tfs.core.httpclient.URI.java
/** * Set the path.//from w w w .j a va 2s . com * * @param path * the path string * @throws URIException * set incorrectly or fragment only * @see #encode */ public void setPath(final String path) throws URIException { if (path == null || path.length() == 0) { _path = _opaque = (path == null) ? null : path.toCharArray(); setURI(); return; } // set the charset to do escape encoding final String charset = getProtocolCharset(); if (_is_net_path || _is_abs_path) { _path = encode(path, allowed_abs_path, charset); } else if (_is_rel_path) { final StringBuffer buff = new StringBuffer(path.length()); final int at = path.indexOf('/'); if (at == 0) { // never 0 throw new URIException(URIException.PARSING, "incorrect relative path"); } if (at > 0) { buff.append(encode(path.substring(0, at), allowed_rel_path, charset)); buff.append(encode(path.substring(at), allowed_abs_path, charset)); } else { buff.append(encode(path, allowed_rel_path, charset)); } _path = buff.toString().toCharArray(); } else if (_is_opaque_part) { final StringBuffer buf = new StringBuffer(); buf.insert(0, encode(path.substring(0, 1), uric_no_slash, charset)); buf.insert(1, encode(path.substring(1), uric, charset)); _opaque = buf.toString().toCharArray(); } else { throw new URIException(URIException.PARSING, "incorrect path"); } setURI(); }
From source file:com.enonic.vertical.engine.handlers.MenuHandler.java
public StringBuffer getPathString(int menuItemKey, boolean includeMenu, boolean includeSpace) { CommonHandler commonHandler = getCommonHandler(); StringBuffer path = commonHandler.getPathString(db.tMenuItem, db.tMenuItem.mei_lKey, db.tMenuItem.mei_lParent, db.tMenuItem.mei_sName, menuItemKey, null, includeSpace); if (includeMenu) { if (includeSpace) { path.insert(0, " / "); } else {/*w w w. ja v a 2s . c o m*/ path.insert(0, "/"); } path.insert(0, getMenuName(getMenuKeyByMenuItem(menuItemKey))); } return path; }
From source file:org.blackdog.lyrics.type.LeoLyrics.java
/** return an html String representing the lyrics content of the page with the given uri * @param uri the uri of the page containing the song lyrics * @return a String or null if failed/*from w w w . j a va 2s.c o m*/ */ private String getLyricsContent(String uri) throws HttpException, IOException { String content = null; if (uri != null) { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(uri); // method.addRequestHeader(Header.) method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(5, false)); try { int statusCode = client.executeMethod(method); if (statusCode == HttpStatus.SC_OK) { String response = method.getResponseBodyAsString(); if (response != null) { /* search first occurrence of 'This song is on the following albums' * * if not found, search <font face="Trebuchet MS, Verdana, Arial" size=-1> * take to next </font> */ String headerString = "This song is on the following albums"; String headerString2 = "<font face=\"Trebuchet MS, Verdana, Arial\" size=-1>"; String paragraphString = "<p>"; String paragraphEndString = "</p>"; StringBuffer bufferContent = new StringBuffer(800); StringBuffer bufferHeaderTmp = new StringBuffer(headerString.length()); StringBuffer bufferParagraphTmp = new StringBuffer(paragraphString.length()); StringBuffer bufferParagraphEndTmp = new StringBuffer(paragraphEndString.length()); boolean headerFound = false; boolean paragraphFound = false; boolean contentFound = false; // for (int i = 0; i < response.length() && !contentFound; i++) { char b = response.charAt(i); /** header found */ if (headerFound) { if (paragraphFound) { bufferContent.append((char) b); if (b == paragraphEndString.charAt(bufferParagraphEndTmp.length())) { bufferParagraphEndTmp.append((char) b); } else if (bufferParagraphEndTmp.length() > 0) { bufferParagraphEndTmp.delete(0, bufferParagraphEndTmp.length() - 1); } /* did we find the end of the paragraph ? */ if (bufferParagraphEndTmp.length() >= paragraphEndString.length()) { contentFound = true; } } else { // System.out.println(" <<"); if (b == paragraphString.charAt(bufferParagraphTmp.length())) { bufferParagraphTmp.append((char) b); } else if (bufferParagraphTmp.length() > 0) { bufferParagraphTmp.delete(0, bufferParagraphTmp.length() - 1); } if (bufferParagraphTmp.length() >= paragraphString.length()) { paragraphFound = true; bufferHeaderTmp.append(headerString); } } } else { // System.out.println(" <<"); if (b == headerString.charAt(bufferHeaderTmp.length())) { bufferHeaderTmp.append((char) b); } else if (bufferHeaderTmp.length() > 0) { bufferHeaderTmp.delete(0, bufferHeaderTmp.length() - 1); } if (bufferHeaderTmp.length() >= headerString.length()) { headerFound = true; } } } if (!contentFound) { int headerString2Index = response.indexOf(headerString2); if (headerString2Index > -1) { String truncatedResponse = response.substring(headerString2Index); int lastEndfont = truncatedResponse.indexOf("</font>"); if (lastEndfont > -1) { bufferContent.append(truncatedResponse.substring(0, lastEndfont)); contentFound = true; } } } if (bufferContent.length() > 0) { bufferContent.insert(0, "<html>"); bufferContent.append("</html>"); try { content = new String(bufferContent.toString().getBytes(), method.getResponseCharSet()); // "UTF-8" } catch (UnsupportedEncodingException e) { logger.warn("unable to encode lyrics content in UTF-8"); content = bufferContent.toString(); } } } } else { logger.error("getting error while trying to connect to : " + uri + " (error code=" + statusCode + ")"); } } finally { method.releaseConnection(); } } return content; }
From source file:org.infoglue.cms.controllers.kernel.impl.simple.ContentController.java
/** * Returns the path to, and including, the supplied content. * /*from w ww .j ava 2 s . co m*/ * @param contentId the content to * * @return String the path to, and including, this content "library/library/..." * */ public String getContentPath(Integer contentId, boolean includeRootContent, boolean includeRepositoryName, Database db) throws ConstraintException, SystemException, Bug, Exception { StringBuffer sb = new StringBuffer(); ContentVO contentVO = ContentController.getContentController().getContentVOWithId(contentId, db); insertContentNameInPath(sb, contentVO); while (contentVO.getParentContentId() != null) { contentVO = ContentController.getContentController().getContentVOWithId(contentVO.getParentContentId(), db); if (includeRootContent || contentVO.getParentContentId() != null) { sb.insert(0, "/"); insertContentNameInPath(sb, contentVO); } } if (includeRepositoryName) { RepositoryVO repositoryVO = RepositoryController.getController() .getRepositoryVOWithId(contentVO.getRepositoryId(), db); if (repositoryVO != null) sb.insert(0, repositoryVO.getName() + "/"); } return sb.toString(); }
From source file:org.sakaiproject.reports.logic.impl.ReportsManagerImpl.java
public String replaceSystemValues(String string, Map beans) { StringBuffer buffer = new StringBuffer(string); Set beanNames = beans.keySet(); for (Iterator it = beanNames.iterator(); it.hasNext();) { String beanName = (String) it.next(); // see if the string contains reference(s) to the supported beans for (int i = buffer.indexOf(beanName), j = beanName.length(); i != -1; i = buffer.indexOf(beanName)) { // if it does, parse the property of the bean the report query references int k = buffer.indexOf("}", i + j); if (k == -1) throw new RuntimeException("Missing closing brace \"}\" in report query: " + string); String property = buffer.substring(i + j, k); // construct the bean property's corresponding "getter" method String getter = null; String param = null;/*from www . j a v a 2s. c o m*/ if (beanName.indexOf(".attribute.") != -1) { getter = "getAttribute"; param = property; } else if (beanName.indexOf(".property.") != -1) { getter = "getProperties"; param = null; } else { getter = "get" + Character.toUpperCase(property.charAt(0)) + property.substring(1); param = null; } try { // use reflection to invoke the method on the bean Object bean = beans.get(beanName); Class clasz = bean.getClass(); Class[] args = param == null ? (Class[]) null : new Class[] { String.class }; Method method = clasz.getMethod(getter, args); Object result = method.invoke(bean, (param == null ? (Object[]) null : new Object[] { param })); if (beanName.indexOf(".property.") != -1) { clasz = org.sakaiproject.entity.api.ResourceProperties.class; getter = "getProperty"; args = new Class[] { String.class }; param = property; method = clasz.getMethod(getter, args); result = method.invoke(result, new Object[] { param }); } // replace the bean expression in the report query with the actual value of calling the bean's corresponding getter method buffer.delete(i, k + 1); buffer.insert(i, (result == null ? "null" : result instanceof Time ? ((Time) result).toStringSql() : result.toString().replaceAll("'", "''"))); } catch (Exception ex) { throw new RuntimeException(ex.getMessage(), ex); } } } return buffer.toString(); }
From source file:org.infoglue.deliver.invokers.DecoratedComponentBasedHTMLPageInvoker.java
private StringBuffer getPagePathAsCommaseparatedIds(TemplateController templateController) { StringBuffer path = new StringBuffer(""); SiteNodeVO currentSiteNode = templateController.getSiteNode(); while (currentSiteNode != null) { path.insert(0, "," + currentSiteNode.getId().toString()); if (currentSiteNode.getParentSiteNodeId() != null) currentSiteNode = templateController.getSiteNode(currentSiteNode.getParentSiteNodeId()); else/* w w w. j av a2 s . c om*/ currentSiteNode = null; } return path; }
From source file:org.auraframework.test.WebDriverTestCase.java
/** * Gather up useful info to add to a test failure. try to get * <ul>/* w w w . j av a 2s. c o m*/ * <li>any client js errors</li> * <li>last known js test function</li> * <li>running/waiting</li> * <li>a screenshot</li> * </ul> * * @param originalErr the test failure * @throws Throwable a new AssertionFailedError or UnexpectedError with the original and additional info */ private Throwable addAuraInfoToTestFailure(Throwable originalErr) { StringBuffer description = new StringBuffer(); if (originalErr != null) { String msg = originalErr.getMessage(); if (msg != null) { description.append(msg); } } description.append(String.format("\nBrowser: %s", currentBrowserType)); if (auraUITestingUtil != null) { description.append("\nUser-Agent: " + auraUITestingUtil.getUserAgent()); } if (currentDriver == null) { description.append("\nTest failed before WebDriver was initialized"); } else { description.append("\nWebDriver: " + currentDriver); description.append("\nJS state: "); try { String dump = (String) auraUITestingUtil .getRawEval("return (window.$A && $A.test && $A.test.getDump())||'';"); if (dump.isEmpty()) { description.append("no errors detected"); } else { description.append(dump); } } catch (Throwable t) { description.append(t.getMessage()); } String screenshotsDirectory = System.getProperty("screenshots.directory"); if (screenshotsDirectory != null) { String img = getBase64EncodedScreenshot(originalErr, true); if (img == null) { description.append("\nScreenshot: {not available}"); } else { String fileName = getClass().getName() + "." + getName() + "_" + currentBrowserType + ".png"; File path = new File(screenshotsDirectory + "/" + fileName); try { path.getParentFile().mkdirs(); byte[] bytes = Base64.decodeBase64(img.getBytes()); FileOutputStream fos = new FileOutputStream(path); fos.write(bytes); fos.close(); String baseUrl = System.getProperty("screenshots.baseurl"); description.append(String.format("%nScreenshot: %s/%s", baseUrl, fileName)); } catch (Throwable t) { description.append(String.format("%nScreenshot: {save error: %s}", t.getMessage())); } } } try { description.append("\nApplication cache status: "); description.append(auraUITestingUtil.getRawEval( "var cache=window.applicationCache;return (cache===undefined || cache===null)?'undefined':cache.status;") .toString()); } catch (Exception ex) { description.append("error calculating status: " + ex); } description.append("\n"); if (SauceUtil.areTestsRunningOnSauce()) { String linkToJob = SauceUtil.getLinkToPublicJobInSauce(currentDriver); description.append("\nSauceLabs-recording: "); description.append((linkToJob != null) ? linkToJob : "{not available}"); } } // replace original exception with new exception with additional info Throwable newFailure; if (originalErr instanceof AssertionFailedError) { newFailure = new AssertionFailedError(description.toString()); } else { description.insert(0, originalErr.getClass() + ": "); newFailure = new UnexpectedError(description.toString(), originalErr.getCause()); } newFailure.setStackTrace(originalErr.getStackTrace()); return newFailure; }
From source file:com.amalto.workbench.utils.XSDGenerateHTML.java
/** * Load the XML Schema file and print the documentation based on it. * /*from w ww. ja v a 2s. co m*/ * @param xsdFile the name of an XML Schema file. */ public void loadAndPrint(String xsdFile) throws Exception { XSDFactory xsdFactory = XSDFactory.eINSTANCE; // Create a resource set and load the main schema file into it. // ResourceSet resourceSet = new ResourceSetImpl(); XSDResourceImpl xsdResource = (XSDResourceImpl) resourceSet.getResource(URI.createFileURI(xsdFile), true); XSDSchema xsdSchema = xsdResource.getSchema(); String elementContentHeaderDocumentation = getContentDocumentation("element-header"); //$NON-NLS-1$ if (elementContentHeaderDocumentation != null) { System.out.println(elementContentHeaderDocumentation); } List all = new ArrayList(xsdSchema.getElementDeclarations()); XSDElementDeclaration simpleContent = xsdSchema.resolveElementDeclaration("simpleContent"); //$NON-NLS-1$ XSDElementDeclaration complexContent = xsdSchema.resolveElementDeclaration("complexContent"); //$NON-NLS-1$ for (int i = 0; i <= 1; ++i) { for (int j = 0; j <= 1; ++j) { XSDElementDeclaration parentElement = (i == 0 ? complexContent : simpleContent); XSDComplexTypeDefinition xsdComplexTypeDefinition = (XSDComplexTypeDefinition) parentElement .getTypeDefinition(); XSDElementDeclaration specialElementDeclaration = (XSDElementDeclaration) ((XSDParticle) ((XSDModelGroup) ((XSDParticle) ((XSDModelGroup) ((XSDParticle) (xsdComplexTypeDefinition .getContentType())).getTerm()).getParticles().get(1)).getTerm()).getParticles().get(j)) .getTerm(); all.add(specialElementDeclaration); specialAnchorMap.put(specialElementDeclaration, parentElement); } } all = XSDNamedComponentImpl.sortNamedComponents(all); for (Iterator i = all.iterator(); i.hasNext();) { XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) i.next(); XSDElementDeclaration parentElementDeclaration = (XSDElementDeclaration) specialAnchorMap .get(xsdElementDeclaration); String elementDeclarationName = xsdElementDeclaration.getName(); String key = (parentElementDeclaration == null ? "" : parentElementDeclaration.getName() + "::") //$NON-NLS-1$ //$NON-NLS-2$ + elementDeclarationName; String elementDeclarationMarkup = getElementDeclarationMarkup(key); System.out.print("<h2>"); //$NON-NLS-1$ System.out.print(elementDeclarationName.substring(0, 1).toUpperCase()); System.out.print(elementDeclarationName.substring(1)); System.out.println("</h2>"); //$NON-NLS-1$ System.out.println("<div class='reprdef'>"); //$NON-NLS-1$ System.out.println("<table cols=1 width='100%'><tr><td>"); //$NON-NLS-1$ System.out.print( "<div class='reprHeader'><span class='reprdef'>XML Representation Summary: </span><code>"); //$NON-NLS-1$ System.out.print("<a name='" + getLocalAnchor(xsdElementDeclaration) + "'>"); //$NON-NLS-1$ //$NON-NLS-2$ System.out.print(getStandardLink(xsdElementDeclaration)); System.out.print(elementDeclarationName); System.out.print("</a></a></code>"); //$NON-NLS-1$ System.out.print(" Element Information Item "); //$NON-NLS-1$ if (parentElementDeclaration != null) { System.out.print("<small>("); //$NON-NLS-1$ System.out.print("<a href='#" + getLocalAnchor(parentElementDeclaration) + "'>"); //$NON-NLS-1$ //$NON-NLS-2$ System.out.print(parentElementDeclaration.getName()); System.out.print("</a>)</small>"); //$NON-NLS-1$ } else if ("restriction".equals(elementDeclarationName)) { //$NON-NLS-1$ System.out.print("<small>(simpleType)</small>"); //$NON-NLS-1$ } System.out.println("</div>"); //$NON-NLS-1$ System.out.println("<div class='reprBody'>"); //$NON-NLS-1$ if (elementDeclarationMarkup != null) { System.out.print("<div class='" + elementDeclarationMarkup + "'>"); //$NON-NLS-1$ //$NON-NLS-2$ } System.out.print("<tt><"); //$NON-NLS-1$ System.out.print(elementDeclarationName); System.out.print("</tt>"); //$NON-NLS-1$ String componentLinks = getComponentLinks(xsdElementDeclaration); if (componentLinks != null) { System.out.print(componentLinks); } System.out.println("<br>"); //$NON-NLS-1$ StringBuffer attributeDocumentationBuffer = new StringBuffer(); Map repeatedDocumentationMap = new HashMap(); XSDTypeDefinition xsdTypeDefinition = xsdElementDeclaration.getTypeDefinition(); XSDComplexTypeDefinition generalType = xsdSchema .resolveComplexTypeDefinitionURI(xsdElementDeclaration.getURI()); if (generalType.getContainer() != null) { xsdTypeDefinition = generalType; } if (xsdTypeDefinition instanceof XSDSimpleTypeDefinition) { System.out.println("<tt>></tt><br>"); //$NON-NLS-1$ } else if (xsdTypeDefinition instanceof XSDComplexTypeDefinition) { XSDComplexTypeDefinition xsdComplexTypeDefinition = (XSDComplexTypeDefinition) xsdTypeDefinition; for (Iterator attributeUses = xsdComplexTypeDefinition.getAttributeUses().iterator(); attributeUses .hasNext();) { XSDAttributeUse xsdAttributeUse = (XSDAttributeUse) attributeUses.next(); XSDAttributeDeclaration xsdAttributeDeclaration = xsdAttributeUse.getAttributeDeclaration(); String attributeDeclarationName = xsdAttributeDeclaration.getName(); System.out.print("<tt> "); //$NON-NLS-1$ if (xsdAttributeDeclaration.getTargetNamespace() != null) { System.out.print("xml:"); //$NON-NLS-1$ } String attributeDeclarationMarkup = null; String attributeDeclarationDocumentation = null; if (!"ignored".equals(elementDeclarationMarkup)) { //$NON-NLS-1$ attributeDeclarationMarkup = getAttributeDeclarationMarkup(attributeDeclarationName); if (attributeDeclarationMarkup == null) { attributeDeclarationMarkup = getAttributeDeclarationMarkup(elementDeclarationName + "." //$NON-NLS-1$ + attributeDeclarationName); } attributeDeclarationDocumentation = getAttributeDeclarationDocumentation( attributeDeclarationName); if (attributeDeclarationDocumentation == null) { attributeDeclarationDocumentation = getAttributeDeclarationDocumentation( elementDeclarationName + "." //$NON-NLS-1$ + attributeDeclarationName); } } if (attributeDeclarationDocumentation != null) { Integer oldInsertIndex = (Integer) repeatedDocumentationMap .get(attributeDeclarationDocumentation); if (oldInsertIndex != null) { String insertion = "<br>" + attributeDeclarationName; //$NON-NLS-1$ attributeDocumentationBuffer.insert(oldInsertIndex.intValue(), insertion); repeatedDocumentationMap.put(attributeDeclarationDocumentation, new Integer(oldInsertIndex.intValue() + insertion.length())); } else { if (attributeDocumentationBuffer.length() == 0) { attributeDocumentationBuffer.append("<table cols=2 width='100%'>\n"); //$NON-NLS-1$ attributeDocumentationBuffer.append( "<tr>\n<th width=25% valign=top align=left><b>Attribute</b></th>\n"); //$NON-NLS-1$ attributeDocumentationBuffer.append( "<th width=75% valign=top align=left><b>Description</b></th>\n</tr>\n"); //$NON-NLS-1$ } attributeDocumentationBuffer.append("<tr><td><b>"); //$NON-NLS-1$ if (attributeDeclarationMarkup != null) { attributeDocumentationBuffer .append("<span class='" + attributeDeclarationMarkup + "'>"); //$NON-NLS-1$ //$NON-NLS-2$ } attributeDocumentationBuffer.append(attributeDeclarationName); int insertIndex = attributeDocumentationBuffer.length(); if (attributeDeclarationMarkup != null) { attributeDocumentationBuffer.append("</span>"); //$NON-NLS-1$ } attributeDocumentationBuffer.append("</b></td>\n<td valign=top>\n"); //$NON-NLS-1$ attributeDocumentationBuffer.append(attributeDeclarationDocumentation); attributeDocumentationBuffer.append("</td></tr>"); //$NON-NLS-1$ repeatedDocumentationMap.put(attributeDeclarationDocumentation, new Integer(insertIndex)); } } if (attributeDeclarationMarkup != null) { System.out.print("<span class='" + attributeDeclarationMarkup + "'>"); //$NON-NLS-1$ //$NON-NLS-2$ } if (xsdAttributeUse.isRequired()) { System.out.print("<b>"); //$NON-NLS-1$ System.out.print(attributeDeclarationName); System.out.print("</b>"); //$NON-NLS-1$ } else { System.out.print(attributeDeclarationName); } if (attributeDeclarationMarkup != null) { System.out.print("</span>"); //$NON-NLS-1$ } System.out.print(" = </tt>"); //$NON-NLS-1$ XSDSimpleTypeDefinition xsdSimpleTypeDefinition = xsdAttributeDeclaration.getTypeDefinition(); printSimpleTypeDefinition(xsdSimpleTypeDefinition); if (xsdAttributeUse.getLexicalValue() != null) { System.out.print(" : "); //$NON-NLS-1$ if ("".equals(xsdAttributeUse.getLexicalValue())) { //$NON-NLS-1$ System.out.print("\"\""); //$NON-NLS-1$ } else { System.out.print(xsdAttributeUse.getLexicalValue()); } } if (attributeUses.hasNext()) { System.out.println("<br>"); //$NON-NLS-1$ } } if (xsdComplexTypeDefinition.getAttributeWildcard() != null) { System.out.println("<br>"); //$NON-NLS-1$ System.out.println("<span class='" //$NON-NLS-1$ + ALLOWS + "'><tt><em> { any attributes with non-schema namespace . . . }</em></tt></span>"); //$NON-NLS-1$ } System.out.println("<tt>></tt><br>"); //$NON-NLS-1$ if (xsdComplexTypeDefinition.getContentType() instanceof XSDParticle) { System.out.print("<tt><em> Content:</em> "); //$NON-NLS-1$ printParticle((XSDParticle) xsdComplexTypeDefinition.getContentType(), elementDeclarationMarkup); System.out.print("</tt>"); //$NON-NLS-1$ } else if (xsdComplexTypeDefinition.getContentType() instanceof XSDSimpleTypeDefinition) { System.out.print("<b>***** simple</b>"); //$NON-NLS-1$ } else { System.out.print("<b>{ **** empty }</b>"); //$NON-NLS-1$ } System.out.println("<br>"); //$NON-NLS-1$ } System.out.print("<tt></"); //$NON-NLS-1$ System.out.print(elementDeclarationName); System.out.println("></tt>"); //$NON-NLS-1$ if (elementDeclarationMarkup != null) { System.out.print("</div>"); //$NON-NLS-1$ } System.out.println("</div>"); //$NON-NLS-1$ String elementDeclarationDocumentation = getElementDeclarationDocumentation(key); if (elementDeclarationDocumentation != null) { System.out.println("<div class='reprBody'>"); //$NON-NLS-1$ System.out.println(elementDeclarationDocumentation); System.out.println("</div>"); //$NON-NLS-1$ } if (attributeDocumentationBuffer.length() > 0) { System.out.println("<div class='reprBody'>"); //$NON-NLS-1$ System.out.print(attributeDocumentationBuffer); System.out.println("</table>"); //$NON-NLS-1$ System.out.println("</div>"); //$NON-NLS-1$ } System.out.println("</td></tr></table>"); //$NON-NLS-1$ System.out.println("</div>"); //$NON-NLS-1$ } // System.out.println("<h1>Built-in Datatypes</h1>"); String typeContentHeaderDocumentation = getContentDocumentation("type-header"); //$NON-NLS-1$ if (typeContentHeaderDocumentation != null) { System.out.println(typeContentHeaderDocumentation); } System.out.println("<table border=true cols=3 width='100%'>"); //$NON-NLS-1$ System.out.println("<tr>"); //$NON-NLS-1$ System.out.println("<th width=33% valign=top align=left><b>Type</b></th>"); //$NON-NLS-1$ System.out.println("<th width=33% valign=top align=left><b>Properties & Facets</b></th>"); //$NON-NLS-1$ System.out.println("<th width=34% valign=top align=left><b>Effective Value</b></th>"); //$NON-NLS-1$ System.out.println("</tr>"); //$NON-NLS-1$ XSDSimpleTypeDefinition anyTypeDefinition = xsdSchema.getSchemaForSchema() .resolveSimpleTypeDefinition("anyType"); //$NON-NLS-1$ XSDSimpleTypeDefinition anySimpleTypeDefinition = xsdSchema.getSchemaForSchema() .resolveSimpleTypeDefinition("anySimpleType"); //$NON-NLS-1$ XSDSimpleTypeDefinition anyListTypeDefinition = xsdFactory.createXSDSimpleTypeDefinition(); anyListTypeDefinition.setVariety(XSDVariety.LIST_LITERAL); anyListTypeDefinition.setName("anyListType"); //$NON-NLS-1$ anyListTypeDefinition.setItemTypeDefinition(anySimpleTypeDefinition); xsdSchema.getContents().add(anyListTypeDefinition); anyListTypeDefinition.getElement().setAttribute(XSDConstants.ID_ATTRIBUTE, "anyListType"); //$NON-NLS-1$ XSDSimpleTypeDefinition anyUnionTypeDefinition = xsdFactory.createXSDSimpleTypeDefinition(); anyUnionTypeDefinition.setVariety(XSDVariety.UNION_LITERAL); anyUnionTypeDefinition.setName("anyUnionType"); //$NON-NLS-1$ anyUnionTypeDefinition.getMemberTypeDefinitions().add(anySimpleTypeDefinition); xsdSchema.getContents().add(anyUnionTypeDefinition); anyUnionTypeDefinition.getElement().setAttribute(XSDConstants.ID_ATTRIBUTE, "anyUnionType"); //$NON-NLS-1$ List allTypeDefinitions = new ArrayList(xsdSchema.getTypeDefinitions()); allTypeDefinitions.add(0, anySimpleTypeDefinition); allTypeDefinitions.add(0, anyTypeDefinition); for (Iterator i = allTypeDefinitions.iterator(); i.hasNext();) { XSDTypeDefinition xsdTypeDefinition = (XSDTypeDefinition) i.next(); if (xsdTypeDefinition instanceof XSDSimpleTypeDefinition && xsdTypeDefinition.getElement() != null && xsdTypeDefinition.getName() .equals(xsdTypeDefinition.getElement().getAttribute(XSDConstants.ID_ATTRIBUTE))) { XSDSimpleTypeDefinition xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) xsdTypeDefinition; System.out.println("<tr>"); //$NON-NLS-1$ System.out.println("<a name='" + xsdSimpleTypeDefinition.getName() + "-simple-type'>"); //$NON-NLS-1$ //$NON-NLS-2$ System.out.println("<td>"); //$NON-NLS-1$ boolean isPrimitive = XSDVariety.ATOMIC_LITERAL == xsdSimpleTypeDefinition.getVariety() && xsdSimpleTypeDefinition.getBaseTypeDefinition() == anySimpleTypeDefinition; if (isPrimitive) { System.out.print("<b>"); //$NON-NLS-1$ } System.out.print(getSimpleTypeDefinitionLink(xsdSimpleTypeDefinition)); if (isPrimitive) { System.out.print("</b>"); //$NON-NLS-1$ } for (XSDSimpleTypeDefinition baseTypeDefinition = xsdSimpleTypeDefinition;; baseTypeDefinition = baseTypeDefinition .getBaseTypeDefinition()) { String javaClass = (String) schemaTypeToJavaClassMap.get(baseTypeDefinition.getName()); if (javaClass != null) { System.out.println("<br> <br>"); //$NON-NLS-1$ if (baseTypeDefinition == xsdSimpleTypeDefinition) { System.out.print("<b>"); // ) //$NON-NLS-1$ } int dotIndex = javaClass.lastIndexOf("."); //$NON-NLS-1$ System.out.print("<font size=-2>"); //$NON-NLS-1$ System.out.print(javaClass.substring(0, dotIndex + 1)); System.out.print("</font><br> "); //$NON-NLS-1$ System.out.print(javaClass.substring(dotIndex + 1)); if (baseTypeDefinition == xsdSimpleTypeDefinition) { // ( System.out.print("<b>"); //$NON-NLS-1$ } System.out.println(); break; } } System.out.println("<br>"); //$NON-NLS-1$ System.out.println("</td>"); //$NON-NLS-1$ System.out.println("</a>"); //$NON-NLS-1$ StringBuffer validFacets = new StringBuffer(); StringBuffer effectiveFacetValues = new StringBuffer(); validFacets.append("variety<br>\n"); //$NON-NLS-1$ effectiveFacetValues .append(xsdSimpleTypeDefinition.isSetVariety() ? "<b>" + xsdSimpleTypeDefinition.getVariety() //$NON-NLS-1$ + "</b>" //$NON-NLS-1$ : "<em>absent</em>"); //$NON-NLS-1$ effectiveFacetValues.append("<br>\n"); //$NON-NLS-1$ validFacets.append("base type definition<br>\n"); //$NON-NLS-1$ XSDSimpleTypeDefinition baseTypeDefinition = xsdSimpleTypeDefinition.getBaseTypeDefinition(); while (baseTypeDefinition.getName() == null) { baseTypeDefinition = baseTypeDefinition.getBaseTypeDefinition(); } effectiveFacetValues.append("<a href='#"); //$NON-NLS-1$ effectiveFacetValues.append(baseTypeDefinition.getName()); effectiveFacetValues.append("-simple-type'>"); //$NON-NLS-1$ effectiveFacetValues.append(baseTypeDefinition.getName()); effectiveFacetValues.append("</a><br>\n"); //$NON-NLS-1$ validFacets.append("ordered<br>\n"); //$NON-NLS-1$ effectiveFacetValues.append("anyUnionType".equals(xsdSimpleTypeDefinition.getName()) ? "*" //$NON-NLS-1$ //$NON-NLS-2$ : xsdSimpleTypeDefinition.getOrderedFacet().getValue().getName()); effectiveFacetValues.append("<br>\n"); //$NON-NLS-1$ validFacets.append("bounded<br>\n"); //$NON-NLS-1$ effectiveFacetValues.append("anyUnionType".equals(xsdSimpleTypeDefinition.getName()) ? "*" //$NON-NLS-1$ //$NON-NLS-2$ : xsdSimpleTypeDefinition.getBoundedFacet().isValue() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ effectiveFacetValues.append("<br>\n"); //$NON-NLS-1$ validFacets.append("cardinality<br>\n"); //$NON-NLS-1$ effectiveFacetValues.append("anyUnionType".equals(xsdSimpleTypeDefinition.getName()) ? "*" //$NON-NLS-1$ //$NON-NLS-2$ : XSDCardinality.COUNTABLY_INFINITE_LITERAL == xsdSimpleTypeDefinition.getCardinalityFacet() .getValue() ? "countably infinite" //$NON-NLS-1$ : xsdSimpleTypeDefinition.getCardinalityFacet().getValue().getName()); effectiveFacetValues.append("<br>\n"); //$NON-NLS-1$ validFacets.append("numeric<br>\n"); //$NON-NLS-1$ effectiveFacetValues.append("anyUnionType".equals(xsdSimpleTypeDefinition.getName()) ? "*" //$NON-NLS-1$ //$NON-NLS-2$ : xsdSimpleTypeDefinition.getNumericFacet().isValue() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ effectiveFacetValues.append("<br>\n"); //$NON-NLS-1$ if (xsdSimpleTypeDefinition.getValidFacets().contains("length")) { //$NON-NLS-1$ validFacets.append("length<br>\n"); //$NON-NLS-1$ if (xsdSimpleTypeDefinition.getEffectiveLengthFacet() != null) { XSDLengthFacet xsdLengthFacet = xsdSimpleTypeDefinition.getEffectiveLengthFacet(); if (xsdLengthFacet.isFixed()) { effectiveFacetValues.append("<b>"); //$NON-NLS-1$ } effectiveFacetValues.append(xsdLengthFacet.getValue()); if (xsdLengthFacet.isFixed()) { effectiveFacetValues.append("</b>"); //$NON-NLS-1$ } } effectiveFacetValues.append("<br>\n"); //$NON-NLS-1$ } if (xsdSimpleTypeDefinition.getValidFacets().contains("minLength")) { //$NON-NLS-1$ validFacets.append("minLength<br>\n"); //$NON-NLS-1$ if (xsdSimpleTypeDefinition.getEffectiveMinLengthFacet() != null) { XSDMinLengthFacet xsdMinLengthFacet = xsdSimpleTypeDefinition.getEffectiveMinLengthFacet(); if (xsdMinLengthFacet.isFixed()) { effectiveFacetValues.append("<b>"); //$NON-NLS-1$ } effectiveFacetValues.append(xsdMinLengthFacet.getValue()); if (xsdMinLengthFacet.isFixed()) { effectiveFacetValues.append("</b>"); //$NON-NLS-1$ } } effectiveFacetValues.append("<br>\n"); //$NON-NLS-1$ } if (xsdSimpleTypeDefinition.getValidFacets().contains("maxLength")) { //$NON-NLS-1$ validFacets.append("maxLength<br>\n"); //$NON-NLS-1$ if (xsdSimpleTypeDefinition.getEffectiveMaxLengthFacet() != null) { XSDMaxLengthFacet xsdMaxLengthFacet = xsdSimpleTypeDefinition.getEffectiveMaxLengthFacet(); if (xsdMaxLengthFacet.isFixed()) { effectiveFacetValues.append("<b>"); //$NON-NLS-1$ } effectiveFacetValues.append(xsdMaxLengthFacet.getValue()); if (xsdMaxLengthFacet.isFixed()) { effectiveFacetValues.append("</b>"); //$NON-NLS-1$ } } effectiveFacetValues.append("<br>\n"); //$NON-NLS-1$ } if (xsdSimpleTypeDefinition.getValidFacets().contains("pattern")) { //$NON-NLS-1$ validFacets.append("pattern<br>\n"); //$NON-NLS-1$ if (xsdSimpleTypeDefinition.getEffectivePatternFacet() != null) { // XSDPatternFacet xsdPatternFacet = // xsdSimpleTypeDefinition.getEffectivePatternFacet(); effectiveFacetValues.append("*"); //$NON-NLS-1$ } effectiveFacetValues.append("<br>\n"); //$NON-NLS-1$ } if (xsdSimpleTypeDefinition.getValidFacets().contains("enumeration")) { //$NON-NLS-1$ validFacets.append("enumeration<br>\n"); //$NON-NLS-1$ if (xsdSimpleTypeDefinition.getEffectiveEnumerationFacet() != null) { XSDEnumerationFacet xsdEnumerationFacet = xsdSimpleTypeDefinition .getEffectiveEnumerationFacet(); for (Iterator enumerators = xsdEnumerationFacet.getValue().iterator(); enumerators .hasNext();) { String enumerator = (String) enumerators.next(); effectiveFacetValues.append(enumerator); effectiveFacetValues.append(" "); //$NON-NLS-1$ } } effectiveFacetValues.append("<br>\n"); //$NON-NLS-1$ } if (xsdSimpleTypeDefinition.getValidFacets().contains("whiteSpace")) { //$NON-NLS-1$ validFacets.append("whiteSpace<br>\n"); //$NON-NLS-1$ if (xsdSimpleTypeDefinition.getEffectiveWhiteSpaceFacet() != null) { XSDWhiteSpaceFacet xsdWhiteSpaceFacet = xsdSimpleTypeDefinition .getEffectiveWhiteSpaceFacet(); if (xsdWhiteSpaceFacet.isFixed()) { effectiveFacetValues.append("<b>"); //$NON-NLS-1$ } effectiveFacetValues.append(xsdWhiteSpaceFacet.getValue()); if (xsdWhiteSpaceFacet.isFixed()) { effectiveFacetValues.append("</b>"); //$NON-NLS-1$ } } effectiveFacetValues.append("<br>\n"); //$NON-NLS-1$ } if (xsdSimpleTypeDefinition.getValidFacets().contains("maxInclusive")) { //$NON-NLS-1$ validFacets.append("maxInclusive<br>\n"); //$NON-NLS-1$ if (xsdSimpleTypeDefinition.getEffectiveMaxFacet() instanceof XSDMaxInclusiveFacet) { XSDMaxInclusiveFacet xsdMaxInclusiveFacet = (XSDMaxInclusiveFacet) xsdSimpleTypeDefinition .getEffectiveMaxFacet(); if (xsdMaxInclusiveFacet.isFixed()) { effectiveFacetValues.append("<b>"); //$NON-NLS-1$ } effectiveFacetValues.append(xsdMaxInclusiveFacet.getValue()); if (xsdMaxInclusiveFacet.isFixed()) { effectiveFacetValues.append("</b>"); //$NON-NLS-1$ } } effectiveFacetValues.append("<br>\n"); //$NON-NLS-1$ } if (xsdSimpleTypeDefinition.getValidFacets().contains("maxExclusive")) { //$NON-NLS-1$ validFacets.append("maxExclusive<br>\n"); //$NON-NLS-1$ if (xsdSimpleTypeDefinition.getEffectiveMaxFacet() instanceof XSDMaxExclusiveFacet) { XSDMaxExclusiveFacet xsdMaxExclusiveFacet = (XSDMaxExclusiveFacet) xsdSimpleTypeDefinition .getEffectiveMaxFacet(); if (xsdMaxExclusiveFacet.isFixed()) { effectiveFacetValues.append("<b>"); //$NON-NLS-1$ } effectiveFacetValues.append(xsdMaxExclusiveFacet.getValue()); if (xsdMaxExclusiveFacet.isFixed()) { effectiveFacetValues.append("</b>"); //$NON-NLS-1$ } } effectiveFacetValues.append("<br>\n"); //$NON-NLS-1$ } if (xsdSimpleTypeDefinition.getValidFacets().contains("minInclusive")) { //$NON-NLS-1$ validFacets.append("maxInclusive<br>\n"); //$NON-NLS-1$ if (xsdSimpleTypeDefinition.getEffectiveMinFacet() instanceof XSDMinInclusiveFacet) { XSDMinInclusiveFacet xsdMinInclusiveFacet = (XSDMinInclusiveFacet) xsdSimpleTypeDefinition .getEffectiveMinFacet(); if (xsdMinInclusiveFacet.isFixed()) { effectiveFacetValues.append("<b>"); //$NON-NLS-1$ } effectiveFacetValues.append(xsdMinInclusiveFacet.getValue()); if (xsdMinInclusiveFacet.isFixed()) { effectiveFacetValues.append("</b>"); //$NON-NLS-1$ } } effectiveFacetValues.append("<br>\n"); //$NON-NLS-1$ } if (xsdSimpleTypeDefinition.getValidFacets().contains("minExclusive")) { //$NON-NLS-1$ validFacets.append("maxExclusive<br>\n"); //$NON-NLS-1$ if (xsdSimpleTypeDefinition.getEffectiveMinFacet() instanceof XSDMinExclusiveFacet) { XSDMinExclusiveFacet xsdMinExclusiveFacet = (XSDMinExclusiveFacet) xsdSimpleTypeDefinition .getEffectiveMinFacet(); if (xsdMinExclusiveFacet.isFixed()) { effectiveFacetValues.append("<b>"); //$NON-NLS-1$ } effectiveFacetValues.append(xsdMinExclusiveFacet.getValue()); if (xsdMinExclusiveFacet.isFixed()) { effectiveFacetValues.append("</b>"); //$NON-NLS-1$ } } effectiveFacetValues.append("<br>\n"); //$NON-NLS-1$ } if (xsdSimpleTypeDefinition.getValidFacets().contains("totalDigits")) { //$NON-NLS-1$ validFacets.append("totalDigits<br>\n"); //$NON-NLS-1$ if (xsdSimpleTypeDefinition.getEffectiveTotalDigitsFacet() != null) { XSDTotalDigitsFacet xsdTotalDigitsFacet = xsdSimpleTypeDefinition .getEffectiveTotalDigitsFacet(); if (xsdTotalDigitsFacet.isFixed()) { effectiveFacetValues.append("<b>"); //$NON-NLS-1$ } effectiveFacetValues.append(xsdTotalDigitsFacet.getValue()); if (xsdTotalDigitsFacet.isFixed()) { effectiveFacetValues.append("</b>"); //$NON-NLS-1$ } } effectiveFacetValues.append("<br>\n"); //$NON-NLS-1$ } if (xsdSimpleTypeDefinition.getValidFacets().contains("fractionDigits")) { //$NON-NLS-1$ validFacets.append("fractionDigits<br>\n"); //$NON-NLS-1$ if (xsdSimpleTypeDefinition.getEffectiveFractionDigitsFacet() != null) { XSDFractionDigitsFacet xsdFractionDigitsFacet = xsdSimpleTypeDefinition .getEffectiveFractionDigitsFacet(); if (xsdFractionDigitsFacet.isFixed()) { effectiveFacetValues.append("<b>"); //$NON-NLS-1$ } effectiveFacetValues.append(xsdFractionDigitsFacet.getValue()); if (xsdFractionDigitsFacet.isFixed()) { effectiveFacetValues.append("</b>"); //$NON-NLS-1$ } } effectiveFacetValues.append("<br>\n"); //$NON-NLS-1$ } System.out.println("<td>"); //$NON-NLS-1$ System.out.print(validFacets); System.out.println("</td>"); //$NON-NLS-1$ System.out.print("<td>"); //$NON-NLS-1$ System.out.println(effectiveFacetValues); System.out.println("</td>"); //$NON-NLS-1$ System.out.println("</tr>"); //$NON-NLS-1$ } } System.out.println("</table>"); //$NON-NLS-1$ String appendixContentHeaderDocumentation = getContentDocumentation("appendix-header"); //$NON-NLS-1$ if (appendixContentHeaderDocumentation != null) { System.out.println(appendixContentHeaderDocumentation); } }
From source file:org.openhealthtools.mdht.uml.cda.core.util.CDAModelUtil.java
public static String computeConformanceMessage(Constraint constraint, boolean markup) { StringBuffer message = new StringBuffer(); String strucTextBody = null;//from w w w.j a v a2 s .com String analysisBody = null; Map<String, String> langBodyMap = new HashMap<String, String>(); ValueSpecification spec = constraint.getSpecification(); if (spec instanceof OpaqueExpression) { for (int i = 0; i < ((OpaqueExpression) spec).getLanguages().size(); i++) { String lang = ((OpaqueExpression) spec).getLanguages().get(i); String body = ((OpaqueExpression) spec).getBodies().get(i); if ("StrucText".equals(lang)) { strucTextBody = body; } else if ("Analysis".equals(lang)) { analysisBody = body; } else { langBodyMap.put(lang, body); } } } String displayBody = null; if (strucTextBody != null && strucTextBody.trim().length() > 0) { // TODO if markup, parse strucTextBody and insert DITA markup displayBody = strucTextBody; } else if (analysisBody != null && analysisBody.trim().length() > 0) { if (markup) { // escape non-dita markup in analysis text displayBody = escapeMarkupCharacters(analysisBody); // change severity words to bold text displayBody = replaceSeverityWithBold(displayBody); } else { displayBody = analysisBody; } } if (!markup) { message.append(getPrefixedSplitName(constraint.getContext())).append(" "); } if (displayBody == null || !containsSeverityWord(displayBody)) { String keyword = getValidationKeyword(constraint); if (keyword == null) { keyword = "SHALL"; } message.append(markup ? "<b>" : ""); message.append(keyword); message.append(markup ? "</b>" : ""); message.append(" satisfy: "); } if (displayBody == null) { message.append(constraint.getName()); } else { message.append(displayBody); } appendConformanceRuleIds(constraint, message, markup); // include comment text only in markup output if (false && markup && constraint.getOwnedComments().size() > 0) { message.append("<ul>"); for (Comment comment : constraint.getOwnedComments()) { message.append("<li>"); message.append(fixNonXMLCharacters(comment.getBody())); message.append("</li>"); } message.append("</ul>"); } // Include other constraint languages, e.g. OCL or XPath if (false && langBodyMap.size() > 0) { message.append("<ul>"); for (String lang : langBodyMap.keySet()) { message.append("<li>"); message.append("<codeblock>[" + lang + "]: "); message.append(escapeMarkupCharacters(langBodyMap.get(lang))); message.append("</codeblock>"); message.append("</li>"); } message.append("</ul>"); } if (!markup) { // remove line feeds int index; while ((index = message.indexOf("\r")) >= 0) { message.deleteCharAt(index); } while ((index = message.indexOf("\n")) >= 0) { message.deleteCharAt(index); if (message.charAt(index) != ' ') { message.insert(index, " "); } } } return message.toString(); }
From source file:com.idega.builder.business.BuilderLogic.java
/** * *//from w w w. j av a2s . c o m */ public String getCurrentPageHtml(IWContext iwc) { String ibpage = getCurrentIBPage(iwc); ICDomain domain = getCurrentDomain(iwc); String sUrl = domain.getURL(); //cut the last '/' away to avoid double '/' if (sUrl != null) { if (sUrl.endsWith("/")) { sUrl = sUrl.substring(0, sUrl.length() - 1); } } StringBuffer url = new StringBuffer(sUrl); // url.append(IWMainApplication.BUILDER_SERVLET_URL); // url.append(iwc.getApplication().getBuilderServletURI()); // url.append("?"); // url.append(IB_PAGE_PARAMETER); // url.append("="); url.append(this.getIBPageURL(iwc, Integer.parseInt(ibpage))); if (url.toString().indexOf("http") == -1) { url.insert(0, "http://"); } String html = FileUtil.getStringFromURL(url.toString()); return (html); }