/** * Carries out preprocessing that makes JEuclid handle the document better. * * @param doc Document */ static void preprocessForJEuclid(Document doc) { // underbrace and overbrace NodeList list = doc.getElementsByTagName("mo"); for (int i = 0; i < list.getLength(); i++) { Element mo = (Element) list.item(i); String parentName = ((Element) mo.getParentNode()).getTagName(); if (parentName == null) { continue; } if (parentName.equals("munder") && isTextChild(mo, "\ufe38")) { mo.setAttribute("stretchy", "true"); mo.removeChild(mo.getFirstChild()); mo.appendChild(doc.createTextNode("\u23df")); } else if (parentName.equals("mover") && isTextChild(mo, "\ufe37")) { mo.setAttribute("stretchy", "true"); mo.removeChild(mo.getFirstChild()); mo.appendChild(doc.createTextNode("\u23de")); } } // menclose for long division doesn't allow enough top padding. Oh, and // <mpadded> isn't implemented. And there isn't enough padding to left of // the bar either. Solve by adding an <mover> with just an <mspace> over# // the longdiv, contained within an mrow that adds a <mspace> before it. list = doc.getElementsByTagName("menclose"); for (int i = 0; i < list.getLength(); i++) { Element menclose = (Element) list.item(i); // Only for longdiv if (!"longdiv".equals(menclose.getAttribute("notation"))) { continue; } Element mrow = doc.createElementNS(WebMathsService.NS, "mrow"); Element mover = doc.createElementNS(WebMathsService.NS, "mover"); Element mspace = doc.createElementNS(WebMathsService.NS, "mspace"); Element mspaceW = doc.createElementNS(WebMathsService.NS, "mspace"); boolean previousElement = false; for (Node previous = menclose.getPreviousSibling(); previous != null; previous = previous.getPreviousSibling()) { if (previous.getNodeType() == Node.ELEMENT_NODE) { previousElement = true; break; } } if (previousElement) { mspaceW.setAttribute("width", "4px"); } menclose.getParentNode().insertBefore(mrow, menclose); menclose.getParentNode().removeChild(menclose); mrow.appendChild(mspaceW); mrow.appendChild(mover); mover.appendChild(menclose); mover.appendChild(mspace); } }
public void remove(Track track) { synchronized (this) { docElt.removeChild(track.getElement()); tracks.remove(track); hash.remove(track.getKey()); } }
/** * Set a property of a resource to a value. * * @param name the property name * @param value the property value * @exception com.ibm.webdav.WebDAVException */ public void setProperty(String name, Element value) throws WebDAVException { // load the properties Document propertiesDocument = resource.loadProperties(); Element properties = propertiesDocument.getDocumentElement(); String ns = value.getNamespaceURI(); Element property = null; if (ns == null) { property = (Element) ((Element) properties).getElementsByTagName(value.getTagName()).item(0); } else { property = (Element) properties.getElementsByTagNameNS(ns, value.getLocalName()).item(0); } if (property != null) { try { properties.removeChild(property); } catch (DOMException exc) { } } properties.appendChild(propertiesDocument.importNode(value, true)); // write out the properties resource.saveProperties(propertiesDocument); }
public void addPackageClass(PackageClass pClass) { Document doc; try { doc = getDocument(); } catch (Exception e) { e.printStackTrace(); return; } String name = pClass.getName(); // check if such class exists and remove duplicates Element rootEl = doc.getDocumentElement(); NodeList classEls = rootEl.getElementsByTagName(EL_CLASS); for (int i = 0; i < classEls.getLength(); i++) { Element nameEl = getElementByName((Element) classEls.item(i), EL_NAME); if (name.equals(nameEl.getTextContent())) { rootEl.removeChild(classEls.item(i)); } } Element classNode = doc.createElement(EL_CLASS); doc.getDocumentElement().appendChild(classNode); classNode.setAttribute(ATR_TYPE, PackageClass.ComponentType.SCHEME.getXmlName()); classNode.setAttribute(ATR_STATIC, "false"); Element className = doc.createElement(EL_NAME); className.setTextContent(name); classNode.appendChild(className); Element desrc = doc.createElement(EL_DESCRIPTION); desrc.setTextContent(pClass.getDescription()); classNode.appendChild(desrc); Element icon = doc.createElement(EL_ICON); icon.setTextContent(pClass.getIcon()); classNode.appendChild(icon); // graphics classNode.appendChild(generateGraphicsNode(doc, pClass.getGraphics())); // ports List<Port> ports = pClass.getPorts(); if (!ports.isEmpty()) { Element portsEl = doc.createElement(EL_PORTS); classNode.appendChild(portsEl); for (Port port : ports) { portsEl.appendChild(generatePortNode(doc, port)); } } // fields Collection<ClassField> fields = pClass.getFields(); if (!fields.isEmpty()) { Element fieldsEl = doc.createElement(EL_FIELDS); classNode.appendChild(fieldsEl); for (ClassField cf : fields) { fieldsEl.appendChild(generateFieldNode(doc, cf)); } } // write try { writeDocument(doc, new FileOutputStream(xmlFile)); } catch (FileNotFoundException e) { e.printStackTrace(); } }
/** * Edit the properties of a resource. The updates must refer to a Document containing a WebDAV * propertyupdates element as the document root. * * @param updates an XML Document containing propertyupdate elements * @return the result of making the updates describing the edits to be made. * @exception com.ibm.webdav.WebDAVException */ public MultiStatus setProperties(Document propertyUpdates) throws WebDAVException { // create a MultiStatus to hold the results. It will hold a MethodResponse // for each update, and one for the method as a whole MultiStatus multiStatus = new MultiStatus(); boolean errorsOccurred = false; // first, load the properties so they can be edited Document propertiesDocument = resource.loadProperties(); Element properties = (Element) propertiesDocument.getDocumentElement(); // be sure the updates have at least one update Element propertyupdate = (Element) propertyUpdates.getDocumentElement(); String tagName = propertyupdate.getNamespaceURI() + propertyupdate.getLocalName(); if (!tagName.equals("DAV:propertyupdate")) { throw new WebDAVException( WebDAVStatus.SC_UNPROCESSABLE_ENTITY, "missing propertyupdate element"); } NodeList updates = propertyupdate.getChildNodes(); if (updates.getLength() == 0) { throw new WebDAVException(WebDAVStatus.SC_UNPROCESSABLE_ENTITY, "no updates in request"); } Vector propsGood = new Vector(); // a list of properties that // were patched correctly or would have been if another // property hadn't gone bad. // apply the updates Node temp = null; for (int i = 0; i < updates.getLength(); i++) { temp = updates.item(i); // skip any ignorable TXText elements if (!(temp.getNodeType() == Node.ELEMENT_NODE)) { continue; } Element update = (Element) temp; int updateCommand = -1; tagName = update.getNamespaceURI() + update.getLocalName(); if (tagName.equals("DAV:set")) { updateCommand = set; } else if (tagName.equals("DAV:remove")) { updateCommand = remove; } else { throw new WebDAVException( WebDAVStatus.SC_UNPROCESSABLE_ENTITY, update.getTagName() + " is not a valid property update request"); } // iterate through the props in the set or remove element and update the // properties as directed Element prop = (Element) update.getElementsByTagNameNS("DAV:", "prop").item(0); if (prop == null) { throw new WebDAVException( WebDAVStatus.SC_UNPROCESSABLE_ENTITY, "no propeprties in update request"); } NodeList propsToUpdate = prop.getChildNodes(); for (int j = 0; j < propsToUpdate.getLength(); j++) { temp = propsToUpdate.item(j); // skip any TXText elements?? if (!(temp.getNodeType() == Node.ELEMENT_NODE)) { continue; } Element propToUpdate = (Element) temp; // find the property in the properties element Element property = null; PropertyName propertyName = new PropertyName(propToUpdate); if (((Element) propToUpdate).getNamespaceURI() != null) { property = (Element) properties .getElementsByTagNameNS( propToUpdate.getNamespaceURI(), propToUpdate.getLocalName()) .item(0); } else { property = (Element) properties.getElementsByTagName(propToUpdate.getTagName()).item(0); } boolean liveone = isLive(propertyName.asExpandedString()); if (liveone) { errorsOccurred = true; PropertyResponse response = new PropertyResponse(resource.getURL().toString()); response.addProperty(propertyName, propToUpdate, WebDAVStatus.SC_FORBIDDEN); multiStatus.addResponse(response); } // do the update if (updateCommand == set) { if (property != null) { try { properties.removeChild(property); } catch (DOMException exc) { } } if (!liveone) { // I don't think we're allowed to update live properties // here. Doing so effects the cache. A case in // point is the lockdiscoveryproperty. properties // is actually the properites cache "document" of this // resource. Even though we don't "save" the request // if it includes live properties, we don't remove // it from the cache after we'd set it here, so it // can affect other queries. (jlc 991002) properties.appendChild(propertiesDocument.importNode(propToUpdate, true)); propsGood.addElement(propToUpdate); } } else if (updateCommand == remove) { try { if (property != null) { properties.removeChild(property); propsGood.addElement(propToUpdate); } } catch (DOMException exc) { } } } } { Enumeration els = propsGood.elements(); for (; els.hasMoreElements(); ) { Object ob1 = els.nextElement(); Element elProp = (Element) ob1; PropertyName pn = new PropertyName(elProp); PropertyResponse response = new PropertyResponse(resource.getURL().toString()); response.addProperty( pn, (Element) elProp.cloneNode(false), (errorsOccurred ? WebDAVStatus.SC_FAILED_DEPENDENCY : WebDAVStatus.SC_OK)); // todo: add code for responsedescription multiStatus.addResponse(response); } } // write out the properties if (!errorsOccurred) { resource.saveProperties(propertiesDocument); } return multiStatus; }