List of usage examples for org.dom4j DocumentHelper createElement
public static Element createElement(String name)
From source file:com.ibm.cognos.API.java
License:Open Source License
/** * addListColumn//from www . j a va 2s .c om * * @param p_sName * @param position * (to insert in the default position pass 0 to this method) * (default position = insert after the last child element.) */ public void addListColumn(String p_sName, int position) { Element n = null; n = (Element) oDocument.selectSingleNode( "/report/layouts/layout/reportPages/page/pageBody/contents" + "/list/listColumns"); // Create an empty column node Element eCol = DocumentHelper.createElement("listColumn"); // Prepare all the bits to contain the column title Element eTitle = DocumentHelper.createElement("listColumnTitle"); Element eStyleTitle = buildStyle("lt"); Element eTContents = DocumentHelper.createElement("contents"); Element eTText = DocumentHelper.createElement("textItem"); Element eTSrc = DocumentHelper.createElement("dataSource"); Element eLabel = DocumentHelper.createElement("dataItemLabel"); eLabel.addAttribute("refDataItem", p_sName); // Prepare all the bits to contain the column data Element eBody = DocumentHelper.createElement("listColumnBody"); Element eStyle = buildStyle("lm"); Element eBContents = DocumentHelper.createElement("contents"); Element eBText = DocumentHelper.createElement("textItem"); Element eBSrc = DocumentHelper.createElement("dataSource"); Element eValue = DocumentHelper.createElement("dataItemValue"); eValue.addAttribute("refDataItem", p_sName); // Piece the Title together in the right order eTSrc.add(eLabel); eTText.add(eTSrc); eTContents.add(eTText); eTitle.add(eStyleTitle); eTitle.add(eTContents); // Piece the Body together eBSrc.add(eValue); eBText.add(eBSrc); eBContents.add(eBText); eBody.add(eStyle); eBody.add(eBContents); // Add the title and body to the column eCol.add(eTitle); eCol.add(eBody); if (position > 0) { n.content().add(position - 1, eCol); } else { n.add(eCol); } }
From source file:com.ibm.cognos.API.java
License:Open Source License
public void addListColumns() { Element n = (Element) oDocument .selectSingleNode("/report/layouts/layout/reportPages/page/pageBody/contents/list"); Element e = DocumentHelper.createElement("listColumns"); n.add(e);/* ww w . j av a2 s . com*/ }
From source file:com.ibm.cognos.ReportObject.java
License:Open Source License
public Document getPackages(CRNConnect connection, String sPath) { Document oDom = null;/*from ww w . ja v a 2 s . com*/ Element packagesElement; try { com.cognos.developer.schemas.bibus._3.BaseClass oBase[]; oBase = connection.getCMService() .query(new SearchPathMultipleObject(sPath), new PropEnum[] { PropEnum.defaultName, PropEnum.source, PropEnum.dispatcherPath, PropEnum.searchPath }, new Sort[] {}, new QueryOptions()); packagesElement = DocumentHelper.createElement("packages"); oDom = DocumentHelper.createDocument(packagesElement); for (int i = 0; i < oBase.length; i++) { if (oBase[i].getClass().getName().toString() .equals("com.cognos.developer.schemas.bibus._3._package")) { Element oElement = DocumentHelper.createElement("package"); String oBaseName = oBase[i].getDefaultName().getValue(); String oBaseSearchPath = oBase[i].getSearchPath().getValue(); oElement.addElement("name").setText(oBaseName); oElement.addElement("searchPath").setText(oBaseSearchPath); oDom.getRootElement().add(oElement); } } } catch (Exception e) { e.printStackTrace(); } return oDom; }
From source file:com.jpsycn.wggl.mobile.androidpn.xmpp.push.NotificationManager.java
License:Open Source License
/** * Creates a new notification IQ and returns it. *//*from w ww.j av a 2 s. c om*/ private IQ createNotificationIQ(String apiKey, String title, String message, String uri) { Random random = new Random(); String id = Integer.toHexString(random.nextInt()); // String id = String.valueOf(System.currentTimeMillis()); Element notification = DocumentHelper.createElement(QName.get("notification", NOTIFICATION_NAMESPACE)); notification.addElement("id").setText(id); notification.addElement("apiKey").setText(apiKey); notification.addElement("title").setText(title); notification.addElement("message").setText(message); notification.addElement("uri").setText(null == uri ? "" : uri); IQ iq = new IQ(); iq.setType(IQ.Type.set); iq.setChildElement(notification); return iq; }
From source file:com.liferay.portal.tools.ExtInfoBuilder.java
License:Open Source License
public ExtInfoBuilder(String basedir, String outputDir, String servletContextName) throws Exception { DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir(basedir);//from w w w . ja v a 2 s . co m ds.setExcludes(new String[] { ".svn/**", "**/.svn/**", "ext-impl/ext-impl.jar", "ext-impl/src/**", "ext-service/ext-service.jar", "ext-service/src/**", "ext-util-bridges/ext-util-bridges.jar", "ext-util-bridges/src/**", "ext-util-java/ext-util-java.jar", "ext-util-java/src/**", "ext-util-taglib/ext-util-taglib.jar", "ext-util-taglib/src/**", "liferay-plugin-package.properties" }); ds.scan(); String[] files = ds.getIncludedFiles(); Arrays.sort(files); Element rootElement = new ElementImpl(DocumentHelper.createElement("ext-info")); Document document = new DocumentImpl(DocumentHelper.createDocument()); document.setRootElement(rootElement); DocUtil.add(rootElement, "servlet-context-name", servletContextName); Element filesElement = rootElement.addElement("files"); for (String file : files) { DocUtil.add(filesElement, "file", StringUtil.replace(file, StringPool.BACK_SLASH, StringPool.SLASH)); } _fileUtil.write(outputDir + "/ext-" + servletContextName + ".xml", document.formattedString()); }
From source file:com.liferay.portal.tools.service.builder.ServiceBuilder.java
License:Open Source License
private void _parseEntity(Element entityElement) throws Exception { String ejbName = entityElement.attributeValue("name"); String humanName = entityElement.attributeValue("human-name"); String table = entityElement.attributeValue("table"); if (Validator.isNull(table)) { table = ejbName;// w ww . j ava2 s . c om if (_badTableNames.contains(ejbName)) { table += StringPool.UNDERLINE; } if (_autoNamespaceTables) { table = _portletShortName + StringPool.UNDERLINE + ejbName; } } boolean uuid = GetterUtil.getBoolean(entityElement.attributeValue("uuid")); boolean uuidAccessor = GetterUtil.getBoolean(entityElement.attributeValue("uuid-accessor")); boolean localService = GetterUtil.getBoolean(entityElement.attributeValue("local-service")); boolean remoteService = GetterUtil.getBoolean(entityElement.attributeValue("remote-service"), true); String persistenceClass = GetterUtil.getString(entityElement.attributeValue("persistence-class"), _packagePath + ".service.persistence.impl." + ejbName + "PersistenceImpl"); String finderClass = ""; File originalFinderImpl = new File(_outputPath + "/service/persistence/" + ejbName + "FinderImpl.java"); File newFinderImpl = new File(_outputPath + "/service/persistence/impl/" + ejbName + "FinderImpl.java"); if (originalFinderImpl.exists()) { FileUtils.moveFile(originalFinderImpl, newFinderImpl); String content = FileUtils.readFileToString(newFinderImpl); StringBundler sb = new StringBundler(); sb.append("package " + _packagePath + ".service.persistence.impl;\n\n"); sb.append("import " + _packagePath + ".service.persistence." + ejbName + "Finder;\n"); sb.append("import " + _packagePath + ".service.persistence." + ejbName + "Util;"); content = StringUtil.replace(content, "package " + _packagePath + ".service.persistence;", sb.toString()); writeFileRaw(newFinderImpl, content, _modifiedFileNames); } if (newFinderImpl.exists()) { finderClass = _packagePath + ".service.persistence.impl." + ejbName + "FinderImpl"; } String dataSource = entityElement.attributeValue("data-source"); String sessionFactory = entityElement.attributeValue("session-factory"); String txManager = entityElement.attributeValue("tx-manager"); boolean cacheEnabled = GetterUtil.getBoolean(entityElement.attributeValue("cache-enabled"), true); boolean jsonEnabled = GetterUtil.getBoolean(entityElement.attributeValue("json-enabled"), remoteService); boolean mvccEnabled = GetterUtil.getBoolean(entityElement.attributeValue("mvcc-enabled"), _mvccEnabled); boolean trashEnabled = GetterUtil.getBoolean(entityElement.attributeValue("trash-enabled")); boolean deprecated = GetterUtil.getBoolean(entityElement.attributeValue("deprecated")); boolean dynamicUpdateEnabled = GetterUtil.getBoolean(entityElement.attributeValue("dynamic-update-enabled"), mvccEnabled); List<EntityColumn> pkList = new ArrayList<>(); List<EntityColumn> regularColList = new ArrayList<>(); List<EntityColumn> blobList = new ArrayList<>(); List<EntityColumn> collectionList = new ArrayList<>(); List<EntityColumn> columnList = new ArrayList<>(); boolean permissionedModel = false; List<Element> columnElements = entityElement.elements("column"); if (uuid) { Element columnElement = DocumentHelper.createElement("column"); columnElement.addAttribute("name", "uuid"); columnElement.addAttribute("type", "String"); columnElements.add(0, columnElement); } if (mvccEnabled && !columnElements.isEmpty()) { Element columnElement = DocumentHelper.createElement("column"); columnElement.addAttribute("name", "mvccVersion"); columnElement.addAttribute("type", "long"); columnElements.add(0, columnElement); } for (Element columnElement : columnElements) { String columnName = columnElement.attributeValue("name"); if (columnName.equals("resourceBlockId") && !ejbName.equals("ResourceBlock")) { permissionedModel = true; } String columnDBName = columnElement.attributeValue("db-name"); if (Validator.isNull(columnDBName)) { columnDBName = columnName; if (_badColumnNames.contains(columnName)) { columnDBName += StringPool.UNDERLINE; } } String columnType = columnElement.attributeValue("type"); boolean primary = GetterUtil.getBoolean(columnElement.attributeValue("primary")); boolean accessor = GetterUtil.getBoolean(columnElement.attributeValue("accessor")); boolean filterPrimary = GetterUtil.getBoolean(columnElement.attributeValue("filter-primary")); String collectionEntity = columnElement.attributeValue("entity"); String mappingTable = columnElement.attributeValue("mapping-table"); if (Validator.isNotNull(mappingTable)) { if (_badTableNames.contains(mappingTable)) { mappingTable += StringPool.UNDERLINE; } if (_autoNamespaceTables) { mappingTable = _portletShortName + StringPool.UNDERLINE + mappingTable; } } String idType = columnElement.attributeValue("id-type"); String idParam = columnElement.attributeValue("id-param"); boolean convertNull = GetterUtil.getBoolean(columnElement.attributeValue("convert-null"), true); boolean lazy = GetterUtil.getBoolean(columnElement.attributeValue("lazy"), true); boolean localized = GetterUtil.getBoolean(columnElement.attributeValue("localized")); boolean colJsonEnabled = GetterUtil.getBoolean(columnElement.attributeValue("json-enabled"), jsonEnabled); boolean containerModel = GetterUtil.getBoolean(columnElement.attributeValue("container-model")); boolean parentContainerModel = GetterUtil .getBoolean(columnElement.attributeValue("parent-container-model")); EntityColumn col = new EntityColumn(columnName, columnDBName, columnType, primary, accessor, filterPrimary, collectionEntity, mappingTable, idType, idParam, convertNull, lazy, localized, colJsonEnabled, containerModel, parentContainerModel); if (primary) { pkList.add(col); } if (columnType.equals("Collection")) { collectionList.add(col); } else { regularColList.add(col); if (columnType.equals("Blob")) { blobList.add(col); } } columnList.add(col); if (Validator.isNotNull(collectionEntity) && Validator.isNotNull(mappingTable)) { EntityMapping entityMapping = new EntityMapping(mappingTable, ejbName, collectionEntity); if (!_entityMappings.containsKey(mappingTable)) { _entityMappings.put(mappingTable, entityMapping); } } } EntityOrder order = null; Element orderElement = entityElement.element("order"); if (orderElement != null) { boolean asc = true; if ((orderElement.attribute("by") != null) && orderElement.attributeValue("by").equals("desc")) { asc = false; } List<EntityColumn> orderColsList = new ArrayList<>(); order = new EntityOrder(asc, orderColsList); List<Element> orderColumnElements = orderElement.elements("order-column"); for (Element orderColElement : orderColumnElements) { String orderColName = orderColElement.attributeValue("name"); boolean orderColCaseSensitive = GetterUtil .getBoolean(orderColElement.attributeValue("case-sensitive"), true); boolean orderColByAscending = asc; String orderColBy = GetterUtil.getString(orderColElement.attributeValue("order-by")); if (orderColBy.equals("asc")) { orderColByAscending = true; } else if (orderColBy.equals("desc")) { orderColByAscending = false; } EntityColumn col = Entity.getColumn(orderColName, columnList); col.setOrderColumn(true); col = (EntityColumn) col.clone(); col.setCaseSensitive(orderColCaseSensitive); col.setOrderByAscending(orderColByAscending); orderColsList.add(col); } } List<EntityFinder> finderList = new ArrayList<>(); List<Element> finderElements = entityElement.elements("finder"); if (uuid) { if (columnList.contains(new EntityColumn("companyId"))) { Element finderElement = DocumentHelper.createElement("finder"); finderElement.addAttribute("name", "Uuid_C"); finderElement.addAttribute("return-type", "Collection"); Element finderColumnElement = finderElement.addElement("finder-column"); finderColumnElement.addAttribute("name", "uuid"); finderColumnElement = finderElement.addElement("finder-column"); finderColumnElement.addAttribute("name", "companyId"); finderElements.add(0, finderElement); } if (columnList.contains(new EntityColumn("groupId"))) { Element finderElement = DocumentHelper.createElement("finder"); if (ejbName.equals("Layout")) { finderElement.addAttribute("name", "UUID_G_P"); } else { finderElement.addAttribute("name", "UUID_G"); } finderElement.addAttribute("return-type", ejbName); finderElement.addAttribute("unique", "true"); Element finderColumnElement = finderElement.addElement("finder-column"); finderColumnElement.addAttribute("name", "uuid"); finderColumnElement = finderElement.addElement("finder-column"); finderColumnElement.addAttribute("name", "groupId"); if (ejbName.equals("Layout")) { finderColumnElement = finderElement.addElement("finder-column"); finderColumnElement.addAttribute("name", "privateLayout"); } finderElements.add(0, finderElement); } Element finderElement = DocumentHelper.createElement("finder"); finderElement.addAttribute("name", "Uuid"); finderElement.addAttribute("return-type", "Collection"); Element finderColumnElement = finderElement.addElement("finder-column"); finderColumnElement.addAttribute("name", "uuid"); finderElements.add(0, finderElement); } if (permissionedModel) { Element finderElement = DocumentHelper.createElement("finder"); finderElement.addAttribute("name", "ResourceBlockId"); finderElement.addAttribute("return-type", "Collection"); Element finderColumnElement = finderElement.addElement("finder-column"); finderColumnElement.addAttribute("name", "resourceBlockId"); finderElements.add(0, finderElement); } String alias = TextFormatter.format(ejbName, TextFormatter.I); if (_badAliasNames.contains(StringUtil.toLowerCase(alias))) { alias += StringPool.UNDERLINE; } for (Element finderElement : finderElements) { String finderName = finderElement.attributeValue("name"); String finderReturn = finderElement.attributeValue("return-type"); boolean finderUnique = GetterUtil.getBoolean(finderElement.attributeValue("unique")); String finderWhere = finderElement.attributeValue("where"); if (Validator.isNotNull(finderWhere)) { for (EntityColumn column : columnList) { String name = column.getName(); finderWhere = StringUtil.replace(finderWhere, name, alias + "." + name); } } boolean finderDBIndex = GetterUtil.getBoolean(finderElement.attributeValue("db-index"), true); List<EntityColumn> finderColsList = new ArrayList<>(); List<Element> finderColumnElements = finderElement.elements("finder-column"); for (Element finderColumnElement : finderColumnElements) { String finderColName = finderColumnElement.attributeValue("name"); boolean finderColCaseSensitive = GetterUtil .getBoolean(finderColumnElement.attributeValue("case-sensitive"), true); String finderColComparator = GetterUtil.getString(finderColumnElement.attributeValue("comparator"), "="); String finderColArrayableOperator = GetterUtil .getString(finderColumnElement.attributeValue("arrayable-operator")); EntityColumn col = Entity.getColumn(finderColName, columnList); if (!col.isFinderPath()) { col.setFinderPath(true); } col = (EntityColumn) col.clone(); col.setCaseSensitive(finderColCaseSensitive); col.setComparator(finderColComparator); col.setArrayableOperator(finderColArrayableOperator); col.validate(); finderColsList.add(col); } finderList.add(new EntityFinder(finderName, finderReturn, finderUnique, finderWhere, finderDBIndex, finderColsList)); } List<Entity> referenceList = new ArrayList<>(); List<String> unresolvedReferenceList = new ArrayList<>(); if (_build) { List<Element> referenceElements = entityElement.elements("reference"); Set<String> referenceSet = new TreeSet<>(); for (Element referenceElement : referenceElements) { String referencePackage = referenceElement.attributeValue("package-path"); String referenceEntity = referenceElement.attributeValue("entity"); referenceSet.add(referencePackage + "." + referenceEntity); } if (!_packagePath.equals("com.liferay.counter")) { referenceSet.add("com.liferay.counter.Counter"); } if (_autoImportDefaultReferences) { referenceSet.add("com.liferay.portal.ClassName"); referenceSet.add("com.liferay.portal.Resource"); referenceSet.add("com.liferay.portal.User"); } for (String referenceName : referenceSet) { try { referenceList.add(getEntity(referenceName)); } catch (RuntimeException re) { unresolvedReferenceList.add(referenceName); } } } List<String> txRequiredList = new ArrayList<>(); List<Element> txRequiredElements = entityElement.elements("tx-required"); for (Element txRequiredEl : txRequiredElements) { String txRequired = txRequiredEl.getText(); txRequiredList.add(txRequired); } boolean resourceActionModel = _resourceActionModels.contains(_packagePath + ".model." + ejbName); _ejbList.add(new Entity(_packagePath, _portletName, _portletShortName, ejbName, humanName, table, alias, uuid, uuidAccessor, localService, remoteService, persistenceClass, finderClass, dataSource, sessionFactory, txManager, cacheEnabled, dynamicUpdateEnabled, jsonEnabled, mvccEnabled, trashEnabled, deprecated, pkList, regularColList, blobList, collectionList, columnList, order, finderList, referenceList, unresolvedReferenceList, txRequiredList, resourceActionModel)); }
From source file:com.liferay.portal.xml.SAXReaderImpl.java
License:Open Source License
public Element createElement(QName qName) { QNameImpl qNameImpl = (QNameImpl) qName; return new ElementImpl(DocumentHelper.createElement(qNameImpl.getWrappedQName())); }
From source file:com.liferay.portal.xml.SAXReaderImpl.java
License:Open Source License
public Element createElement(String name) { return new ElementImpl(DocumentHelper.createElement(name)); }
From source file:com.mg.framework.support.ui.UIProducer.java
License:Open Source License
private static Element copyElement(Element element, RuntimeMacrosLoader runtimeMacrosLoader) { //if (INCLUDE_TAG_NAME.equals(element.getQualifiedName())) //return includeMacros(); Element result = DocumentHelper.createElement(element.getQualifiedName()); result.setAttributes(element.attributes()); List<Element> childElements = MiscUtils.convertUncheckedList(Element.class, element.elements()); for (Element childElement : childElements) { Element copy;/*from w ww . ja v a 2s . c o m*/ if (childElement.getQualifiedName().equals(INCLUDE_TAG_NAME)) { copy = includeMacros(result, childElement, runtimeMacrosLoader); /*Document macros = null; String runtimeMacros = childElement.attributeValue(RUNTIME_MACROS_NAME_ATTR); if (runtimeMacros == null) macros = loadMacros(childElement.attributeValue(MACROS_NAME_ATTR)); else macros = loadRuntimeMacros(runtimeMacros, runtimeMacrosLoader); String macrosType = macros.getRootElement().getQualifiedName(); if (macrosType.equals(EMPTY_MACROS)) copy = null; //handle special case for empty macros else if (macrosType.equals(WRAP_MACROS)) { //copy macros contents exclude root element List<Element> macrosChildElements = MiscUtils.convertUncheckedList(Element.class, macros.getRootElement().elements()); for (Element macrosChild : macrosChildElements) { Element macrosElement = copyElement(macrosChild, runtimeMacrosLoader); if (macrosElement != null) result.add(macrosElement); } copy = null; } else copy = copyElement(macros.getRootElement(), runtimeMacrosLoader); //copy root element */ } else { copy = copyElement(childElement, runtimeMacrosLoader); } if (copy != null) result.add(copy); } return result; }
From source file:com.nokia.ant.Database.java
License:Open Source License
public Document createDOM() throws Exception { //log("Building Ant project database", Project.MSG_DEBUG); Element root = DocumentHelper.createElement("antDatabase"); Document outDoc = DocumentHelper.createDocument(root); ArrayList antFiles = getAntFiles(getProject(), homeFilesOnly); Iterator antFilesIter = antFiles.iterator(); while (antFilesIter.hasNext()) { String antFile = (String) antFilesIter.next(); readSignals(root, antFile);/* ww w . ja va 2 s.c o m*/ } antFilesIter = antFiles.iterator(); while (antFilesIter.hasNext()) { String antFile = (String) antFilesIter.next(); parseAntFile(root, antFile); } buildTaskDefs(root); return outDoc; }