Java Code Examples for org.dom4j.Element#addNamespace()
The following examples show how to use
org.dom4j.Element#addNamespace() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManifestFileUtils.java From atlas with Apache License 2.0 | 6 votes |
public static void updatePreProcessBaseManifestFile(File modifyManifest, File orgManifestFile) throws IOException, DocumentException { Document document = XmlHelper.readXml(orgManifestFile);// Read the XML file Element root = document.getRootElement();// Get the root node root.addNamespace("tools", "http://schemas.android.com/tools"); Element applicationElement = root.element("application"); //Determines whether there is application and needs to be deleted if (null != applicationElement) { applicationElement.addAttribute("tools:replace", "android:name,android:icon,android:allowBackup,android:label," + "android:supportsRtl"); } XmlHelper.saveDocument(document, modifyManifest); }
Example 2
Source File: UnifiedXmlDataShapeSupport.java From syndesis with Apache License 2.0 | 5 votes |
@Override public DataShape createShapeFromResponse(final ObjectNode json, final T openApiDoc, final O operation) { final Optional<R> maybeResponse = findResponse(openApiDoc, operation, hasSchema(), getResponseType()); if (!maybeResponse.isPresent()) { return DATA_SHAPE_NONE; } final Document document = DocumentHelper.createDocument(); final Element schemaSet = document.addElement("d:SchemaSet", SCHEMA_SET_NS); schemaSet.addNamespace(XmlSchemaHelper.XML_SCHEMA_PREFIX, XmlSchemaHelper.XML_SCHEMA_NS); final Map<String, SchemaPrefixAndElement> moreSchemas = new HashMap<>(); final Element bodySchema = createResponseBodySchema(openApiDoc, getSchema(maybeResponse.get()), moreSchemas); if (bodySchema == null) { return DATA_SHAPE_NONE; } schemaSet.add(bodySchema.detach()); if (!moreSchemas.isEmpty()) { final Element additionalSchemas = schemaSet.addElement("d:AdditionalSchemas"); moreSchemas.values().forEach(e -> additionalSchemas.add(e.schema.detach())); } final String xmlSchemaSet = XmlSchemaHelper.serialize(document); return new DataShape.Builder()// .name("Response")// .description("API response payload")// .kind(DataShapeKinds.XML_SCHEMA)// .specification(xmlSchemaSet)// .putMetadata(DataShapeMetaData.UNIFIED, "true") .build(); }
Example 3
Source File: GMLMapFormat.java From rcrs-server with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void write(Map map, File file) throws MapException { if (map == null) { throw new IllegalArgumentException("Map must not be null"); } if (file == null) { throw new IllegalArgumentException("File must not be null"); } if (!(map instanceof GMLMap)) { throw new IllegalArgumentException("Map is not a GMLMap: " + map.getClass().getName()); } Document doc = write((GMLMap)map); try { if (!file.exists()) { File parent = file.getParentFile(); if (!parent.exists()) { if (!file.getParentFile().mkdirs()) { throw new MapException("Couldn't create file " + file.getPath()); } } if (!file.createNewFile()) { throw new MapException("Couldn't create file " + file.getPath()); } } XMLWriter writer = new XMLWriter(new FileOutputStream(file), OutputFormat.createPrettyPrint()); Element root = doc.getRootElement(); for (java.util.Map.Entry<String, String> next : getNamespaces().entrySet()) { root.addNamespace(next.getKey(), next.getValue()); } writer.write(doc); writer.flush(); writer.close(); } catch (IOException e) { throw new MapException(e); } }
Example 4
Source File: BpmnXMLConverter.java From FoxBPM with Apache License 2.0 | 5 votes |
/** * 将bpmnModel转换成documnet * * @param model * bpmn模型 */ public Document convertToXML(BpmnModel model) { if (null == model) { throw new BpmnConverterException("模型转换XML失败,模型实例不能为空!"); } DocumentFactory factory = DocumentFactory.getInstance(); Document doc = factory.createDocument(); Element element = factory.createElement(BpmnXMLConstants.BPMN2_PREFIX + ':' + BpmnXMLConstants.ELEMENT_DEFINITIONS, BpmnXMLConstants.BPMN2_NAMESPACE); element.addNamespace(BpmnXMLConstants.XSI_PREFIX, BpmnXMLConstants.XSI_NAMESPACE); element.addNamespace(BpmnXMLConstants.DC_PREFIX, BpmnXMLConstants.DC_NAMESPACE); element.addNamespace(BpmnXMLConstants.DI_PREFIX, BpmnXMLConstants.DI_NAMESPACE); element.addNamespace(BpmnXMLConstants.BPMNDI_PREFIX, BpmnXMLConstants.BPMNDI_NAMESPACE); element.addNamespace(BpmnXMLConstants.FOXBPM_PREFIX, BpmnXMLConstants.FOXBPM_NAMESPACE); element.addNamespace(BpmnXMLConstants.XSD_PREFIX, BpmnXMLConstants.XSD_NAMESPACE); element.addNamespace(BpmnXMLConstants.EMPTY_STRING, BpmnXMLConstants.XMLNS_NAMESPACE); // 添加属性 element.addAttribute(BpmnXMLConstants.TARGET_NAMESPACE_ATTRIBUTE, BpmnXMLConstants.XMLNS_NAMESPACE); element.addAttribute(BpmnXMLConstants.ATTRIBUTE_ID, "Definitions_1"); doc.add(element); // 流程转换 try { for (Iterator<Process> iterator = model.getProcesses().iterator(); iterator.hasNext();) { ProcessExport.writeProcess(iterator.next(), element); } // 位置坐标转换 BPMNDIExport.writeBPMNDI(model, element); } catch (Exception e) { LOGGER.error("模型转换XML失败,流程名" + model.getProcesses().get(0).getName(), e); if (e instanceof BpmnConverterException) { throw (BpmnConverterException) e; } else { throw new BpmnConverterException("模型转换XML失败,流程名:" + model.getProcesses().get(0).getName(), e); } } return doc; }
Example 5
Source File: HttpSessionManager.java From Openfire with Apache License 2.0 | 5 votes |
private static String createSessionCreationResponse(HttpSession session) throws DocumentException { Element response = DocumentHelper.createElement( QName.get( "body", "http://jabber.org/protocol/httpbind" ) ); response.addNamespace("stream", "http://etherx.jabber.org/streams"); response.addAttribute("from", session.getServerName()); response.addAttribute("authid", session.getStreamID().getID()); response.addAttribute("sid", session.getStreamID().getID()); response.addAttribute("secure", Boolean.TRUE.toString()); response.addAttribute("requests", String.valueOf(session.getMaxRequests())); response.addAttribute("inactivity", String.valueOf(session.getInactivityTimeout())); response.addAttribute("polling", String.valueOf(session.getMaxPollingInterval())); response.addAttribute("wait", String.valueOf(session.getWait())); if ((session.getMajorVersion() == 1 && session.getMinorVersion() >= 6) || session.getMajorVersion() > 1) { response.addAttribute("hold", String.valueOf(session.getHold())); response.addAttribute("ack", String.valueOf(session.getLastAcknowledged())); response.addAttribute("maxpause", String.valueOf(session.getMaxPause())); response.addAttribute("ver", String.valueOf(session.getMajorVersion()) + "." + String.valueOf(session.getMinorVersion())); } Element features = response.addElement("stream:features"); for (Element feature : session.getAvailableStreamFeaturesElements()) { features.add(feature); } return response.asXML(); }
Example 6
Source File: HttpSession.java From Openfire with Apache License 2.0 | 5 votes |
private String createSessionRestartResponse() { final Element response = DocumentHelper.createElement( QName.get( "body", "http://jabber.org/protocol/httpbind" ) ); response.addNamespace("stream", "http://etherx.jabber.org/streams"); final Element features = response.addElement("stream:features"); for (Element feature : getAvailableStreamFeaturesElements()) { features.add(feature); } return response.asXML(); }
Example 7
Source File: UnifiedXmlDataShapeSupport.java From syndesis with Apache License 2.0 | 4 votes |
@Override public DataShape createShapeFromRequest(final ObjectNode json, final T openApiDoc, final O operation) { final Document document = DocumentHelper.createDocument(); final Element schemaSet = document.addElement("d:SchemaSet", SCHEMA_SET_NS); schemaSet.addNamespace(XmlSchemaHelper.XML_SCHEMA_PREFIX, XmlSchemaHelper.XML_SCHEMA_NS); final Element schema = XmlSchemaHelper.addElement(schemaSet, "schema"); schema.addAttribute("targetNamespace", SYNDESIS_REQUEST_NS); schema.addAttribute("elementFormDefault", "qualified"); final Element parametersSchema = createParametersSchema(openApiDoc, operation); final Map<String, SchemaPrefixAndElement> moreSchemas = new HashMap<>(); final Element bodySchema = createRequestBodySchema(openApiDoc, operation, moreSchemas); if (bodySchema == null && parametersSchema == null) { return DATA_SHAPE_NONE; } final Element element = XmlSchemaHelper.addElement(schema, ELEMENT); element.addAttribute(NAME, "request"); final Element sequence = XmlSchemaHelper.addElement(element, COMPLEX_TYPE, SEQUENCE); final Element additionalSchemas = schemaSet.addElement("d:AdditionalSchemas"); if (parametersSchema != null) { final Element parameters = XmlSchemaHelper.addElement(sequence, ELEMENT); parameters.addNamespace("p", SYNDESIS_PARAMETERS_NS); parameters.addAttribute(REF, "p:parameters"); additionalSchemas.add(parametersSchema.detach()); } if (bodySchema != null) { final Element bodyElement = XmlSchemaHelper.addElement(sequence, ELEMENT); bodyElement.addAttribute(NAME, "body"); final Element body = XmlSchemaHelper.addElement(bodyElement, COMPLEX_TYPE, SEQUENCE, ELEMENT); final String bodyTargetNamespace = bodySchema.attributeValue("targetNamespace"); final String bodyElementName = bodySchema.element(ELEMENT).attributeValue(NAME); if (bodyTargetNamespace != null) { body.addNamespace("b", bodyTargetNamespace); body.addAttribute(REF, "b:" + bodyElementName); } else { body.addAttribute(REF, bodyElementName); } additionalSchemas.add(bodySchema.detach()); } moreSchemas.values().forEach(e -> additionalSchemas.add(e.schema.detach())); final String xmlSchemaSet = XmlSchemaHelper.serialize(document); return new DataShape.Builder()// .kind(DataShapeKinds.XML_SCHEMA)// .name("Request")// .description("API request payload")// .specification(xmlSchemaSet)// .putMetadata(DataShapeMetaData.UNIFIED, "true") .build(); }
Example 8
Source File: UnifiedXmlDataShapeSupport.java From syndesis with Apache License 2.0 | 4 votes |
private Element defineComplexElement(final OasSchema property, final Element parent, final T openApiDoc, final Map<String, SchemaPrefixAndElement> moreSchemas) { final OasSchema model = dereference(property, openApiDoc); Element ret; Element elementToDeclareIn; final String namespace = XmlSchemaHelper.xmlTargetNamespaceOrNull(model); final String name = XmlSchemaHelper.xmlNameOrDefault(model.xml, getName(model)); if (namespace != null && parent != null) { // this is element that could be in a (possibly) previously unknown // namespace final SchemaPrefixAndElement schemaPrefixAndElement = moreSchemas.computeIfAbsent(namespace, n -> { return new SchemaPrefixAndElement("p" + moreSchemas.size(), XmlSchemaHelper.newXmlSchema(n)); }); elementToDeclareIn = XmlSchemaHelper.addElement(schemaPrefixAndElement.schema, ELEMENT); elementToDeclareIn.addAttribute(NAME, name); ret = XmlSchemaHelper.addElement(parent, ELEMENT); ret.addAttribute(REF, schemaPrefixAndElement.prefix + ":" + name); ret.addNamespace(schemaPrefixAndElement.prefix, namespace); } else { if (parent == null) { // this is the top level element (in a new namespace) ret = XmlSchemaHelper.newXmlSchema(namespace); elementToDeclareIn = XmlSchemaHelper.addElement(ret, ELEMENT); elementToDeclareIn.addAttribute(NAME, name); } else { // this is a nested element in the same namespace ret = XmlSchemaHelper.addElement(parent, ELEMENT); ret.addAttribute(NAME, name); elementToDeclareIn = ret; } } final Element complex = XmlSchemaHelper.addElement(elementToDeclareIn, COMPLEX_TYPE); final Element sequence = XmlSchemaHelper.addElement(complex, SEQUENCE); defineElementPropertiesOf(sequence, model, openApiDoc, moreSchemas); defineAttributePropertiesOf(complex, model); return ret; }