@Override public void relink_namespace(ThreadContext context) { Element e = (Element) node; e.getOwnerDocument().renameNode(e, e.lookupNamespaceURI(e.getPrefix()), e.getNodeName()); if (e.hasAttributes()) { NamedNodeMap attrs = e.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Attr attr = (Attr) attrs.item(i); String nsUri = ""; String prefix = attr.getPrefix(); String nodeName = attr.getNodeName(); if ("xml".equals(prefix)) { nsUri = "http://www.w3.org/XML/1998/namespace"; } else if ("xmlns".equals(prefix) || nodeName.equals("xmlns")) { nsUri = "http://www.w3.org/2000/xmlns/"; } else { nsUri = attr.lookupNamespaceURI(nodeName); } e.getOwnerDocument().renameNode(attr, nsUri, nodeName); } } if (e.hasChildNodes()) { ((XmlNodeSet) children(context)).relink_namespace(context); } }
public void saveToXml(Element ele) { Document doc = ele.getOwnerDocument(); ele.setAttribute("id", String.valueOf(partNumber)); SaveUtil.appendChildTextElement(ele, "title", String.valueOf(title)); SaveUtil.appendChildTextElement(ele, "instrument", String.valueOf(instrument)); for (int t = 0; t < getTrackCount(); t++) { if (!isTrackEnabled(t)) continue; TrackInfo trackInfo = abcSong.getSequenceInfo().getTrackInfo(t); Element trackEle = (Element) ele.appendChild(doc.createElement("track")); trackEle.setAttribute("id", String.valueOf(t)); if (trackInfo.hasName()) trackEle.setAttribute("name", trackInfo.getName()); if (trackTranspose[t] != 0) SaveUtil.appendChildTextElement(trackEle, "transpose", String.valueOf(trackTranspose[t])); if (trackVolumeAdjust[t] != 0) SaveUtil.appendChildTextElement( trackEle, "volumeAdjust", String.valueOf(trackVolumeAdjust[t])); if (instrument.isPercussion) { BitSet[] enabledSetByTrack = isCowbellPart() ? cowbellsEnabled : drumsEnabled; BitSet enabledSet = (enabledSetByTrack == null) ? null : enabledSetByTrack[t]; if (enabledSet != null) { Element drumsEnabledEle = ele.getOwnerDocument().createElement("drumsEnabled"); trackEle.appendChild(drumsEnabledEle); if (isCowbellPart()) { drumsEnabledEle.setAttribute("defaultEnabled", String.valueOf(false)); // Only store the drums that are enabled for (int i = enabledSet.nextSetBit(0); i >= 0; i = enabledSet.nextSetBit(i + 1)) { Element drumEle = ele.getOwnerDocument().createElement("note"); drumsEnabledEle.appendChild(drumEle); drumEle.setAttribute("id", String.valueOf(i)); drumEle.setAttribute("isEnabled", String.valueOf(true)); } } else { drumsEnabledEle.setAttribute("defaultEnabled", String.valueOf(true)); // Only store the drums that are disabled for (int i = enabledSet.nextClearBit(0); i >= 0; i = enabledSet.nextClearBit(i + 1)) { if (i >= MidiConstants.NOTE_COUNT) break; Element drumEle = ele.getOwnerDocument().createElement("note"); drumsEnabledEle.appendChild(drumEle); drumEle.setAttribute("id", String.valueOf(i)); drumEle.setAttribute("isEnabled", String.valueOf(false)); } } } if (!isCowbellPart()) { if (drumNoteMap[t] != null) drumNoteMap[t].saveToXml((Element) trackEle.appendChild(doc.createElement("drumMap"))); } } } }
protected void transferAttributes( Element source, Element result, java.util.List nonTransferList) { boolean debug = false; NamedNodeMap sourceAttrNodeMap = source.getAttributes(); if (sourceAttrNodeMap == null) return; NamedNodeMap resultAttrNodeMap = result.getAttributes(); for (int index = 0; index < sourceAttrNodeMap.getLength(); index++) { Node sourceAttrNode = sourceAttrNodeMap.item(index); if (!this.canTransferAttribute(sourceAttrNode.getNodeName(), nonTransferList)) continue; if (!isValidAttributeToTransfer( sourceAttrNode.getNodeName(), getAttributeListForElement(result.getTagName()))) continue; if (resultAttrNodeMap == null) { Attr addAttr = result.getOwnerDocument().createAttribute(sourceAttrNode.getNodeName()); addAttr.setValue(sourceAttrNode.getNodeValue()); result.setAttributeNode(addAttr); } else { Node resultAttrNode = resultAttrNodeMap.getNamedItem(sourceAttrNode.getNodeName()); if (resultAttrNode != null) { resultAttrNode.setNodeValue(sourceAttrNode.getNodeValue()); // result.setAttributeNode((Attr)resultAttrNode); } else { Attr addAttr = result.getOwnerDocument().createAttribute(sourceAttrNode.getNodeName()); addAttr.setValue(sourceAttrNode.getNodeValue()); result.setAttributeNode(addAttr); } } } }
/** * Calls the method with the same name of the handler object or passes the SAX event to the helper * object depending on the value of the <CODE>wantDOM</CODE> flag. The completed DOM sub-trees are * passed to the controller's <CODE>handleDOM()</CODE> method. * * @param namespaceURI The element's namespace URI * @param localName The element's local name * @param qualifiedName The element's qualified name * @throws SAXException Error reported by the handler or helper */ public void endElement(String namespaceURI, String localName, String qualifiedName) throws SAXException { if (wantDOM) { // We are in DOM mode. // Decrease the level counter level--; // Pass the SAX event to the helper's handler helper.getContentHandler().endElement(namespaceURI, localName, qualifiedName); if (level == 0) { // The DOM sub-tree is completed. Get its root element Element element = helper.endBuilding(); // Make the sub-tree look like a regular DOM tree // (The sub-tree's root becomes "document element") element.getOwnerDocument().appendChild(element); // Ask the controller to handle the DOM sub-tree controller.handleDOM(element); // Don't keep any reference to the DOM sub-tree // so that it can be garbage collected element.getOwnerDocument().removeChild(element); // Return to the SAX mode wantDOM = false; } } else // We are in SAX mode. Forward the SAX event to the app handler handler.endElement(namespaceURI, localName, qualifiedName); }
@Override protected void changeItem(UntypedItemXml item) { Element element = getElement(item, property); if (element == null) { throw new CliException("Cannot find element: " + property); } String namespaceURI = element.getNamespaceURI(); String localName = element.getLocalName(); Node parentNode = element.getParentNode(); String parentNamespaceUri = parentNode.getNamespaceURI(); String parentTag = parentNode.getLocalName(); String pathKey = parentNamespaceUri + ":" + parentTag + ":" + namespaceURI + ":" + localName; if ("http://platformlayer.org/service/platformlayer/v1.0:platformLayerService:http://platformlayer.org/service/platformlayer/v1.0:config" .equals(pathKey)) { Element newNode = element.getOwnerDocument().createElementNS(NAMESPACE_URI_CORE, "property"); Element keyNode = element.getOwnerDocument().createElementNS(NAMESPACE_URI_CORE, "key"); keyNode.setTextContent(key); Element valueNode = element.getOwnerDocument().createElementNS(NAMESPACE_URI_CORE, "value"); valueNode.setTextContent(value); newNode.appendChild(keyNode); newNode.appendChild(valueNode); element.appendChild(newNode); } else { throw new UnsupportedOperationException(); } }
@Override public void apply(Element e) { if (e.getTagName().equals("property")) { Element parent = (Element) e.getParentNode(); if (parent != null && parent.getTagName().equals("ndbx")) { Attr name = e.getAttributeNode("name"); Attr value = e.getAttributeNode("value"); if (name != null && name.getValue().equals("oscPort")) { if (value != null) { Element device = e.getOwnerDocument().createElement("device"); device.setAttribute("name", "osc1"); device.setAttribute("type", "osc"); Element portProperty = e.getOwnerDocument().createElement("property"); portProperty.setAttribute("name", "port"); portProperty.setAttribute("value", value.getValue()); device.appendChild(portProperty); Element autostartProperty = e.getOwnerDocument().createElement("property"); autostartProperty.setAttribute("name", "autostart"); autostartProperty.setAttribute("value", "true"); device.appendChild(autostartProperty); parent.replaceChild(device, e); } else { parent.removeChild(e); } } } } }
private static void test( final XmlContentModel XmlContentModel, final String initialContent, final String elementNameToInsert, final String expectedContent) throws Exception { Element root = parse(initialContent); NodeList nodeList = root.getChildNodes(); final int position = XmlContentModel.findInsertionPosition(nodeList, new QName(elementNameToInsert)); final Element elementToInsert = root.getOwnerDocument().createElementNS(null, elementNameToInsert); if (position == -1) { root.appendChild(elementToInsert); } else { final Node nodeAtPosition = nodeList.item(position); root.insertBefore(elementToInsert, nodeAtPosition); } final Element expectedContentRoot = parse(expectedContent); if (!equal(nodeList, expectedContentRoot.getChildNodes())) { final StringBuilder buf = new StringBuilder(); buf.append("=== actual ===\n"); buf.append(toString(root.getOwnerDocument())); buf.append("\n=== expected ===\n"); buf.append(expectedContent); assertTrue(buf.toString(), false); } }
private void marshallUnknownProps(Collection<PropertyDataObject> unknownProps, Element parent) throws MarshalException { for (PropertyDataObject pData : unknownProps) { if (!(pData instanceof GenericDOMData)) throw new UnsupportedDataObjectException(pData); Node propElem = ((GenericDOMData) pData).getPropertyElement(); if (propElem.getOwnerDocument() != parent.getOwnerDocument()) propElem = parent.getOwnerDocument().importNode(propElem, true); parent.appendChild(propElem); } }
private void addStyle(final Element parentElement, final Map<String, String> style) { final Element element = parentElement.getOwnerDocument().createElement("styles"); for (final Map.Entry<String, String> entry : style.entrySet()) { final Element styleElement = parentElement.getOwnerDocument().createElement("style"); styleElement.setAttribute("name", entry.getKey()); styleElement.setTextContent(entry.getValue()); element.appendChild(styleElement); } parentElement.appendChild(element); }
public CMElementDeclaration getCMElementDeclaration(Element element) { CMElementDeclaration result = null; Document document = element.getOwnerDocument(); String[] doctypeInfo = getDoctypeInfo(document); if (doctypeInfo != null) { // we have detected doctype information so we assume that we can locate the // CMElementDeclaration // in the CMDocument's table of global elements CMDocument cmDocument = getCorrespondingCMDocument(element, false); // TODO... consider replacing above with // CMDocument cmDocument = getCMDocument(document, doctypeInfo[0], doctypeInfo[1]); if (cmDocument != null) { result = (CMElementDeclaration) cmDocument.getElements().getNamedItem(element.getNodeName()); // this is a hack to get our xsl code assist working... we might want to handle similar // grammar behaviour via some established model query setting if (result == null && getImplictDoctype(document) != null) { Node parent = element.getParentNode(); if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) { result = getCMElementDeclaration((Element) parent); } } } } else { // here we use a namespaceTable to consider if the root element has any namespace information // NamespaceTable namespaceTable = new NamespaceTable(element.getOwnerDocument()); List list = NamespaceTable.getElementLineage(element); Element rootElement = (Element) list.get(0); namespaceTable.addElement(rootElement); if (namespaceTable.isNamespaceEncountered()) { // we assume that this is an XMLSchema style namespace aware document result = getCMElementDeclaration(element, list, namespaceTable); } else { result = checkExternalSchema(element); if (result == null) { // we assume that this is an inferred CMDocument for a DTD style 'namespaceless' document CMDocument cmDocument = getCMDocument("", "", "DTD"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if (cmDocument != null) { result = (CMElementDeclaration) cmDocument.getElements().getNamedItem(element.getNodeName()); } } } } return result; }
// DOM output public void addPrefixDecl(Element element, String prefix, String uri) { if ("".equals(prefix)) { Document doc = element.getOwnerDocument(); Attr attr = doc.createAttributeNS("http://www.w3.org/XML/2000/xmlns/", "xmlns"); attr.setValue(uri); element.setAttributeNode(attr); } else { Document doc = element.getOwnerDocument(); Attr attr = doc.createAttributeNS("http://www.w3.org/XML/2000/xmlns/", "xmlns:" + prefix); attr.setValue(uri); element.setAttributeNode(attr); } }
/** * Add dependencies element for the given bundle to the string buffer. * * @param el element to add the dependencies to. * @param ba The bundle archive to defining the coordinates. * @param prefix Whitespace to add before the new element. */ private void addDependencies(Element el, BundleArchive ba, String prefix) { final Element dependencies = el.getOwnerDocument().createElement("dependencies"); final String prefix1 = prefix + " "; final String prefix2 = prefix1 + " "; el.appendChild(el.getOwnerDocument().createTextNode("\n" + prefix1)); el.appendChild(dependencies); el.appendChild(el.getOwnerDocument().createTextNode("\n" + prefix)); for (final Entry<BundleArchive, SortedSet<String>> depEntry : selectCtDeps(ba).entrySet()) { final BundleArchives.BundleArchive depBa = depEntry.getKey(); final SortedSet<String> pkgNames = depEntry.getValue(); dependencies.appendChild(el.getOwnerDocument().createTextNode("\n" + prefix2)); dependencies.appendChild(el.getOwnerDocument().createComment(pkgNames.toString())); final Element dependency = el.getOwnerDocument().createElement("dependency"); addMavenCoordinates(dependency, depBa); if (pkgNames.contains("org.osgi.framework")) { dependency.setAttribute("scope", "provided"); } dependencies.appendChild(el.getOwnerDocument().createTextNode("\n" + prefix2)); dependencies.appendChild(dependency); dependencies.appendChild(el.getOwnerDocument().createTextNode("\n")); } dependencies.appendChild(el.getOwnerDocument().createTextNode("\n" + prefix1)); if (0 < ba.pkgUnprovidedMap.size()) { log(" Imports without any provider: " + ba.pkgUnprovidedMap, Project.MSG_DEBUG); } }
private void linkFamilyMembers( Entry from, Entry parent, List<Entry> siblingList, int siblingCount, int topicIndex) { switch (from.linking) { case NORMAL: case SOURCE_ONLY: { Element topic = from.topic; assert (topic != null); Document doc = topic.getOwnerDocument(); assert (doc != null); Element linkpool = addLinkpool(topic, /*prepend*/ true, "family-members", doc); if (parent != null) { addLink(linkpool, parent, "parent", doc); } for (int i = 0; i < siblingCount; ++i) { if (i != topicIndex) { addLink(linkpool, siblingList.get(i), "sibling", doc); } } } break; } }
private static void addConfiguration( final Element element, final Map<PropertyDescriptor, String> properties, final String annotationData, final StringEncryptor encryptor) { final Document doc = element.getOwnerDocument(); for (final Map.Entry<PropertyDescriptor, String> entry : properties.entrySet()) { final PropertyDescriptor descriptor = entry.getKey(); String value = entry.getValue(); if (value != null && descriptor.isSensitive()) { value = ENC_PREFIX + encryptor.encrypt(value) + ENC_SUFFIX; } if (value == null) { value = descriptor.getDefaultValue(); } final Element propElement = doc.createElement("property"); addTextElement(propElement, "name", descriptor.getName()); if (value != null) { addTextElement(propElement, "value", value); } element.appendChild(propElement); } if (annotationData != null) { addTextElement(element, "annotationData", annotationData); } }
private void addProcessor(final Element parentElement, final ProcessorNode processor) { final Document doc = parentElement.getOwnerDocument(); final Element element = doc.createElement("processor"); parentElement.appendChild(element); addTextElement(element, "id", processor.getIdentifier()); addTextElement(element, "name", processor.getName()); addPosition(element, processor.getPosition()); addStyle(element, processor.getStyle()); addTextElement(element, "comment", processor.getComments()); addTextElement(element, "class", processor.getProcessor().getClass().getCanonicalName()); addTextElement(element, "maxConcurrentTasks", processor.getMaxConcurrentTasks()); addTextElement(element, "schedulingPeriod", processor.getSchedulingPeriod()); addTextElement(element, "penalizationPeriod", processor.getPenalizationPeriod()); addTextElement(element, "yieldPeriod", processor.getYieldPeriod()); addTextElement(element, "bulletinLevel", processor.getBulletinLevel().toString()); addTextElement(element, "lossTolerant", String.valueOf(processor.isLossTolerant())); addTextElement(element, "scheduledState", processor.getScheduledState().name()); addTextElement(element, "schedulingStrategy", processor.getSchedulingStrategy().name()); addTextElement(element, "runDurationNanos", processor.getRunDuration(TimeUnit.NANOSECONDS)); addConfiguration(element, processor.getProperties(), processor.getAnnotationData(), encryptor); for (final Relationship rel : processor.getAutoTerminatedRelationships()) { addTextElement(element, "autoTerminatedRelationship", rel.getName()); } }
private void addRemoteProcessGroup( final Element parentElement, final RemoteProcessGroup remoteRef) { final Document doc = parentElement.getOwnerDocument(); final Element element = doc.createElement("remoteProcessGroup"); parentElement.appendChild(element); addTextElement(element, "id", remoteRef.getIdentifier()); addTextElement(element, "name", remoteRef.getName()); addPosition(element, remoteRef.getPosition()); addTextElement(element, "comment", remoteRef.getComments()); addTextElement(element, "url", remoteRef.getTargetUri().toString()); addTextElement(element, "timeout", remoteRef.getCommunicationsTimeout()); addTextElement(element, "yieldPeriod", remoteRef.getYieldDuration()); addTextElement(element, "transmitting", String.valueOf(remoteRef.isTransmitting())); for (final RemoteGroupPort port : remoteRef.getInputPorts()) { if (port.hasIncomingConnection()) { addRemoteGroupPort(element, port, "inputPort"); } } for (final RemoteGroupPort port : remoteRef.getOutputPorts()) { if (!port.getConnections().isEmpty()) { addRemoteGroupPort(element, port, "outputPort"); } } parentElement.appendChild(element); }
private void addFunnel(final Element parentElement, final Funnel funnel) { final Document doc = parentElement.getOwnerDocument(); final Element element = doc.createElement("funnel"); parentElement.appendChild(element); addTextElement(element, "id", funnel.getIdentifier()); addPosition(element, funnel.getPosition()); }
// utility method to create or get an existing use-sdk xml element under manifest. // this could be made more generic by adding more metadata to the enum but since there is // only one case so far, keep it simple. private static XmlElement createOrGetUseSdk( ActionRecorder actionRecorder, XmlDocument document) { Element manifest = document.getXml().getDocumentElement(); NodeList usesSdks = manifest.getElementsByTagName(ManifestModel.NodeTypes.USES_SDK.toXmlName()); if (usesSdks.getLength() == 0) { usesSdks = manifest.getElementsByTagNameNS( SdkConstants.ANDROID_URI, ManifestModel.NodeTypes.USES_SDK.toXmlName()); } if (usesSdks.getLength() == 0) { // create it first. Element useSdk = manifest.getOwnerDocument().createElement(ManifestModel.NodeTypes.USES_SDK.toXmlName()); manifest.appendChild(useSdk); XmlElement xmlElement = new XmlElement(useSdk, document); Actions.NodeRecord nodeRecord = new Actions.NodeRecord( Actions.ActionType.INJECTED, new Actions.ActionLocation(xmlElement.getSourceLocation(), PositionImpl.UNKNOWN), xmlElement.getId(), "use-sdk injection requested", NodeOperationType.STRICT); actionRecorder.recordNodeAction(xmlElement, nodeRecord); return xmlElement; } else { return new XmlElement((Element) usesSdks.item(0), document); } }
public void enableMojoExecution(MojoExecutionData execution) throws CoreException { Configuration config = lifecycleMappingPlugin.getConfiguration(); Element configNode = (Element) config.getConfigurationNode(); Element executionsDom = getChildElement(configNode, "mojoExecutions"); if (null == executionsDom) { executionsDom = configNode.getOwnerDocument().createElement("mojoExecutions"); configNode.appendChild(executionsDom); } Element executionDom = configNode.getOwnerDocument().createElement("mojoExecution"); executionDom.setAttribute("runOnIncremental", "" + execution.isRunOnIncrementalBuild()); executionDom.appendChild(configNode.getOwnerDocument().createTextNode(execution.getId())); executionsDom.appendChild(executionDom); }
private void addAttribute(Element e, String attributeName, String value) { if (value != null) { Attr attr = e.getOwnerDocument().createAttribute(attributeName); attr.setNodeValue(value); e.setAttributeNode(attr); } }
/** * Convert an item in the Segment relation into XML, inserting it at the specified location in the * XML tree. * * @param deep whether to create a deep structure of <syllable> and <ph> elements or not. */ protected String insertSegment(Item segmentItem, Element syllable, boolean deep) { // allow for syllable == null if not deep: if (segmentItem == null || deep && syllable == null) { throw new NullPointerException("Null arguments to insertSegment()"); } if (deep && !syllable.getTagName().equals(MaryXML.SYLLABLE)) { throw new IllegalArgumentException("Segments can only be inserted in <syllable> elements"); } String segmentString = segmentItem.toString(); Voice maryVoice = FreeTTSVoices.getMaryVoice(segmentItem.getUtterance().getVoice()); if (deep) { Document doc = syllable.getOwnerDocument(); Element segment = MaryXML.createElement(doc, MaryXML.PHONE); syllable.appendChild(segment); segment.setAttribute("p", segmentString); if (segmentItem.getFeatures().isPresent("end")) { float endInSeconds = segmentItem.getFeatures().getFloat("end"); int endInMillis = (int) (1000 * endInSeconds); segment.setAttribute("end", String.valueOf(endInMillis)); } if (segmentItem.getFeatures().isPresent("mbr_dur")) { int mbrDur = segmentItem.getFeatures().getInt("mbr_dur"); segment.setAttribute("d", String.valueOf(mbrDur)); } if (segmentItem.getFeatures().isPresent("mbr_targets")) { String mbrTargets = segmentItem.getFeatures().getString("mbr_targets"); if (!mbrTargets.equals("")) { segment.setAttribute("f0", mbrTargets); } } } return segmentString; }
/** * Helper method to find a specific element within a root element or to create that element if it * does not exist. */ public Element getElement(Element parent, SammaXml.ELEMENT tag) { NodeList nl = parent.getElementsByTagName(tag.toString()); if (nl.getLength() == 1) return (Element) nl.item(0); Element newel = parent.getOwnerDocument().createElement(tag.toString()); parent.appendChild(newel); return newel; }
private void processPlugin(final Element root, final ArtifactInformation a) { if (!Helper.isBundle(a.getMetaData())) { return; } final String id = a.getMetaData().get(new MetaKey(OsgiExtractor.NAMESPACE, OsgiExtractor.KEY_NAME)); final String version = a.getMetaData().get(new MetaKey(OsgiExtractor.NAMESPACE, OsgiExtractor.KEY_VERSION)); if (id == null || version == null) { return; } boolean unpack = false; try { final String biString = a.getMetaData() .get(new MetaKey(OsgiExtractor.NAMESPACE, OsgiExtractor.KEY_BUNDLE_INFORMATION)); final BundleInformation bi = BundleInformation.fromJson(biString); unpack = "dir".equals(bi.getEclipseBundleShape()); } catch (final Exception e) { } final Element p = root.getOwnerDocument().createElement("plugin"); root.appendChild(p); p.setAttribute("id", id); p.setAttribute("version", version); p.setAttribute("unpack", "" + unpack); }
/** * Parses a string containing XML and returns a DocumentFragment containing the nodes of the * parsed XML. */ public static void loadFragment(Element el, String fragment) { // Wrap the fragment in an arbitrary element fragment = "<fragment>" + fragment + "</fragment>"; try { // Create a DOM builder and parse the fragment DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(fragment))); Document doc = el.getOwnerDocument(); // Import the nodes of the new document into doc so that they // will be compatible with doc Node node = doc.importNode(d.getDocumentElement(), true); // Create the document fragment node to hold the new nodes DocumentFragment docfrag = doc.createDocumentFragment(); // Move the nodes into the fragment while (node.hasChildNodes()) { el.appendChild(node.removeChild(node.getFirstChild())); } } catch (Exception e) { log.error(e, e); } }
private void linkSequenceMembers(Entry from, Entry parent, Entry previous, Entry next) { switch (from.linking) { case NORMAL: case SOURCE_ONLY: { Element topic = from.topic; assert (topic != null); Document doc = topic.getOwnerDocument(); assert (doc != null); Element linkpool = addLinkpool(topic, /*prepend*/ true, "sequence-members", doc); if (parent != null) { addLink(linkpool, parent, "parent", doc); } if (previous != null) { addLink(linkpool, previous, "previous", doc); } if (next != null) { addLink(linkpool, next, "next", doc); } } break; } }
private void addPosition( final Element parentElement, final Position position, final String elementName) { final Element element = parentElement.getOwnerDocument().createElement(elementName); element.setAttribute("x", String.valueOf(position.getX())); element.setAttribute("y", String.valueOf(position.getY())); parentElement.appendChild(element); }
private void linkMembers(Entry from, Entry parent, CollectionType collectionType) { // In the case of choice and unordered, the siblings are not linked to // each other in any way. Therefore this leaves us with the link to // parent alone. if (parent != null) { switch (from.linking) { case NORMAL: case SOURCE_ONLY: { Element topic = from.topic; assert (topic != null); Document doc = topic.getOwnerDocument(); assert (doc != null); String linkpoolType = collectionType.toString() + "-members"; Element linkpool = addLinkpool(topic, /*prepend*/ true, linkpoolType, doc); addLink(linkpool, parent, "parent", doc); } break; } } }
/** * Transforms the given list in a valid XHTML list by moving the nodes that are not allowed inside * <ul> and <ol> in <li> elements. * * @param list the list to be filtered */ private void filter(Element list) { // Iterate all the child nodes of the given list to see who's allowed and who's not allowed // inside it. Node child = list.getFirstChild(); Node previousListItem = null; while (child != null) { Node nextSibling = child.getNextSibling(); if (isAllowedInsideList(child)) { // Save a reference to the previous list item. Note that the previous list item is not // necessarily the // previous sibling. if (child.getNodeName().equalsIgnoreCase(TAG_LI)) { previousListItem = child; } } else { if (previousListItem == null) { // Create a new list item to be able to move the invalid child. previousListItem = list.getOwnerDocument().createElement(TAG_LI); list.insertBefore(previousListItem, child); // Hide the marker of the list item to make the list look the same after it is cleaned. ((Element) previousListItem).setAttribute(ATTRIBUTE_STYLE, "list-style-type: none"); } // Move the child node at the end of the previous list item because it is not allowed where // it is now. previousListItem.appendChild(child); } child = nextSibling; } }
public IXArchElement cloneElement(int depth) { synchronized (DOMUtils.getDOMLock(elt)) { Document doc = elt.getOwnerDocument(); if (depth == 0) { Element cloneElt = (Element) elt.cloneNode(false); cloneElt = (Element) doc.importNode(cloneElt, true); AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(cloneElt); cloneImpl.setXArch(getXArch()); return cloneImpl; } else if (depth == 1) { Element cloneElt = (Element) elt.cloneNode(false); cloneElt = (Element) doc.importNode(cloneElt, true); AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(cloneElt); cloneImpl.setXArch(getXArch()); NodeList nl = elt.getChildNodes(); int size = nl.getLength(); for (int i = 0; i < size; i++) { Node n = nl.item(i); Node cloneNode = (Node) n.cloneNode(false); cloneNode = doc.importNode(cloneNode, true); cloneElt.appendChild(cloneNode); } return cloneImpl; } else /* depth = infinity */ { Element cloneElt = (Element) elt.cloneNode(true); cloneElt = (Element) doc.importNode(cloneElt, true); AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(cloneElt); cloneImpl.setXArch(getXArch()); return cloneImpl; } } }
/** @see com.levelonelabs.aim.XMLizable#writeState(Element) */ public void writeState(Element emptyStateElement) { Document doc = emptyStateElement.getOwnerDocument(); emptyStateElement.setAttribute("name", this.getName()); emptyStateElement.setAttribute("group", this.getGroup()); emptyStateElement.setAttribute("isBanned", Boolean.toString(this.isBanned())); Iterator roleit = roles.keySet().iterator(); while (roleit.hasNext()) { String role = (String) roleit.next(); Element roleElem = doc.createElement("role"); roleElem.setAttribute("name", role); emptyStateElement.appendChild(roleElem); } Iterator prefs = preferences.keySet().iterator(); while (prefs.hasNext()) { String pref = (String) prefs.next(); Element prefElem = doc.createElement("preference"); prefElem.setAttribute("name", pref); prefElem.setAttribute("value", (String) preferences.get(pref)); emptyStateElement.appendChild(prefElem); } for (int i = 0; i < messages.size(); i++) { String message = (String) messages.get(i); Element messElem = doc.createElement("message"); CDATASection data = doc.createCDATASection(message); messElem.appendChild(data); emptyStateElement.appendChild(messElem); } }