List of usage examples for org.w3c.dom Node getNextSibling
public Node getNextSibling();
From source file:org.n52.wps.server.handler.RequestHandler.java
/** * Handles requests of type HTTP_POST (currently executeProcess). A Document * is used to represent the client input. This Document must first be parsed * from an InputStream./*www .j ava2 s. c om*/ * * @param is * The client input * @param os * The OutputStream to write the response to. * @throws ExceptionReport */ public RequestHandler(InputStream is, OutputStream os) throws ExceptionReport { String nodeName, localName, nodeURI, version = null; Document doc; this.os = os; boolean isCapabilitiesNode = false; try { System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance(); fac.setNamespaceAware(true); // parse the InputStream to create a Document doc = fac.newDocumentBuilder().parse(is); // Get the first non-comment child. Node child = doc.getFirstChild(); while (child.getNodeName().compareTo("#comment") == 0) { child = child.getNextSibling(); } nodeName = child.getNodeName(); localName = child.getLocalName(); nodeURI = child.getNamespaceURI(); Node versionNode = child.getAttributes().getNamedItem("version"); /* * check for service parameter. this has to be present for all requests */ Node serviceNode = child.getAttributes().getNamedItem("service"); if (serviceNode == null) { throw new ExceptionReport("Parameter <service> not specified.", ExceptionReport.MISSING_PARAMETER_VALUE, "service"); } else { if (!serviceNode.getNodeValue().equalsIgnoreCase("WPS")) { throw new ExceptionReport("Parameter <service> not specified.", ExceptionReport.INVALID_PARAMETER_VALUE, "service"); } } isCapabilitiesNode = nodeName.toLowerCase().contains("capabilities"); if (versionNode == null && !isCapabilitiesNode) { throw new ExceptionReport("Parameter <version> not specified.", ExceptionReport.MISSING_PARAMETER_VALUE, "version"); } //TODO: I think this can be removed, as capabilities requests do not have a version parameter (BenjaminPross) if (!isCapabilitiesNode) { // version = child.getFirstChild().getTextContent();//.getNextSibling().getFirstChild().getNextSibling().getFirstChild().getNodeValue(); version = child.getAttributes().getNamedItem("version").getNodeValue(); } /* * check language, if not supported, return ExceptionReport * Fix for https://bugzilla.52north.org/show_bug.cgi?id=905 */ Node languageNode = child.getAttributes().getNamedItem("language"); if (languageNode != null) { String language = languageNode.getNodeValue(); Request.checkLanguageSupported(language); } } catch (SAXException e) { throw new ExceptionReport("There went something wrong with parsing the POST data: " + e.getMessage(), ExceptionReport.NO_APPLICABLE_CODE, e); } catch (IOException e) { throw new ExceptionReport("There went something wrong with the network connection.", ExceptionReport.NO_APPLICABLE_CODE, e); } catch (ParserConfigurationException e) { throw new ExceptionReport("There is a internal parser configuration error", ExceptionReport.NO_APPLICABLE_CODE, e); } //Fix for Bug 904 https://bugzilla.52north.org/show_bug.cgi?id=904 if (!isCapabilitiesNode && version == null) { throw new ExceptionReport("Parameter <version> not specified.", ExceptionReport.MISSING_PARAMETER_VALUE, "version"); } if (!isCapabilitiesNode && !version.equals(Request.SUPPORTED_VERSION)) { throw new ExceptionReport("Version not supported.", ExceptionReport.INVALID_PARAMETER_VALUE, "version"); } // get the request type if (nodeURI.equals(WebProcessingService.WPS_NAMESPACE) && localName.equals("Execute")) { req = new ExecuteRequest(doc); setResponseMimeType((ExecuteRequest) req); } else if (nodeURI.equals(WebProcessingService.WPS_NAMESPACE) && localName.equals("GetCapabilities")) { req = new CapabilitiesRequest(doc); this.responseMimeType = "text/xml"; } else if (nodeURI.equals(WebProcessingService.WPS_NAMESPACE) && localName.equals("DescribeProcess")) { req = new DescribeProcessRequest(doc); this.responseMimeType = "text/xml"; } else if (!localName.equals("Execute")) { throw new ExceptionReport( "The requested Operation not supported or not applicable to the specification: " + nodeName, ExceptionReport.OPERATION_NOT_SUPPORTED, localName); } else if (nodeURI.equals(WebProcessingService.WPS_NAMESPACE)) { throw new ExceptionReport("specified namespace is not supported: " + nodeURI, ExceptionReport.INVALID_PARAMETER_VALUE); } }
From source file:org.nimbustools.messaging.gt4_0_elastic.rpc.RequestEngine.java
protected Element perhapsChangeTimestampFormat(Element timestampElem) throws Exception { if (timestampElem == null) { throw new Exception("timestampElem may not be null"); }//from www .jav a 2s . c o m final Node firstChild = timestampElem.getFirstChild(); if (firstChild == null) { logger.warn("Timestamp but no data enclosed?"); return timestampElem; } final String firstChildLocal = firstChild.getLocalName(); if (firstChildLocal != null && firstChildLocal.equals("Created")) { if (firstChildLocal.equals("Created")) { this.handleCreatedOrExpires(firstChild, "Created"); } else { logger.warn("Timestamp with something besides " + "Created: '" + firstChildLocal + "'"); return timestampElem; } final Node sibling = firstChild.getNextSibling(); if (sibling == null) { logger.warn("Timestamp with Created but no Expires?"); return timestampElem; } final String siblingLocal = sibling.getLocalName(); if (siblingLocal != null && siblingLocal.equals("Expires")) { this.handleCreatedOrExpires(sibling, "Expires"); } else { logger.warn("Timestamp with Created but no Expires?"); logger.warn( "Timestamp with Created and then something " + "besides Expires: '" + siblingLocal + "'"); return timestampElem; } } return timestampElem; }
From source file:org.nuxeo.common.xmap.XMap.java
/** * Processes the given DOM element and return the first mappable object found in the element. * <p>/*from w ww . j a v a 2 s . c o m*/ * The given context is used. * * @param ctx the context to use * @param root the element to process * @return the first object found in this element or null if none */ public Object load(Context ctx, Element root) { // check if the current element is bound to an annotated object String name = root.getNodeName(); XAnnotatedObject xob = roots.get(name); if (xob != null) { return xob.newInstance(ctx, root); } else { Node p = root.getFirstChild(); while (p != null) { if (p.getNodeType() == Node.ELEMENT_NODE) { // Recurse in the first child Element return load((Element) p); } p = p.getNextSibling(); } // We didn't find any Element return null; } }
From source file:org.nuxeo.common.xmap.XMap.java
/** * Same as {@link XMap#loadAll(Context, Element)} but put collected objects in the given collection. * * @param ctx the context to use/* ww w . j a v a2s . c o m*/ * @param root the element to process * @param result the collection where to collect objects */ public void loadAll(Context ctx, Element root, Collection<Object> result) { // check if the current element is bound to an annotated object String name = root.getNodeName(); XAnnotatedObject xob = roots.get(name); if (xob != null) { Object ob = xob.newInstance(ctx, root); result.add(ob); } else { Node p = root.getFirstChild(); while (p != null) { if (p.getNodeType() == Node.ELEMENT_NODE) { loadAll(ctx, (Element) p, result); } p = p.getNextSibling(); } } }
From source file:org.nuxeo.connect.update.task.standalone.CommandsTask.java
public void readLog(Reader reader) throws PackageException { try {//from www . j ava 2 s.c o m DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new InputSource(reader)); Element root = document.getDocumentElement(); Node node = root.getFirstChild(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; String id = node.getNodeName(); Command cmd = service.getCommand(id); if (cmd == null) { // may be the name of an embedded class try { cmd = (Command) pkg.getData().loadClass(id).getConstructor().newInstance(); } catch (ReflectiveOperationException t) { throw new PackageException("Unknown command: " + id); } } cmd.initialize(element); cmd.setPackageUpdateService(service); commands.add(cmd); } node = node.getNextSibling(); } } catch (ParserConfigurationException | SAXException | IOException e) { throw new PackageException("Failed to read commands", e); } }
From source file:org.nuxeo.connect.update.task.update.RegistrySerializer.java
protected void read(Element element, Map<String, Entry> registry) throws PackageException { Node node = element.getFirstChild(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE && "entry".equals(node.getNodeName())) { Entry entry = readEntryElement((Element) node); registry.put(entry.getKey(), entry); }/* www. j ava2 s . c o m*/ node = node.getNextSibling(); } }
From source file:org.nuxeo.connect.update.task.update.RegistrySerializer.java
protected Entry readEntryElement(Element element) throws PackageException { Entry entry = new Entry(readKeyAttr(element)); Node node = element.getFirstChild(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE) { String name = node.getNodeName(); if ("version".equals(name)) { Version v = readVersionElement((Element) node); entry.addVersion(v);//from w ww . ja v a 2 s . c o m } else if ("base-version".equals(name)) { Version v = readVersionElement((Element) node); entry.setBaseVersion(v); } } node = node.getNextSibling(); } return entry; }
From source file:org.nuxeo.connect.update.task.update.RegistrySerializer.java
protected Version readVersionElement(Element element) throws PackageException { Version v = new Version(readNameAttr(element)); v.setPath(readPathAttr(element));/* w w w . j a v a2 s . c o m*/ Node node = element.getFirstChild(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE && "package".equals(node.getNodeName())) { UpdateOptions opt = new UpdateOptions(); opt.pkgId = ((Element) node).getTextContent().trim(); opt.upgradeOnly = Boolean.parseBoolean(((Element) node).getAttribute("upgradeOnly")); v.addPackage(opt); } node = node.getNextSibling(); } return v; }
From source file:org.nuxeo.ecm.platform.forms.layout.descriptors.WidgetDescriptor.java
@XContent("selectOptions") public void setSelectOptions(DocumentFragment selectOptionsDOM) { XMap xmap = new XMap(); xmap.register(WidgetSelectOptionDescriptor.class); xmap.register(WidgetSelectOptionsDescriptor.class); Node p = selectOptionsDOM.getFirstChild(); List<WidgetSelectOption> options = new ArrayList<WidgetSelectOption>(); while (p != null) { if (p.getNodeType() == Node.ELEMENT_NODE) { Object desc = xmap.load((Element) p); if (desc instanceof WidgetSelectOptionDescriptor) { options.add(((WidgetSelectOptionDescriptor) desc).getWidgetSelectOption()); } else if (desc instanceof WidgetSelectOptionsDescriptor) { options.add(((WidgetSelectOptionsDescriptor) desc).getWidgetSelectOption()); } else { log.error("Unknown resolution of select option"); }/*from w ww. j a v a 2 s .c o m*/ } p = p.getNextSibling(); } selectOptions = options.toArray(new WidgetSelectOption[0]); }
From source file:org.nuxeo.ecm.webengine.security.GuardDescriptor.java
@XContent protected void setGuards(DocumentFragment content) { Node node = content.getFirstChild(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE) { String name = node.getNodeName(); if ("guard".equals(name)) { NamedNodeMap map = node.getAttributes(); Node aId = map.getNamedItem("id"); Node aType = map.getNamedItem("type"); if (aId == null) { throw new IllegalArgumentException("id is required"); }/*from w ww . j a va2s . c o m*/ String id = aId.getNodeValue(); if (aType == null) { throw new IllegalArgumentException("type is required"); } else { //String value = node.getTextContent().trim(); //guards.put(id, new ScriptGuard(value)); //TODO: compound guard } String type = aType.getNodeValue(); if ("permission".equals(type)) { String value = node.getTextContent().trim(); guards.put(id, new PermissionGuard(value)); } else if ("isAdministrator".equals(type)) { String value = node.getTextContent().trim(); guards.put(id, new IsAdministratorGuard(value)); } else if ("facet".equals(type)) { String value = node.getTextContent().trim(); guards.put(id, new FacetGuard(value)); } else if ("type".equals(type)) { String value = node.getTextContent().trim(); guards.put(id, new TypeGuard(value)); } else if ("schema".equals(type)) { String value = node.getTextContent().trim(); guards.put(id, new SchemaGuard(value)); } else if ("user".equals(type)) { String value = node.getTextContent().trim(); guards.put(id, new UserGuard(value)); } else if ("group".equals(type)) { String value = node.getTextContent().trim(); guards.put(id, new GroupGuard(value)); } else if ("script".equals(type)) { Node engineNode = map.getNamedItem("engine"); if (engineNode == null) { throw new IllegalArgumentException("Must specify an engine attribute on script guards"); } String value = node.getTextContent().trim(); guards.put(id, new ScriptGuard(engineNode.getNodeValue(), value)); } else if ("expression".equals(type)) { String value = node.getTextContent().trim(); try { guards.put(id, PermissionService.getInstance().parse(value, guards)); } catch (ParseException e) { log.error(e, e); } } else { // the type should be a guard factory String value = node.getTextContent().trim(); try { Class<?> factory = Class.forName(type); Guard guard = ((GuardFactory) factory.newInstance()).newGuard(value); guards.put(id, guard); } catch (Exception e) { log.error(e, e); //TODO should throw a DeployException } } } } node = node.getNextSibling(); } }