List of usage examples for org.dom4j Namespace Namespace
public Namespace(String prefix, String uri)
From source file:com.alibaba.citrus.dev.handler.util.ConfigurationFileReader.java
License:Open Source License
private ConfigurationFile parseConfigurationFile(final NamedResource namedResource, final Set<String> parsedNames) { URL url;//from ww w . ja v a 2 s. co m try { url = namedResource.resource.getURL(); } catch (IOException e) { unexpectedException(e); return null; } String name = url.toExternalForm(); if (name.startsWith(baseURL)) { name = name.substring(baseURL.length()); } if (parsedNames.contains(name)) { return null; } parsedNames.add(name); final List<ConfigurationFile> importedConfigurationFiles = createLinkedList(); Element rootElement; try { rootElement = DomUtil.readDocument(name, url, new ElementFilter() { public org.dom4j.Element filter(org.dom4j.Element e) throws Exception { // schemaLocation org.dom4j.Attribute attr = e.attribute(new QName("schemaLocation", new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"))); if (attr != null) { e.remove(attr); } // beans:importelement if ("http://www.springframework.org/schema/beans".equals(e.getNamespaceURI()) && "import".equals(e.getName())) { String importedResourceName = trimToNull(e.attributeValue("resource")); if (importedResourceName != null) { Resource importedResource; if (importedResourceName.contains(":")) { importedResource = loader.getResource(importedResourceName); } else { importedResource = namedResource.resource.createRelative(importedResourceName); } ConfigurationFile importedConfigurationFile = parseConfigurationFile( new NamedResource(importedResourceName, importedResource), parsedNames); if (importedConfigurationFile != null) { importedConfigurationFiles.add(importedConfigurationFile); } } return null; } return e; } }); } catch (Exception e) { rootElement = new Element("read-error").setText(getStackTrace(getRootCause(e))); } return new ConfigurationFile(namedResource.name, url, importedConfigurationFiles.toArray(new ConfigurationFile[importedConfigurationFiles.size()]), rootElement); }
From source file:com.bluexml.side.Framework.alfresco.dataGenerator.serialization.mapping.XMLForACPMappingHelper.java
License:Open Source License
/** * create the dom4j qualified name of given generated node * @param node/*from ww w. ja v a2s. co m*/ * @return the dom4j qualified name of given generated node */ public QName createType(INode node) { String qualifiedName = services.getQualifiedName(node); String name = services.getName(qualifiedName); String prefix = services.getPrefix(qualifiedName); String uri = services.getSIDEUri(node); Namespace namespace = new Namespace(prefix, uri); return new QName(name, namespace, qualifiedName); }
From source file:com.cladonia.xngreditor.actions.ToolsAddNodeAction.java
License:Open Source License
/** * add one of various types of node to the xpath - selected nodes * //from w ww . ja v a 2 s . c o m * @param document * @param xpathPredicate * @param nodeType * @param namespace * @param name * @param value * @return */ public String addNode(ExchangerDocument document, String xpathPredicate, String nodeType, String namespace, String prefix, String name, String value) throws Exception { Vector nodeList = document.search(xpathPredicate); Vector attributeList = new Vector(); String warning = ""; if (nodeList.size() > 0) { try { for (int cnt = 0; cnt < nodeList.size(); ++cnt) { Node node = (Node) nodeList.get(cnt); if (node instanceof Element) { XElement e = (XElement) node; if (nodeType.equalsIgnoreCase("Element Node")) { QName qname = null; //resolve the namespace string if (!namespace.equalsIgnoreCase("none")) { Namespace newNs; try { newNs = new Namespace(prefix, namespace); qname = new QName(name, newNs); } catch (StringIndexOutOfBoundsException e1) { //cannot parse string MessageHandler.showError(parent, "Could not resolve Namespace:\n" + namespace, "Tools Add Node"); qname = new QName(name); } } else { qname = new QName(name); } XElement newNode = new XElement(qname); e.add(newNode); newNode.setValue(value); } else if (nodeType.equalsIgnoreCase("Attribute Node")) { QName qname = null; //resolve the namespace string if (!namespace.equalsIgnoreCase("none")) { Namespace newNs; try { newNs = new Namespace(namespace.substring(0, namespace.indexOf(":")), namespace.substring(namespace.indexOf(":") + 1, namespace.length())); qname = new QName(name, newNs); } catch (StringIndexOutOfBoundsException e1) { //cannot parse string MessageHandler.showError(parent, "Could not resolve Namespace:\n" + namespace, "Tools Add Node"); qname = new QName(name); } } else { qname = new QName(name); } XAttribute newNode = new XAttribute(qname, value); e.add(newNode); } else if (nodeType.equalsIgnoreCase("Text Node")) { FlyweightText newNode = new FlyweightText(value); e.add(newNode); } else if (nodeType.equalsIgnoreCase("CDATA Section Node")) { FlyweightCDATA newNode = new FlyweightCDATA(value); e.add(newNode); } else if (nodeType.equalsIgnoreCase("Processing Instruction Node")) { FlyweightProcessingInstruction newNode = new FlyweightProcessingInstruction(name, value); e.add(newNode); } else if (nodeType.equalsIgnoreCase("Comment Node")) { FlyweightComment newNode = new FlyweightComment(value); e.add(newNode); } } else if (node instanceof Document) { XDocument d = (XDocument) node; if (nodeType.equalsIgnoreCase("Processing Instruction Node")) { FlyweightProcessingInstruction newNode = new FlyweightProcessingInstruction(name, value); d.add(newNode); } else if (nodeType.equalsIgnoreCase("Comment Node")) { FlyweightComment newNode = new FlyweightComment(value); d.add(newNode); } else { //cant handle any others // can only handle elements MessageHandler.showError(parent, "Cannot add nodes to this xpath\n+" + "XPath: " + xpathPredicate + "refers to a" + node.getNodeTypeName(), "Tools Add Node"); //end for loop cnt = nodeList.size(); return (null); } } else { //can only handle elements MessageHandler.showError(parent, "Cannot add nodes to this xpath\n+" + "XPath: " + xpathPredicate + "refers to a" + node.getNodeTypeName(), "Tools Add Node"); //end for loop cnt = nodeList.size(); return (null); } } } catch (NullPointerException e) { MessageHandler.showError(parent, "XPath: " + xpathPredicate + "\nCannot be resolved", "Tools Add Node"); return (null); } catch (Exception e) { MessageHandler.showError(parent, "Error Adding Node", "Tools Add Node"); return (null); } document.update(); } else { MessageHandler.showError(parent, "No nodes could be found for:\n" + xpathPredicate, "Tools Add Node"); return (null); } return (document.getText()); }
From source file:com.cladonia.xngreditor.actions.ToolsAddNodeToNamespaceAction.java
License:Open Source License
/** * The implementation of the validate action, called * after a user action./*from w w w. jav a2 s . c o m*/ * * @param event the action event. */ public void actionPerformed(ActionEvent event) { if (dialog == null) { dialog = new ToolsAddNodeToNamespaceDialog(parent, props); } //called to make sure that the model is up to date to //prevent any problems found when undo-ing etc. parent.getView().updateModel(); //get the document final ExchangerDocument document = parent.getDocument(); if (document.isError()) { MessageHandler.showError(parent, "Please make sure the document is well-formed.", "Parser Error"); return; } String currentXPath = null; Node node = (Node) document.getLastNode(parent.getView().getEditor().getCursorPosition(), true); if (props.isUniqueXPath()) { currentXPath = node.getUniquePath(); } else { currentXPath = node.getPath(); } //create temporary document dialog.show(document.getDeclaredNamespaces(), currentXPath); if (!dialog.isCancelled()) { parent.setWait(true); parent.setStatus("Adding Nodes To Namespace ..."); // Run in Thread!!! Runnable runner = new Runnable() { public void run() { try { ExchangerDocument tempDoc = new ExchangerDocument(document.getText()); String uri = (String) dialog.nsURICombo.getSelectedItem(); String prefix = dialog.nsPrefixTextField.getText(); if (uri.equalsIgnoreCase("none")) { uri = ""; } if (prefix.equalsIgnoreCase("none")) { prefix = ""; } Namespace ns = new Namespace(prefix, uri); String newString = ToolsAddNodeToNamespaceAction.this.addNamespaceToNode(tempDoc, dialog.xpathPanel.getXpathPredicate(), ns); if (newString != null) { //need to parse the new document to make sure that it //will produce well-formed xml. ExchangerDocument newDocument = new ExchangerDocument(newString); boolean createDocument = true; if (newDocument.isError()) { int questionResult = MessageHandler.showConfirm(parent, "The resulting document will not be well-formed\n" + "Do you wish to continue?"); if (questionResult == MessageHandler.CONFIRM_NO_OPTION) { createDocument = false; } } if (createDocument) { if (dialog.toNewDocumentRadio.isSelected()) { //user has selected to create the result as a new document parent.open(newDocument, null); } else { parent.getView().getEditor().setText(newString); SwingUtilities.invokeLater(new Runnable() { public void run() { parent.switchToEditor(); parent.getView().updateModel(); } }); } } } } catch (Exception e) { // This should never happen, just report and continue MessageHandler.showError(parent, "Cannot Add Nodes To Namespace", "Tools Add Nodes To Namespace Error"); } finally { parent.setStatus("Done"); parent.setWait(false); } } }; // Create and start the thread ... Thread thread = new Thread(runner); thread.start(); // } } }
From source file:com.collabnet.ccf.core.ga.GenericArtifactHelper.java
License:Open Source License
/** * Creates a generic artifact XML representation out of the Java object * // w w w . j a v a2 s .co m * @param genericArtifact * Java object that will be represented as XML document * @return XML representation of generic artifact */ public static Document createGenericArtifactXMLDocument(GenericArtifact genericArtifact) throws GenericArtifactParsingException { Document document = DocumentHelper.createDocument(); document.setXMLEncoding(EncodingAwareObject.UTF_8); // Create XML elements with attributes Element root = addRootElement(document, ARTIFACT_ROOT_ELEMENT_NAME, CCF_ARTIFACT_NAMESPACE); switch (genericArtifact.getArtifactAction()) { case CREATE: { addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_CREATE); break; } case DELETE: { addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_DELETE); break; } case IGNORE: { addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_IGNORE); break; } case UPDATE: { addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_UPDATE); break; } case RESYNC: { addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_RESYNC); break; } case UNKNOWN: { addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_UNKNOWN); break; } default: { throw new GenericArtifactParsingException( "Non valid value for root-attribute " + ARTIFACT_ACTION + " specified."); } } switch (genericArtifact.getArtifactMode()) { case CHANGEDFIELDSONLY: { addAttribute(root, ARTIFACT_MODE, ARTIFACT_MODE_CHANGED_FIELDS_ONLY); break; } case COMPLETE: { addAttribute(root, ARTIFACT_MODE, ARTIFACT_MODE_COMPLETE); break; } case UNKNOWN: { addAttribute(root, ARTIFACT_MODE, ARTIFACT_MODE_UNKNOWN); break; } default: { throw new GenericArtifactParsingException( "Non valid value for root-attribute " + ARTIFACT_MODE + "specified."); } } ArtifactTypeValue artifactType = genericArtifact.getArtifactType(); switch (artifactType) { case ATTACHMENT: { addAttribute(root, ARTIFACT_TYPE, ARTIFACT_TYPE_ATTACHMENT); String content = genericArtifact.getArtifactValue(); // TODO BASE64 validation? if (content != null) // embed content in CDATA section setValue(root, content, true); break; } case DEPENDENCY: { addAttribute(root, ARTIFACT_TYPE, ARTIFACT_TYPE_DEPENDENCY); break; } case PLAINARTIFACT: { addAttribute(root, ARTIFACT_TYPE, ARTIFACT_TYPE_PLAIN_ARTIFACT); break; } case UNKNOWN: { addAttribute(root, ARTIFACT_TYPE, ARTIFACT_TYPE_UNKNOWN); break; } default: { throw new GenericArtifactParsingException( "Non valid value for root-attribute " + ARTIFACT_TYPE + " specified."); } } switch (genericArtifact.getIncludesFieldMetaData()) { case TRUE: { addAttribute(root, INCLUDES_FIELD_META_DATA, INCLUDES_FIELD_META_DATA_TRUE); break; } case FALSE: { addAttribute(root, INCLUDES_FIELD_META_DATA, INCLUDES_FIELD_META_DATA_FALSE); break; } default: { throw new GenericArtifactParsingException( "Non valid value for root-attribute " + ARTIFACT_MODE + "specified."); } } addAttribute(root, SOURCE_ARTIFACT_LAST_MODIFICATION_DATE, genericArtifact.getSourceArtifactLastModifiedDate()); addAttribute(root, TARGET_ARTIFACT_LAST_MODIFICATION_DATE, genericArtifact.getTargetArtifactLastModifiedDate()); // addAttribute(root, ARTIFACT_LAST_READ_TRANSACTION_ID, genericArtifact // .getLastReadTransactionId()); addAttribute(root, ERROR_CODE, genericArtifact.getErrorCode()); addAttribute(root, SOURCE_ARTIFACT_VERSION, genericArtifact.getSourceArtifactVersion()); addAttribute(root, TARGET_ARTIFACT_VERSION, genericArtifact.getTargetArtifactVersion()); addAttribute(root, CONFLICT_RESOLUTION_PRIORITY, genericArtifact.getConflictResolutionPriority()); // only create optional attributes if necessary if (artifactType == ArtifactTypeValue.DEPENDENCY || artifactType == ArtifactTypeValue.ATTACHMENT || artifactType == ArtifactTypeValue.PLAINARTIFACT) { addAttribute(root, DEP_PARENT_SOURCE_ARTIFACT_ID, genericArtifact.getDepParentSourceArtifactId()); addAttribute(root, DEP_PARENT_SOURCE_REPOSITORY_ID, genericArtifact.getDepParentSourceRepositoryId()); addAttribute(root, DEP_PARENT_SOURCE_REPOSITORY_KIND, genericArtifact.getDepParentSourceRepositoryKind()); addAttribute(root, DEP_PARENT_TARGET_ARTIFACT_ID, genericArtifact.getDepParentTargetArtifactId()); addAttribute(root, DEP_PARENT_TARGET_REPOSITORY_ID, genericArtifact.getDepParentTargetRepositoryId()); addAttribute(root, DEP_PARENT_TARGET_REPOSITORY_KIND, genericArtifact.getDepParentTargetRepositoryKind()); } // dependencies have even more optional attributes if (artifactType == ArtifactTypeValue.DEPENDENCY) { addAttribute(root, DEP_CHILD_SOURCE_ARTIFACT_ID, genericArtifact.getDepChildSourceArtifactId()); addAttribute(root, DEP_CHILD_SOURCE_REPOSITORY_ID, genericArtifact.getDepChildSourceRepositoryId()); addAttribute(root, DEP_CHILD_SOURCE_REPOSITORY_KIND, genericArtifact.getDepChildSourceRepositoryKind()); addAttribute(root, DEP_CHILD_TARGET_ARTIFACT_ID, genericArtifact.getDepChildTargetArtifactId()); addAttribute(root, DEP_CHILD_TARGET_REPOSITORY_ID, genericArtifact.getDepChildTargetRepositoryId()); addAttribute(root, DEP_CHILD_TARGET_REPOSITORY_KIND, genericArtifact.getDepChildTargetRepositoryKind()); } addAttribute(root, SOURCE_ARTIFACT_ID, genericArtifact.getSourceArtifactId()); addAttribute(root, SOURCE_REPOSITORY_ID, genericArtifact.getSourceRepositoryId()); addAttribute(root, SOURCE_REPOSITORY_KIND, genericArtifact.getSourceRepositoryKind()); addAttribute(root, SOURCE_SYSTEM_ID, genericArtifact.getSourceSystemId()); addAttribute(root, SOURCE_SYSTEM_KIND, genericArtifact.getSourceSystemKind()); addAttribute(root, TARGET_ARTIFACT_ID, genericArtifact.getTargetArtifactId()); addAttribute(root, TARGET_REPOSITORY_ID, genericArtifact.getTargetRepositoryId()); addAttribute(root, TARGET_REPOSITORY_KIND, genericArtifact.getTargetRepositoryKind()); addAttribute(root, TARGET_SYSTEM_ID, genericArtifact.getTargetSystemId()); addAttribute(root, TARGET_SYSTEM_KIND, genericArtifact.getTargetSystemKind()); addAttribute(root, SOURCE_SYSTEM_TIMEZONE, genericArtifact.getSourceSystemTimezone()); addAttribute(root, TARGET_SYSTEM_TIMEZONE, genericArtifact.getTargetSystemTimezone()); // addAttribute(root, SOURCE_SYSTEM_ENCODING, genericArtifact // .getSourceSystemEncoding()); // addAttribute(root, TARGET_SYSTEM_ENCODING, genericArtifact // .getTargetSystemEncoding()); addAttribute(root, TRANSACTION_ID, genericArtifact.getTransactionId()); if (genericArtifact.getAllGenericArtifactFields() != null) { // now add fields for (GenericArtifactField genericArtifactField : genericArtifact.getAllGenericArtifactFields()) { Element field = addElement(root, ARTIFACT_FIELD_ELEMENT_NAME, CCF_ARTIFACT_NAMESPACE); switch (genericArtifactField.getFieldAction()) { case APPEND: { addAttribute(field, FIELD_ACTION, FIELD_ACTION_APPEND); break; } case DELETE: { addAttribute(field, FIELD_ACTION, FIELD_ACTION_DELETE); break; } case REPLACE: { addAttribute(field, FIELD_ACTION, FIELD_ACTION_REPLACE); break; } case UNKNOWN: { addAttribute(field, FIELD_ACTION, FIELD_ACTION_UNKNOWN); break; } default: { throw new GenericArtifactParsingException( "Non valid value for field-attribute " + FIELD_ACTION + " specified."); } } addAttribute(field, FIELD_NAME, genericArtifactField.getFieldName()); addAttribute(field, FIELD_TYPE, genericArtifactField.getFieldType()); if (genericArtifactField.getFieldValueHasChanged()) { addAttribute(field, FIELD_VALUE_HAS_CHANGED, FIELD_VALUE_HAS_CHANGED_TRUE); } else { addAttribute(field, FIELD_VALUE_HAS_CHANGED, FIELD_VALUE_HAS_CHANGED_FALSE); } if (genericArtifact.getIncludesFieldMetaData() .equals(GenericArtifact.IncludesFieldMetaDataValue.TRUE)) { addAttribute(field, MIN_OCCURS, genericArtifactField.getMinOccursValue()); addAttribute(field, MAX_OCCURS, genericArtifactField.getMaxOccursValue()); addAttribute(field, NULL_VALUE_SUPPORTED, genericArtifactField.getNullValueSupported()); } else if (!GenericArtifactField.VALUE_UNKNOWN .equals(genericArtifactField.getAlternativeFieldName()) && genericArtifactField.getAlternativeFieldName() != null) { // if the alternative field name field has been set, we will ship it even if the other meta data has not been populated addAttribute(field, ALTERNATIVE_FIELD_NAME, genericArtifactField.getAlternativeFieldName()); } setFieldValue(field, genericArtifactField.getFieldValue(), genericArtifactField.getFieldValueType()); } } root.addAttribute( new QName(SCHEMA_LOCATION_ATTRIBUTE, new Namespace(SCHEMA_NAMESPACE_PREFIX, SCHEMA_NAMESPACE)), CCF_SCHEMA_LOCATION); return document; }
From source file:com.collabnet.ccf.core.GenericArtifactHelper.java
License:Apache License
/** * Creates a generic artifact XML representation out of the Java object * // w w w .j a v a 2s . co m * @param genericArtifact * Java object that will be represented as XML document * @return XML representation of generic artifact */ public static Document createGenericArtifactXMLDocument(GenericArtifact genericArtifact) throws GenericArtifactParsingException { Document document = DocumentHelper.createDocument(); document.setXMLEncoding("UTF-8"); // Create XML elements with attributes Element root = addRootElement(document, ARTIFACT_ROOT_ELEMENT_NAME, CCF_ARTIFACT_NAMESPACE); switch (genericArtifact.getArtifactAction()) { case CREATE: { addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_CREATE); break; } case DELETE: { addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_DELETE); break; } case IGNORE: { addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_IGNORE); break; } case UPDATE: { addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_UPDATE); break; } case RESYNC: { addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_RESYNC); break; } case UNKNOWN: { addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_UNKNOWN); break; } default: { throw new GenericArtifactParsingException( "Non valid value for root-attribute " + ARTIFACT_ACTION + " specified."); } } switch (genericArtifact.getArtifactMode()) { case CHANGEDFIELDSONLY: { addAttribute(root, ARTIFACT_MODE, ARTIFACT_MODE_CHANGED_FIELDS_ONLY); break; } case COMPLETE: { addAttribute(root, ARTIFACT_MODE, ARTIFACT_MODE_COMPLETE); break; } case UNKNOWN: { addAttribute(root, ARTIFACT_MODE, ARTIFACT_MODE_UNKNOWN); break; } default: { throw new GenericArtifactParsingException( "Non valid value for root-attribute " + ARTIFACT_MODE + "specified."); } } ArtifactTypeValue artifactType = genericArtifact.getArtifactType(); switch (artifactType) { case ATTACHMENT: { addAttribute(root, ARTIFACT_TYPE, ARTIFACT_TYPE_ATTACHMENT); String content = genericArtifact.getArtifactValue(); // TODO BASE64 validation? if (content != null) // embed content in CDATA section setValue(root, content, true); break; } case DEPENDENCY: { addAttribute(root, ARTIFACT_TYPE, ARTIFACT_TYPE_DEPENDENCY); break; } case PLAINARTIFACT: { addAttribute(root, ARTIFACT_TYPE, ARTIFACT_TYPE_PLAIN_ARTIFACT); break; } case UNKNOWN: { addAttribute(root, ARTIFACT_TYPE, ARTIFACT_TYPE_UNKNOWN); break; } default: { throw new GenericArtifactParsingException( "Non valid value for root-attribute " + ARTIFACT_TYPE + " specified."); } } switch (genericArtifact.getIncludesFieldMetaData()) { case TRUE: { addAttribute(root, INCLUDES_FIELD_META_DATA, INCLUDES_FIELD_META_DATA_TRUE); break; } case FALSE: { addAttribute(root, INCLUDES_FIELD_META_DATA, INCLUDES_FIELD_META_DATA_FALSE); break; } default: { throw new GenericArtifactParsingException( "Non valid value for root-attribute " + ARTIFACT_MODE + "specified."); } } addAttribute(root, SOURCE_ARTIFACT_LAST_MODIFICATION_DATE, genericArtifact.getSourceArtifactLastModifiedDate()); addAttribute(root, TARGET_ARTIFACT_LAST_MODIFICATION_DATE, genericArtifact.getTargetArtifactLastModifiedDate()); // addAttribute(root, ARTIFACT_LAST_READ_TRANSACTION_ID, genericArtifact // .getLastReadTransactionId()); addAttribute(root, ERROR_CODE, genericArtifact.getErrorCode()); addAttribute(root, SOURCE_ARTIFACT_VERSION, genericArtifact.getSourceArtifactVersion()); addAttribute(root, TARGET_ARTIFACT_VERSION, genericArtifact.getTargetArtifactVersion()); addAttribute(root, CONFLICT_RESOLUTION_PRIORITY, genericArtifact.getConflictResolutionPriority()); // only create optional attributes if necessary if (artifactType == ArtifactTypeValue.DEPENDENCY || artifactType == ArtifactTypeValue.ATTACHMENT) { addAttribute(root, DEP_PARENT_SOURCE_ARTIFACT_ID, genericArtifact.getDepParentSourceArtifactId()); addAttribute(root, DEP_PARENT_SOURCE_REPOSITORY_ID, genericArtifact.getDepParentSourceRepositoryId()); addAttribute(root, DEP_PARENT_SOURCE_REPOSITORY_KIND, genericArtifact.getDepParentSourceRepositoryKind()); addAttribute(root, DEP_PARENT_TARGET_ARTIFACT_ID, genericArtifact.getDepParentTargetArtifactId()); addAttribute(root, DEP_PARENT_TARGET_REPOSITORY_ID, genericArtifact.getDepParentTargetRepositoryId()); addAttribute(root, DEP_PARENT_TARGET_REPOSITORY_KIND, genericArtifact.getDepParentTargetRepositoryKind()); } // dependencies have even more optional attributes if (artifactType == ArtifactTypeValue.DEPENDENCY) { addAttribute(root, DEP_CHILD_SOURCE_ARTIFACT_ID, genericArtifact.getDepChildSourceArtifactId()); addAttribute(root, DEP_CHILD_SOURCE_REPOSITORY_ID, genericArtifact.getDepChildSourceRepositoryId()); addAttribute(root, DEP_CHILD_SOURCE_REPOSITORY_KIND, genericArtifact.getDepChildSourceRepositoryKind()); addAttribute(root, DEP_CHILD_TARGET_ARTIFACT_ID, genericArtifact.getDepChildTargetArtifactId()); addAttribute(root, DEP_CHILD_TARGET_REPOSITORY_ID, genericArtifact.getDepChildTargetRepositoryId()); addAttribute(root, DEP_CHILD_TARGET_REPOSITORY_KIND, genericArtifact.getDepChildTargetRepositoryKind()); } addAttribute(root, SOURCE_ARTIFACT_ID, genericArtifact.getSourceArtifactId()); addAttribute(root, SOURCE_REPOSITORY_ID, genericArtifact.getSourceRepositoryId()); addAttribute(root, SOURCE_REPOSITORY_KIND, genericArtifact.getSourceRepositoryKind()); addAttribute(root, SOURCE_SYSTEM_ID, genericArtifact.getSourceSystemId()); addAttribute(root, SOURCE_SYSTEM_KIND, genericArtifact.getSourceSystemKind()); addAttribute(root, TARGET_ARTIFACT_ID, genericArtifact.getTargetArtifactId()); addAttribute(root, TARGET_REPOSITORY_ID, genericArtifact.getTargetRepositoryId()); addAttribute(root, TARGET_REPOSITORY_KIND, genericArtifact.getTargetRepositoryKind()); addAttribute(root, TARGET_SYSTEM_ID, genericArtifact.getTargetSystemId()); addAttribute(root, TARGET_SYSTEM_KIND, genericArtifact.getTargetSystemKind()); addAttribute(root, SOURCE_SYSTEM_TIMEZONE, genericArtifact.getSourceSystemTimezone()); addAttribute(root, TARGET_SYSTEM_TIMEZONE, genericArtifact.getTargetSystemTimezone()); // addAttribute(root, SOURCE_SYSTEM_ENCODING, genericArtifact // .getSourceSystemEncoding()); // addAttribute(root, TARGET_SYSTEM_ENCODING, genericArtifact // .getTargetSystemEncoding()); addAttribute(root, TRANSACTION_ID, genericArtifact.getTransactionId()); if (genericArtifact.getAllGenericArtifactFields() != null) { // now add fields for (GenericArtifactField genericArtifactField : genericArtifact.getAllGenericArtifactFields()) { Element field = addElement(root, ARTIFACT_FIELD_ELEMENT_NAME, CCF_ARTIFACT_NAMESPACE); switch (genericArtifactField.getFieldAction()) { case APPEND: { addAttribute(field, FIELD_ACTION, FIELD_ACTION_APPEND); break; } case DELETE: { addAttribute(field, FIELD_ACTION, FIELD_ACTION_DELETE); break; } case REPLACE: { addAttribute(field, FIELD_ACTION, FIELD_ACTION_REPLACE); break; } case UNKNOWN: { addAttribute(field, FIELD_ACTION, FIELD_ACTION_UNKNOWN); break; } default: { throw new GenericArtifactParsingException( "Non valid value for field-attribute " + FIELD_ACTION + " specified."); } } addAttribute(field, FIELD_NAME, genericArtifactField.getFieldName()); addAttribute(field, FIELD_TYPE, genericArtifactField.getFieldType()); if (genericArtifactField.getFieldValueHasChanged()) { addAttribute(field, FIELD_VALUE_HAS_CHANGED, FIELD_VALUE_HAS_CHANGED_TRUE); } else { addAttribute(field, FIELD_VALUE_HAS_CHANGED, FIELD_VALUE_HAS_CHANGED_FALSE); } if (genericArtifact.getIncludesFieldMetaData() .equals(GenericArtifact.IncludesFieldMetaDataValue.TRUE)) { addAttribute(field, MIN_OCCURS, genericArtifactField.getMinOccursValue()); addAttribute(field, MAX_OCCURS, genericArtifactField.getMaxOccursValue()); addAttribute(field, NULL_VALUE_SUPPORTED, genericArtifactField.getNullValueSupported()); addAttribute(field, ALTERNATIVE_FIELD_NAME, genericArtifactField.getAlternativeFieldName()); } setFieldValue(field, genericArtifactField.getFieldValue(), genericArtifactField.getFieldValueType()); } } root.addAttribute( new QName(SCHEMA_LOCATION_ATTRIBUTE, new Namespace(SCHEMA_NAMESPACE_PREFIX, SCHEMA_NAMESPACE)), CCF_SCHEMA_LOCATION); return document; }
From source file:com.haulmont.cuba.core.sys.persistence.MappingFileCreator.java
License:Apache License
private Document createDocument(Map<Class<?>, List<Attr>> mappings) { Document doc = DocumentHelper.createDocument(); Element rootEl = doc.addElement("entity-mappings", XMLNS); Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); rootEl.add(xsi);/*from w w w.j a va2s . co m*/ rootEl.addAttribute(new QName("schemaLocation", xsi), SCHEMA_LOCATION); rootEl.addAttribute("version", PERSISTENCE_VER); for (Map.Entry<Class<?>, List<Attr>> entry : mappings.entrySet()) { if (entry.getKey().getAnnotation(MappedSuperclass.class) != null) { Element entityEl = rootEl.addElement("mapped-superclass", XMLNS); entityEl.addAttribute("class", entry.getKey().getName()); createAttributes(entry, entityEl); } } for (Map.Entry<Class<?>, List<Attr>> entry : mappings.entrySet()) { if (entry.getKey().getAnnotation(Entity.class) != null) { Element entityEl = rootEl.addElement("entity", XMLNS); entityEl.addAttribute("class", entry.getKey().getName()); entityEl.addAttribute("name", entry.getKey().getAnnotation(Entity.class).name()); createAttributes(entry, entityEl); } } for (Map.Entry<Class<?>, List<Attr>> entry : mappings.entrySet()) { if (entry.getKey().getAnnotation(Embeddable.class) != null) { Element entityEl = rootEl.addElement("embeddable", XMLNS); entityEl.addAttribute("class", entry.getKey().getName()); createAttributes(entry, entityEl); } } return doc; }
From source file:com.ostrichemulators.semtool.poi.main.LowMemXlsReader.java
/** * Gets sheet name-to-id mapping//from w ww .j a v a 2 s. c om * * @param r * @return */ private LinkedHashMap<String, String> readSheetInfo(XSSFReader r) { LinkedHashMap<String, String> map = new LinkedHashMap<>(); try (InputStream is = r.getWorkbookData()) { SAXReader sax = new SAXReader(); Document doc = sax.read(is); Namespace ns = new Namespace("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"); Element sheets = doc.getRootElement().element("sheets"); for (Object sheet : sheets.elements("sheet")) { Element e = Element.class.cast(sheet); String name = e.attributeValue("name"); String id = e.attributeValue(new QName("id", ns)); map.put(name, id); } } catch (Exception e) { log.error(e, e); } return map; }
From source file:com.stratumsoft.xmlgen.SchemaTypeXmlGenerator.java
License:Open Source License
private org.dom4j.QName createDom4jQName(QName qname, XmlSchemaForm form) { org.dom4j.QName dom4jQname = null; if (qname != null) { String nsUri = qname.getNamespaceURI(); Namespace ns = null;/*from w w w. ja v a 2s . co m*/ if (StringUtils.isNotEmpty(nsUri)) { if (form == XmlSchemaForm.QUALIFIED) { String prefix = nsMap.getPrefix(nsUri); if (StringUtils.isEmpty(prefix)) { prefix = DEFAULT_PREFIX + prefixCounter++; nsMap.add(prefix, nsUri); } ns = new Namespace(prefix, nsUri); } } dom4jQname = new org.dom4j.QName(qname.getLocalPart(), ns); } return dom4jQname; }
From source file:com.uletian.ultcrm.business.service.CustomerInfoSyncService.java
public void notifycationDataChange(Customer customer) { StringWriter writer = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); Document doc = DocumentHelper.createDocument(); Namespace namespace = new Namespace("ns0", "http://crm/91jpfw.cn"); Element root = doc.addElement(new QName("customer", namespace)); root.addElement(new QName("action")).addText(action.BINDING_TEL.toString()); root.addElement(new QName("sourceSys")).addText("ULTCRM"); root.addElement(new QName("ultcrmid")).addText(customer.getId().toString()); root.addElement(new QName("crmid")).addText(customer.getSyncid() == null ? "" : customer.getSyncid()); String name = null;/*ww w .j a va 2 s. com*/ if (customer.getName() == null || "".equals(customer.getName())) { name = customer.getNickname(); } else { name = customer.getName(); } root.addElement(new QName("name")).addText(name); root.addElement(new QName("sexy")).addText(customer.getSex() == null ? "" : customer.getSex()); root.addElement(new QName("telephone")).addText(customer.getPhone() == null ? "" : customer.getPhone()); root.addElement(new QName("country")).addText(customer.getCountry() == null ? "" : customer.getCountry()); root.addElement(new QName("province")) .addText(customer.getProvince() == null ? "" : customer.getProvince()); root.addElement(new QName("city")).addText(customer.getCity() == null ? "" : customer.getCity()); root.addElement(new QName("address")).addText(customer.getAddress() == null ? "" : customer.getAddress()); root.addElement(new QName("postcode")) .addText(customer.getPostcode() == null ? "" : customer.getPostcode()); Element techsElement = root.addElement(new QName("techs")); List<Tech> techs = customer.getTechs(); if (techs != null && techs.size() > 0) { for (int i = 0; i < techs.size(); i++) { Tech tech = techs.get(i); Element techElement = techsElement.addElement("tech"); techElement.addElement(new QName("crmtechid")) .addText(tech.getCrmTechId() == null ? "" : tech.getCrmTechId()); techElement.addElement(new QName("code")).addText(tech.getTechModel().getCode()); techElement.addElement(new QName("techlevelno")) .addText(tech.getTechlevelno() == null ? "" : tech.getTechlevelno()); techElement.addElement(new QName("techerno")) .addText(tech.getTecherno() == null ? "" : tech.getTecherno()); techElement.addElement(new QName("techname")) .addText(tech.getTechname() == null ? "" : tech.getTechname()); techElement.addElement(new QName("coursetime")) .addText(tech.getCoursetime() == null ? "" : tech.getCoursetime()); String trainExpireDate = ""; if (tech.getTrainExpireDate() != null) { trainExpireDate = sdf.format(tech.getTrainExpireDate()); } techElement.addElement(new QName("trainExpireDate")).addText(trainExpireDate); techElement.addElement(new QName("trainCompany")) .addText(tech.getTrainCompany() == null ? "" : tech.getTrainCompany()); techElement.addElement(new QName("courseCode")) .addText(tech.getCourseCode() == null ? "" : tech.getCourseCode()); techElement.addElement(new QName("techColor")) .addText(tech.getColor() == null ? "" : tech.getColor()); String registerDate = ""; if (tech.getRegisterDate() != null) { registerDate = sdf.format(tech.getRegisterDate()); } techElement.addElement(new QName("registerDate")).addText(registerDate); techElement.addElement(new QName("courseLicense")) .addText(tech.getCourseLicense() == null ? "" : tech.getCourseLicense()); String checkExpireDate = ""; if (tech.getCheckExpireDate() != null) { checkExpireDate = sdf.format(tech.getCheckExpireDate()); } techElement.addElement(new QName("checkExpireDate")).addText(checkExpireDate); techElement.addElement(new QName("memberLevel")) .addText(tech.getMemberLevel() == null ? "" : tech.getMemberLevel()); // ? by xiecheng 2015-11-19 techElement.addElement(new QName("nextMaintCoursetime")) .addText(StringUtils.isNoneBlank(tech.getNextMaintCoursetime()) ? tech.getNextMaintCoursetime() : ""); String nextMaintDate = ""; if (tech.getNextMaintDate() != null) { nextMaintDate = sdf.format(tech.getNextMaintDate()); } techElement.addElement(new QName("nextMaintDate")).addText(nextMaintDate); String lastConsumeDate = ""; if (tech.getLastConsumeDate() != null) { lastConsumeDate = sdf.format(tech.getLastConsumeDate()); } techElement.addElement(new QName("lastConsumeDate")).addText(lastConsumeDate); } } XMLWriter xmlwriter = new XMLWriter(writer, format); try { xmlwriter.write(doc); } catch (IOException e) { } customerInfoMessageService.sendMessage(writer.toString()); }