List of usage examples for org.w3c.dom Element cloneNode
public Node cloneNode(boolean deep);
From source file:org.asimba.idp.profile.catalog.saml2.SAML2Catalog.java
/** * Private helper to clone XMLObjects//from w w w .j a va2s .c om * @param oSource * @return * @throws OAException */ private <T extends XMLObject> T cloneXMLObject(XMLObject oSource) throws MarshallingException, UnmarshallingException { Marshaller oMarshaller = Configuration.getMarshallerFactory().getMarshaller(oSource); try { if (oMarshaller == null) { _oLogger.warn("Unknown element '" + oSource.getElementQName() + "'; no marshaller available"); return null; } // go through process of creating a new Document as intermediate: DocumentBuilderFactory oDBFactory = DocumentBuilderFactory.newInstance(); oDBFactory.setNamespaceAware(true); DocumentBuilder oDocBuilder = oDBFactory.newDocumentBuilder(); DOMImplementation oDOMImpl = oDocBuilder.getDOMImplementation(); Document oDocument = oDOMImpl.createDocument(null, null, null); Element elSource = oSource.getDOM(); // Element elSource = oMarshaller.marshall(oSource, oDocument); // is this right: .getDOM() ?? Element clonedElement = (Element) elSource.cloneNode(true); // deep clone Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(clonedElement); T clonedXMLObject = (T) unmarshaller.unmarshall(clonedElement); return clonedXMLObject; // } catch (MarshallingException e) { // _oLogger.warn("Could not marshall element '"+oSource.getElementQName()+"'"); // return null; } catch (UnmarshallingException e) { _oLogger.warn("Could not unmarshall element '" + oSource.getElementQName() + "'"); return null; } catch (ParserConfigurationException e) { _oLogger.warn("Exception when creating intermedia document for cloning: " + e.getMessage()); return null; } }
From source file:org.chiba.tools.schemabuilder.AbstractSchemaFormBuilder.java
private void addAttributeSet(Document xForm, Element modelSection, Element formSection, XSComplexTypeDefinition controlType, XSElementDeclaration owner, String pathToRoot, boolean checkIfExtension) { XSObjectList attrUses = controlType.getAttributeUses(); if (attrUses != null) { int nbAttr = attrUses.getLength(); for (int i = 0; i < nbAttr; i++) { XSAttributeUse currentAttributeUse = (XSAttributeUse) attrUses.item(i); XSAttributeDeclaration currentAttribute = currentAttributeUse.getAttrDeclaration(); //test if extended ! if (checkIfExtension && this.doesAttributeComeFromExtension(currentAttributeUse, controlType)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(// ww w .ja v a 2s .c o m "This attribute comes from an extension: recopy form controls. \n Model section: "); DOMUtil.prettyPrintDOM(modelSection); } String attributeName = currentAttributeUse.getName(); if (attributeName == null || attributeName.equals("")) attributeName = currentAttributeUse.getAttrDeclaration().getName(); //find the existing bind Id //(modelSection is the enclosing bind of the element) NodeList binds = modelSection.getElementsByTagNameNS(XFORMS_NS, "bind"); int j = 0; int nb = binds.getLength(); String bindId = null; while (j < nb && bindId == null) { Element bind = (Element) binds.item(j); String nodeset = bind.getAttributeNS(XFORMS_NS, "nodeset"); if (nodeset != null) { String name = nodeset.substring(1); //remove "@" in nodeset if (name.equals(attributeName)) bindId = bind.getAttributeNS(XFORMS_NS, "id"); } j++; } //find the control Element control = null; if (bindId != null) { if (LOGGER.isDebugEnabled()) LOGGER.debug("bindId found: " + bindId); JXPathContext context = JXPathContext.newContext(formSection.getOwnerDocument()); Pointer pointer = context .getPointer("//*[@" + this.getXFormsNSPrefix() + "bind='" + bindId + "']"); if (pointer != null) control = (Element) pointer.getNode(); } //copy it if (control == null) { LOGGER.warn("Corresponding control not found"); } else { Element newControl = (Element) control.cloneNode(true); //set new Ids to XForm elements this.resetXFormIds(newControl); formSection.appendChild(newControl); } } else { String newPathToRoot; if ((pathToRoot == null) || pathToRoot.equals("")) { newPathToRoot = "@" + currentAttribute.getName(); } else if (pathToRoot.endsWith("/")) { newPathToRoot = pathToRoot + "@" + currentAttribute.getName(); } else { newPathToRoot = pathToRoot + "/@" + currentAttribute.getName(); } XSSimpleTypeDefinition simpleType = currentAttribute.getTypeDefinition(); //TODO SRA: UrType ? /*if(simpleType==null){ simpleType=new UrType(); }*/ addSimpleType(xForm, modelSection, formSection, simpleType, currentAttributeUse, newPathToRoot); } } } }
From source file:org.chiba.tools.schemabuilder.AbstractSchemaFormBuilder.java
/** * checkIfExtension: if false, addElement is called wether it is an extension or not * if true, if it is an extension, element is recopied (and no additional bind) *//*from w w w . j a va2 s . c o m*/ private void addGroup(Document xForm, Element modelSection, Element formSection, XSModelGroup group, XSComplexTypeDefinition controlType, XSElementDeclaration owner, String pathToRoot, int minOccurs, int maxOccurs, boolean checkIfExtension) { if (group != null) { Element repeatSection = addRepeatIfNecessary(xForm, modelSection, formSection, owner.getTypeDefinition(), minOccurs, maxOccurs, pathToRoot); Element repeatContentWrapper = repeatSection; if (repeatSection != formSection) { //selector -> no more needed? //this.addSelector(xForm, repeatSection); //group wrapper repeatContentWrapper = _wrapper.createGroupContentWrapper(repeatSection); } if (LOGGER.isDebugEnabled()) LOGGER.debug( "addGroup from owner=" + owner.getName() + " and controlType=" + controlType.getName()); XSObjectList particles = group.getParticles(); for (int counter = 0; counter < particles.getLength(); counter++) { XSParticle currentNode = (XSParticle) particles.item(counter); XSTerm term = currentNode.getTerm(); if (LOGGER.isDebugEnabled()) LOGGER.debug(" : next term = " + term.getName()); int childMaxOccurs = currentNode.getMaxOccurs(); if (currentNode.getMaxOccursUnbounded()) childMaxOccurs = -1; int childMinOccurs = currentNode.getMinOccurs(); if (term instanceof XSModelGroup) { if (LOGGER.isDebugEnabled()) LOGGER.debug(" term is a group"); addGroup(xForm, modelSection, repeatContentWrapper, ((XSModelGroup) term), controlType, owner, pathToRoot, childMinOccurs, childMaxOccurs, checkIfExtension); } else if (term instanceof XSElementDeclaration) { XSElementDeclaration element = (XSElementDeclaration) term; if (LOGGER.isDebugEnabled()) LOGGER.debug(" term is an element declaration: " + term.getName()); //special case for types already added because used in an extension //do not add it when it comes from an extension !!! //-> make a copy from the existing form control if (checkIfExtension && this.doesElementComeFromExtension(element, controlType)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug( "This element comes from an extension: recopy form controls.\n Model Section="); DOMUtil.prettyPrintDOM(modelSection); } //find the existing bind Id //(modelSection is the enclosing bind of the element) NodeList binds = modelSection.getElementsByTagNameNS(XFORMS_NS, "bind"); int i = 0; int nb = binds.getLength(); String bindId = null; while (i < nb && bindId == null) { Element bind = (Element) binds.item(i); String nodeset = bind.getAttributeNS(XFORMS_NS, "nodeset"); if (nodeset != null && nodeset.equals(element.getName())) bindId = bind.getAttributeNS(XFORMS_NS, "id"); i++; } //find the control Element control = null; if (bindId != null) { if (LOGGER.isDebugEnabled()) LOGGER.debug("bindId found: " + bindId); JXPathContext context = JXPathContext.newContext(formSection.getOwnerDocument()); Pointer pointer = context .getPointer("//*[@" + this.getXFormsNSPrefix() + "bind='" + bindId + "']"); if (pointer != null) control = (Element) pointer.getNode(); } //copy it if (control == null) { LOGGER.warn("Corresponding control not found"); } else { Element newControl = (Element) control.cloneNode(true); //set new Ids to XForm elements this.resetXFormIds(newControl); repeatContentWrapper.appendChild(newControl); } } else { //add it normally String elementName = getElementName(element, xForm); String path = pathToRoot + "/" + elementName; if (pathToRoot.equals("")) { //relative path = elementName; } addElement(xForm, modelSection, repeatContentWrapper, element, element.getTypeDefinition(), path); } } else { //XSWildcard -> ignore ? //LOGGER.warn("XSWildcard found in group from "+owner.getName()+" for pathToRoot="+pathToRoot); } } if (LOGGER.isDebugEnabled()) LOGGER.debug("--- end of addGroup from owner=" + owner.getName()); } }
From source file:org.chiba.xml.xforms.Model.java
private XSModel loadSchema(Element element) throws TransformerException, IllegalAccessException, InstantiationException, ClassNotFoundException { Element copy = (Element) element.cloneNode(true); NamespaceCtx.applyNamespaces(element, copy); ByteArrayOutputStream stream = new ByteArrayOutputStream(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.transform(new DOMSource(copy), new StreamResult(stream)); byte[] array = stream.toByteArray(); return loadSchema(new ByteArrayInputStream(array)); }
From source file:org.dita.dost.module.BranchFilterModule.java
/** * Duplicate branches so that each {@code ditavalref} will in a separate branch. *//* w ww .j a v a 2 s .co m*/ void splitBranches(final Element elem, final Branch filter) { final List<Element> ditavalRefs = getChildElements(elem, DITAVAREF_D_DITAVALREF); if (ditavalRefs.size() > 0) { // remove ditavalrefs for (final Element branch : ditavalRefs) { elem.removeChild(branch); } // create additional branches after current element final List<Element> branches = new ArrayList<>(ditavalRefs.size()); branches.add(elem); final Node next = elem.getNextSibling(); for (int i = 1; i < ditavalRefs.size(); i++) { final Element clone = (Element) elem.cloneNode(true); if (next != null) { elem.getParentNode().insertBefore(clone, next); } else { elem.getParentNode().appendChild(clone); } branches.add(clone); } // insert ditavalrefs for (int i = 0; i < branches.size(); i++) { final Element branch = branches.get(i); final Element ditavalref = ditavalRefs.get(i); branch.appendChild(ditavalref); final Branch currentFilter = filter.merge(ditavalref); processAttributes(branch, currentFilter); final Branch childFilter = new Branch(currentFilter.resourcePrefix, currentFilter.resourceSuffix, Optional.empty(), Optional.empty()); // process children of all branches for (final Element child : getChildElements(branch, MAP_TOPICREF)) { if (DITAVAREF_D_DITAVALREF.matches(child)) { continue; } splitBranches(child, childFilter); } } } else { processAttributes(elem, filter); for (final Element child : getChildElements(elem, MAP_TOPICREF)) { splitBranches(child, filter); } } }
From source file:org.etudes.mneme.impl.ImportQti2ServiceImpl.java
/** * Build the question presentation text. Its important to remove inline feedback text and interaction text while creating this text. * /*from www . jav a 2 s .c o m*/ * @param contentsDOM * @param itemBodyElement * @param interaction * @return * @throws Exception */ private String processQuestionText(String context, Document contentsDOM, Element itemElement, List<String> embedMedia, String interaction, String unzipBackUpLocation) throws Exception { String text = ""; if (itemElement == null) return text; boolean fillBlanks = ("inlineChoiceInteraction".equalsIgnoreCase(interaction) || "textEntryInteraction".equalsIgnoreCase(interaction)) ? true : false; Element itemBodyElement = (Element) itemElement.cloneNode(true); List<Element> interactionElements = new ArrayList<Element>(); // embed images processEmbedMedia(itemBodyElement, unzipBackUpLocation, context, embedMedia); itemBodyElement = removeFeedback(itemBodyElement); if (interaction == null || "".equals(interaction)) return normalizeElementBody(contentsDOM, itemBodyElement); XPath interactionPath = new DOMXPath(".//" + interaction); interactionElements = interactionPath.selectNodes(itemBodyElement); if (interactionElements == null || interactionElements.size() == 0) return normalizeElementBody(contentsDOM, itemBodyElement); // add prompt or block quote inside interaction to question text for (Element i : interactionElements) { String additionalText = ""; XPath promptPath = new DOMXPath("prompt|blockquote"); List<Element> prompts = promptPath.selectNodes(i); for (Element prompt : prompts) { additionalText = additionalText.concat(normalizeElementBody(contentsDOM, prompt)); } if (fillBlanks) { Element replaceDivElement = contentsDOM.createElement("div"); i.setTextContent(additionalText + "{}"); itemBodyElement.appendChild(replaceDivElement); } else i.setTextContent(additionalText); } // normalize all child nodes and create a string String content = normalizeElementBody(contentsDOM, itemBodyElement); return content; }
From source file:org.etudes.mneme.impl.ImportQti2ServiceImpl.java
/** * Create True False question when interaction is choiceInteraction and 2 choices. * //from w w w .j a v a 2 s .co m * @param tf * @param text * @param contentsDOM * @return * @throws Exception */ private Question buildTrueFalse(Pool pool, String text, String interactionText, Document contentsDOM) throws Exception { if (interactionText == null || !interactionText.equals("choiceInteraction")) return null; XPath responseDeclarePath = new DOMXPath("/assessmentItem/responseDeclaration"); Element responseDeclare = (Element) responseDeclarePath.selectSingleNode(contentsDOM); String cardinality = (responseDeclare.getAttribute("cardinality") != null) ? responseDeclare.getAttribute("cardinality") : null; String basetype = (responseDeclare.getAttribute("baseType") != null) ? responseDeclare.getAttribute("baseType") : null; // choice interaction XPath choicesPath = new DOMXPath("/assessmentItem/itemBody//choiceInteraction"); Element choices = (Element) choicesPath.selectSingleNode(contentsDOM); if (choices == null) return null; XPath identifierPath = new DOMXPath("/assessmentItem/responseDeclaration/correctResponse/value"); List<Element> values = identifierPath.selectNodes(contentsDOM); XPath simpleChoicesPath = new DOMXPath("//simpleChoice"); List<Element> choiceList = simpleChoicesPath.selectNodes(contentsDOM); // check for true/false traits if (!("identifier".equalsIgnoreCase(basetype) && cardinality != null && choiceList.size() == 2)) return null; List<String> answerChoices = new ArrayList<String>(); List<String> correctAnswerChoices = new ArrayList<String>(); String correctAnswer = null; // if response declaration has correct answer if (values != null && values.size() > 0) { for (Element value : values) correctAnswerChoices.add(getCorrectResponse(value, contentsDOM, false)); } else { // get correct answers from RequestProcessing correctAnswerChoices = getCorrectResponsefromResponseProcessing(contentsDOM, choices.getAttribute("responseIdentifier"), false); } for (Element Choice : choiceList) { Element ChoiceCopy = (Element) Choice.cloneNode(true); ChoiceCopy = removeFeedback(ChoiceCopy); String id = ChoiceCopy.getAttribute("identifier"); String label = normalizeElementBody(contentsDOM, ChoiceCopy); if (label == null) continue; label = label.trim(); answerChoices.add(label); if (correctAnswerChoices.contains(id)) { if ("yes".equalsIgnoreCase(label) || "Right".equalsIgnoreCase(label) || "True".equalsIgnoreCase(label)) correctAnswer = new Boolean("true").toString(); else if ("no".equalsIgnoreCase(label) || "Wrong".equalsIgnoreCase(label) || "False".equalsIgnoreCase(label)) correctAnswer = new Boolean("false").toString(); } } if (correctAnswer == null) return null; Question question = this.questionService.newQuestion(pool, "mneme:TrueFalse"); TrueFalseQuestionImpl tf = (TrueFalseQuestionImpl) (question.getTypeSpecificQuestion()); question.getPresentation().setText(text); tf.setCorrectAnswer(correctAnswer); question.getTypeSpecificQuestion().consolidate(""); return question; }
From source file:org.fireflow.webdesigner.transformer.FpdlDiagramSerializerSvgImpl.java
private Element transformConnectorShape2Svg(ConnectorShape connectorShape) { NodeShape fromNodeShape = connectorShape.getFromNode(); NodeShape toNodeShape = connectorShape.getToNode(); ModelElement wfElm = connectorShape.getWorkflowElementRef(); String wfElmId = wfElm == null ? "null" : wfElm.getId(); if (fromNodeShape == null || toNodeShape == null) { log.warn("TransitionShape[Id=" + connectorShape.getId() + ",WfElemId=" + wfElmId + "] from_nodeto_node"); return null; }/* w w w. j ava2s . com*/ Bounds absoluteFromNodeBounds = this._getAbsoluteBounds(fromNodeShape); Bounds absoluteToNodeBounds = this._getAbsoluteBounds(toNodeShape); if (absoluteFromNodeBounds == null || absoluteToNodeBounds == null) { log.warn("TransitionShape[Id=" + connectorShape.getId() + ",WfElemId=" + wfElmId + "] from_nodeto_nodebounds"); return null; } Line fireLine = (Line) connectorShape.getFigure(); List<Point> linePoints = fireLine.getPoints(); Point fromRefPoint = null;//from_anchor? Point toRefPoint = null;//to_anchor? if (linePoints == null || linePoints.size() == 0) { fromRefPoint = new Point(); fromRefPoint.setX(absoluteToNodeBounds.getX() + absoluteToNodeBounds.getWidth() / 2); fromRefPoint.setY(absoluteToNodeBounds.getY() + absoluteToNodeBounds.getHeight() / 2); } else { fromRefPoint = linePoints.get(0); } if (linePoints == null || linePoints.size() == 0) { toRefPoint = new Point(); toRefPoint.setX(absoluteFromNodeBounds.getX() + absoluteFromNodeBounds.getWidth() / 2); toRefPoint.setY(absoluteFromNodeBounds.getY() + absoluteFromNodeBounds.getHeight() / 2); } else { toRefPoint = linePoints.get(linePoints.size() - 1); } //from_anchor Point fromAnchor = null; fromAnchor = _calculateAnchor(fromNodeShape, absoluteFromNodeBounds, fromRefPoint); //to_anchor Point toAnchor = null; toAnchor = _calculateAnchor(toNodeShape, absoluteToNodeBounds, toRefPoint); Element groupElement = document.createElement("g"); String elementType = null; groupElement.setAttribute(FPDLNames.ID, connectorShape.getId()); if (connectorShape instanceof TransitionShape) { elementType = FPDLNames.TRANSITION; } else if (connectorShape instanceof MessageFlowShape) { elementType = FPDLNames.MESSAGEFLOW; } else if (connectorShape instanceof AssociationShape) { elementType = FPDLNames.ASSOCIATION; } groupElement.setAttribute(TYPE, elementType); ModelElement wfElmRef = connectorShape.getWorkflowElementRef(); if (wfElmRef != null) { groupElement.setAttribute(FPDLNames.REF, wfElmRef == null ? "" : wfElmRef.getId()); } //polyline Element polylineElm = document.createElement("polyline"); groupElement.appendChild(polylineElm); polylineElm.setAttribute("points", _makePointsSeq(fromAnchor.copy(), toAnchor.copy(), linePoints)); //2.1 StringBuffer lineStyle = (new StringBuffer()); Bounds lineBounds = fireLine.getBounds(); String color = "#000000"; if (lineBounds != null) { int thick = lineBounds.getThick(); lineStyle.append("stroke-width:").append(Integer.toString(thick < 0 ? 1 : thick)).append("px;"); color = lineBounds.getColor(); color = (color == null || color.trim().equals("")) ? "#000000" : color; lineStyle.append("stroke:").append(color).append(";"); String lineType = lineBounds.getLineType(); if (Bounds.LINETYPE_DOTTED.equals(lineType) || Bounds.LINETYPE_DASHED.equals(lineType) || Bounds.LINETYPE_DASHDOTTED.equals(lineType)) { String dashArray = lineBounds.getDashArray(); if (dashArray == null || dashArray.trim().equals("")) { if (connectorShape instanceof AssociationShape) { dashArray = DEFAULT_ASSOC_DASHARRAY; } else if (connectorShape instanceof MessageFlowShape) { dashArray = DEFAULT_MESSAGEFLOW_DASHARRAY; } else { if (Bounds.LINETYPE_DOTTED.equals(lineType)) { dashArray = DEFAULT_DOT_DASHARRAY; } else if (Bounds.LINETYPE_DASHED.equals(lineType)) { dashArray = DEFAULT_DASH_DASHARRAY; } else if (Bounds.LINETYPE_DASHDOTTED.equals(lineType)) { dashArray = DEFAULT_DOTDASH_DASHARRAY; } } } lineStyle.append("stroke-dasharray: ").append(lineBounds.getDashArray()).append(";"); } } // if (connectorShape instanceof TransitionShape) { Element mkElm = this.blockArrowMarkerMap.get(color); String mkId = BASIC_BLOCK_ARROW_MARKER_ID; if (mkElm != null) { mkId = mkElm.getAttribute("id"); } else { //marker Element mkElmOriginal = this.blockArrowMarkerMap.get("#000000"); if (mkElmOriginal != null) { Element newElm = (Element) mkElmOriginal.cloneNode(true); mkId = connectorShape.getId() + "_end_marker"; newElm.setAttribute("id", mkId); Element pathElm = (Element) newElm.getFirstChild(); pathElm.setAttribute("style", "stroke:none;fill:" + color + ";"); blockArrowMarkerMap.put(color, newElm); this.defsElement.appendChild(newElm); } } polylineElm.setAttribute("marker-end", "url(#" + mkId + ")"); } else if (connectorShape instanceof MessageFlowShape) { Element mkElm = this.circleMarkerMap.get(color); String mkId = BASIC_CIRCLE_MARKER_ID; if (mkElm != null) { mkId = mkElm.getAttribute("id"); } else { //marker Element mkElmOriginal = this.circleMarkerMap.get("#000000"); if (mkElmOriginal != null) { Element newElm = (Element) mkElmOriginal.cloneNode(true); mkId = connectorShape.getId() + "_start_marker"; newElm.setAttribute("id", mkId); Element pathElm = (Element) newElm.getFirstChild(); pathElm.setAttribute("style", "stroke:" + color + ";fill:none;stroke-dasharray:2,0;"); circleMarkerMap.put(color, newElm); this.defsElement.appendChild(newElm); } } polylineElm.setAttribute("marker-start", "url(#" + mkId + ")"); mkElm = this.blockArrowMarker2Map.get(color); mkId = BASIC_BLOCK_ARROW_MARKER2_ID; if (mkElm != null) { mkId = mkElm.getAttribute("id"); } else { //marker Element mkElmOriginal = this.blockArrowMarker2Map.get("#000000"); if (mkElmOriginal != null) { Element newElm = (Element) mkElmOriginal.cloneNode(true); mkId = connectorShape.getId() + "_end_marker"; newElm.setAttribute("id", mkId); Element pathElm = (Element) newElm.getFirstChild(); pathElm.setAttribute("style", "stroke:" + color + ";fill:none;stroke-dasharray:2,0;"); blockArrowMarker2Map.put(color, newElm); this.defsElement.appendChild(newElm); } } polylineElm.setAttribute("marker-end", "url(#" + mkId + ")"); } // lineStyle.append("fill:none;"); polylineElm.setAttribute("style", lineStyle.toString()); // Label lb = fireLine.getTitleLabel(); String displayName = null; if (wfElm != null) { displayName = wfElm.getDisplayName(); } else { displayName = fireLine.getTitle(); } if (displayName != null && !displayName.trim().equals("")) { Point labelRelativePos = fireLine.getLabelPosition(); //labelAbsPoslabel Point labelAbsPos = _getLabelAbsolutePosition(fromAnchor.copy(), toAnchor.copy(), linePoints, labelRelativePos); Label titleLabel = null; if (lb == null) { titleLabel = new LabelImpl(); titleLabel.setFontSize(DEFAULT_FONT_SIZE); } else { titleLabel = lb.copy(); } titleLabel.setText(displayName); Dimension dimension = _calculateFontSize(titleLabel.getText(), titleLabel.getFontSize()); labelAbsPos.setX(labelAbsPos.getX() - dimension.width / 2); labelAbsPos.setY(labelAbsPos.getY() - dimension.height / 2); Element textRect = this.buildTextBox(connectorShape, elementType, labelAbsPos.getX(), labelAbsPos.getY(), dimension.width, dimension.height, titleLabel, "middle"); groupElement.appendChild(textRect); //?? Bounds boundsTmp = new BoundsImpl(); boundsTmp.setX(labelAbsPos.getX()); boundsTmp.setY(labelAbsPos.getY()); boundsTmp.setWidth(dimension.width); boundsTmp.setHeight(dimension.height); this._refreshDiagramSize(boundsTmp); } //?? List<Point> tmpList = new ArrayList<Point>(); tmpList.addAll(linePoints); tmpList.add(fromAnchor); tmpList.add(toAnchor); _refreshDiagramSize(tmpList); return groupElement; }
From source file:org.fireflow.webdesigner.transformer.FpdlDiagramSerializerVmlImpl.java
private Element transformPool2Vml(PoolShape nodeShape, boolean isTopLevelElem) { // 1?viewport Bounds viewportBounds = _getViewPortBounds(nodeShape); Rectangle figure = (Rectangle) nodeShape.getFigure(); Element nodeGroup = document.createElement("v:group"); StringBuffer groupStyle = new StringBuffer(); groupStyle.append("position:absolute;").append("left:").append(viewportBounds.getX()).append("px;") .append("top:").append(viewportBounds.getY()).append("px;").append("width:") .append(viewportBounds.getWidth()).append("px;").append("height:") .append(viewportBounds.getHeight()).append("px;"); nodeGroup.setAttribute("style", groupStyle.toString()); nodeGroup.setAttribute(FPDLNames.ID, nodeShape.getId()); nodeGroup.setAttribute(TYPE, FPDLNames.POOL); ModelElement wfElmRef = nodeShape.getWorkflowElementRef(); if (wfElmRef != null) { nodeGroup.setAttribute(FPDLNames.REF, wfElmRef == null ? "" : wfElmRef.getId()); }// w w w.j av a 2 s . co m StringBuffer coordSizeBuf = new StringBuffer(); coordSizeBuf.append(viewportBounds.getWidth()).append(",").append(viewportBounds.getHeight()); nodeGroup.setAttribute("coordsize", coordSizeBuf.toString()); // 2?pool Bounds rectBounds = figure.getBounds().copy(); int thick = rectBounds.getThick(); int newWidth = rectBounds.getWidth() - thick * 2; int newHeight = rectBounds.getHeight() - thick * 2; Element rect = document.createElement("v:rect"); StringBuffer rectStyle = (new StringBuffer()).append("position:absolute;").append("left:").append(thick) .append("px;").append("top:").append(thick).append("px;").append("width:").append(newWidth) .append("px;").append("height:").append(newHeight).append("px;").append("z-index:-1;"); rect.setAttribute("style", rectStyle.toString()); nodeGroup.appendChild(rect); Element line = document.createElement("v:line"); if (Diagram.VERTICAL.equals(diagram.getDirection())) { String from = thick + "," + POOL_LANE_TITLE_HEIGHT; line.setAttribute("from", from); String to = (thick + newWidth) + "," + POOL_LANE_TITLE_HEIGHT; line.setAttribute("to", to); } else { String from = POOL_LANE_TITLE_HEIGHT + "," + thick; line.setAttribute("from", from); String to = POOL_LANE_TITLE_HEIGHT + "," + (thick + newHeight); line.setAttribute("to", to); } nodeGroup.appendChild(line); // 2.1 if (rectBounds != null) { Element stroke = document.createElement("v:stroke"); stroke.setAttribute("weight", Integer.toString(thick < 0 ? 1 : thick) + "px"); String color = rectBounds.getColor(); stroke.setAttribute("color", (color == null || color.trim().equals("")) ? "#000000" : color); String lineType = rectBounds.getLineType(); if (lineType == null || lineType.trim().equals("")) { stroke.setAttribute("dashstyle", "solid"); } else if (Bounds.LINETYPE_DOTTED.equals(lineType)) { stroke.setAttribute("dashstyle", "dot"); } else if (Bounds.LINETYPE_DASHED.equals(lineType)) { stroke.setAttribute("dashstyle", "dash"); } else if (Bounds.LINETYPE_DASHDOTTED.equals(lineType)) { stroke.setAttribute("dashstyle", "dashdot"); } Element stroke2 = (Element) stroke.cloneNode(true); rect.appendChild(stroke); line.appendChild(stroke2); } // 2.2 if (figure.getFulfilStyle() != null) { String color1 = figure.getFulfilStyle().getColor1(); String color2 = figure.getFulfilStyle().getColor2(); String gradient = figure.getFulfilStyle().getGradientStyle(); Element fillStyle = document.createElement("v:fill"); if (gradient == null || gradient.trim().equals("") || FulfilStyle.GRADIENT_STYLE_NONE.equals(gradient)) { fillStyle.setAttribute("type", "solid"); fillStyle.setAttribute("color", color2); } else { fillStyle.setAttribute("type", "gradient"); fillStyle.setAttribute("method", "linear"); fillStyle.setAttribute("color", color1); fillStyle.setAttribute("color2", color2); if (FulfilStyle.GRADIENT_STYLE_TOP2DOWN.equals(gradient)) { fillStyle.setAttribute("angle", "180");// } else if (FulfilStyle.GRADIENT_STYLE_UPPERLEFT2LOWERRIGHT.equals(gradient)) { fillStyle.setAttribute("angle", "225"); } else if (FulfilStyle.GRADIENT_STYLE_UPPERRIGHT2LOWERLEFT.equals(gradient)) { fillStyle.setAttribute("angle", "135"); } else if (FulfilStyle.GRADIENT_STYLE_LEFT2RIGHT.equals(gradient)) { fillStyle.setAttribute("angle", "270");// ? } else { fillStyle.setAttribute("angle", "270");// ? } } rect.appendChild(fillStyle); } // 2.3 label?? String title = figure.getTitle(); if (title != null && !title.trim().equals("")) { // textbox int paddingLeft = (thick); Label titleLabel = figure.getTitleLabel().copy(); int fontSize = titleLabel.getFontSize(); ; int textRectHeight = (int) (fontSize + 2);// ? int check = POOL_LANE_TITLE_HEIGHT - textRectHeight - thick; int paddingTop = thick; if (check > 0) { paddingTop = thick + (int) (check / 2); } else { textRectHeight = POOL_LANE_TITLE_HEIGHT - thick; } // ?? if (Diagram.VERTICAL.equals(diagram.getDirection())) { int width = rectBounds.getWidth() - paddingLeft * 2;// width???2?thick if (width < 0) { width = 0; } Element textRect = this.buildVmlTextBox(nodeShape, FPDLNames.POOL, paddingLeft, paddingTop, width, textRectHeight, titleLabel, true, "center"); nodeGroup.appendChild(textRect); } else {// ?? int height = rectBounds.getHeight() - paddingLeft * 2; Element textRect = this.buildVmlTextBox(nodeShape, FPDLNames.POOL, paddingTop, paddingLeft, textRectHeight, height, titleLabel, true, "center", "middle", false); nodeGroup.appendChild(textRect); } } if (isTopLevelElem) { _refreshDiagramSize(viewportBounds); } // 3?? List<DiagramElement> children = nodeShape.getChildren(); if (children != null && children.size() > 0) { // ?? Element childrenGroup = document.createElement("v:group"); StringBuffer tmpStyle = new StringBuffer(); if (Diagram.VERTICAL.equals(diagram.getDirection())) { tmpStyle.append("position:absolute;").append("left:").append(thick).append("px;") // .append("top:").append(POOL_LANE_TITLE_HEIGHT).append("px;") // .append("width:").append(newWidth).append("px;").append("height:") .append(rectBounds.getHeight() - GROUP_TITLE_HEIGHT - thick).append("px"); } else { tmpStyle.append("position:absolute;").append("left:").append(POOL_LANE_TITLE_HEIGHT).append("px;") .append("top:").append(thick).append("px;").append("width:") .append(rectBounds.getWidth() - POOL_LANE_TITLE_HEIGHT - thick).append("px;") .append("height:").append(newHeight).append("px"); } childrenGroup.setAttribute("style", tmpStyle.toString()); if (Diagram.VERTICAL.equals(diagram.getDirection())) { StringBuffer coordSizeBufTmp = new StringBuffer(); coordSizeBufTmp.append(newWidth).append(",") .append(rectBounds.getHeight() - GROUP_TITLE_HEIGHT - thick); childrenGroup.setAttribute("coordsize", coordSizeBufTmp.toString()); } else { StringBuffer coordSizeBufTmp = new StringBuffer(); coordSizeBufTmp.append(viewportBounds.getWidth() - POOL_LANE_TITLE_HEIGHT - thick).append(",") .append(newHeight); childrenGroup.setAttribute("coordsize", coordSizeBufTmp.toString()); } int offset = 0; int laneCount = children.size(); for (int index = 0; index < laneCount; index++) { DiagramElement diagramElm = children.get(index); if (diagramElm instanceof LaneShape) { LaneShape laneShape = (LaneShape) diagramElm; Element elm = this.transformLane2Vml(laneShape, offset, index, laneCount); if (elm != null) { childrenGroup.appendChild(elm); } Rectangle rectTmp = (Rectangle) laneShape.getFigure(); Bounds tmpBounds = rectTmp.getBounds(); if (Diagram.VERTICAL.equals(diagram.getDirection())) { offset = offset + tmpBounds.getWidth(); } else { offset = offset + tmpBounds.getHeight(); } } } nodeGroup.appendChild(childrenGroup); } return nodeGroup; }
From source file:org.fireflow.webdesigner.transformer.FpdlDiagramSerializerVmlImpl.java
private Element transformLane2Vml(LaneShape nodeShape, int offset, int laneIndex, int laneCount) { Bounds viewportBounds = _getViewPortBounds(nodeShape); Rectangle figure = (Rectangle) nodeShape.getFigure(); Element nodeGroup = document.createElement("v:group"); StringBuffer groupStyle = new StringBuffer(); groupStyle.append("position:absolute;").append("width:").append(viewportBounds.getWidth()).append("px;") .append("height:").append(viewportBounds.getHeight()).append("px;"); if (Diagram.VERTICAL.equals(diagram.getDirection())) { groupStyle.append("left:").append(offset).append("px;").append("top:").append(0).append("px;"); } else {/*from www . j a v a2s. c o m*/ groupStyle.append("left:").append(0).append("px;").append("top:").append(offset).append("px;"); } nodeGroup.setAttribute("style", groupStyle.toString()); nodeGroup.setAttribute(FPDLNames.ID, nodeShape.getId()); nodeGroup.setAttribute(TYPE, FPDLNames.LANE); ModelElement wfElmRef = nodeShape.getWorkflowElementRef(); if (wfElmRef != null) { nodeGroup.setAttribute(FPDLNames.REF, wfElmRef == null ? "" : wfElmRef.getId()); } StringBuffer coordSizeBuf = new StringBuffer(); coordSizeBuf.append(viewportBounds.getWidth()).append(",").append(viewportBounds.getHeight()); nodeGroup.setAttribute("coordsize", coordSizeBuf.toString()); Bounds rectBounds = figure.getBounds().copy(); int thick = rectBounds.getThick(); int newWidth = rectBounds.getWidth() - thick * 2; int newHeight = rectBounds.getHeight() - thick * 2; String title = figure.getTitle(); // Element stroke = null; if (rectBounds != null) { stroke = document.createElement("v:stroke"); stroke.setAttribute("weight", Integer.toString(thick < 0 ? 1 : thick) + "px"); String color = rectBounds.getColor(); stroke.setAttribute("color", (color == null || color.trim().equals("")) ? "#000000" : color); String lineType = rectBounds.getLineType(); if (lineType == null || lineType.trim().equals("")) { stroke.setAttribute("dashstyle", "solid"); } else if (Bounds.LINETYPE_DOTTED.equals(lineType)) { stroke.setAttribute("dashstyle", "dot"); } else if (Bounds.LINETYPE_DASHED.equals(lineType)) { stroke.setAttribute("dashstyle", "dash"); } else if (Bounds.LINETYPE_DASHDOTTED.equals(lineType)) { stroke.setAttribute("dashstyle", "dashdot"); } } // lane if (Diagram.VERTICAL.equals(diagram.getDirection())) { // 2 if (title != null && !title.trim().equals("")) { Element line = document.createElement("v:line"); String from = thick + "," + POOL_LANE_TITLE_HEIGHT; line.setAttribute("from", from); String to = (thick + newWidth) + "," + POOL_LANE_TITLE_HEIGHT; line.setAttribute("to", to); if (stroke != null) { Node tmpStroke = stroke.cloneNode(true); line.appendChild(tmpStroke); } nodeGroup.appendChild(line); } // if (laneIndex > 0) { Element line = document.createElement("v:line"); String from = thick + "," + thick; line.setAttribute("from", from); String to = (thick + newHeight) + "," + (thick); line.setAttribute("to", to); if (stroke != null) { Node tmpStroke = stroke.cloneNode(true); line.appendChild(tmpStroke); } nodeGroup.appendChild(line); } } else { // 1 // 2 if (title != null && !title.trim().equals("")) { Element line = document.createElement("v:line"); String from = POOL_LANE_TITLE_HEIGHT + "," + thick; line.setAttribute("from", from); String to = POOL_LANE_TITLE_HEIGHT + "," + (thick + newHeight); line.setAttribute("to", to); if (stroke != null) { Node tmpStroke = stroke.cloneNode(true); line.appendChild(tmpStroke); } nodeGroup.appendChild(line); } // if (laneIndex > 0) { Element line = document.createElement("v:line"); String from = thick + "," + thick; line.setAttribute("from", from); String to = (thick + newWidth) + "," + (thick); line.setAttribute("to", to); if (stroke != null) { Node tmpStroke = stroke.cloneNode(true); line.appendChild(tmpStroke); } nodeGroup.appendChild(line); } } // Element rect = document.createElement("v:rect"); StringBuffer rectStyle = (new StringBuffer()).append("position:absolute;").append("width:").append(newWidth) .append("px;").append("height:").append(newHeight).append("px;").append("z-index:-1;"); rectStyle.append("left:").append(thick).append("px;").append("top:").append(thick).append("px;"); rect.setAttribute("style", rectStyle.toString()); rect.setAttribute("stroked", "false"); nodeGroup.appendChild(rect); /* rect.appendChild(stroke); */ if (figure.getFulfilStyle() != null) { String color1 = figure.getFulfilStyle().getColor1(); String color2 = figure.getFulfilStyle().getColor2(); String gradient = figure.getFulfilStyle().getGradientStyle(); Element fillStyle = document.createElement("v:fill"); if (gradient == null || gradient.trim().equals("") || FulfilStyle.GRADIENT_STYLE_NONE.equals(gradient)) { fillStyle.setAttribute("type", "solid"); fillStyle.setAttribute("color", color2); } else { fillStyle.setAttribute("type", "gradient"); fillStyle.setAttribute("method", "linear"); fillStyle.setAttribute("color", color1); fillStyle.setAttribute("color2", color2); if (FulfilStyle.GRADIENT_STYLE_TOP2DOWN.equals(gradient)) { fillStyle.setAttribute("angle", "180");// } else if (FulfilStyle.GRADIENT_STYLE_UPPERLEFT2LOWERRIGHT.equals(gradient)) { fillStyle.setAttribute("angle", "225"); } else if (FulfilStyle.GRADIENT_STYLE_UPPERRIGHT2LOWERLEFT.equals(gradient)) { fillStyle.setAttribute("angle", "135"); } else if (FulfilStyle.GRADIENT_STYLE_LEFT2RIGHT.equals(gradient)) { fillStyle.setAttribute("angle", "270");// ? } else { fillStyle.setAttribute("angle", "270");// ? } } rect.appendChild(fillStyle); } // label?? if (title != null && !title.trim().equals("")) { int paddingLeft = (thick); Label titleLabel = figure.getTitleLabel().copy(); int fontSize = titleLabel.getFontSize(); int textRectHeight = (int) (fontSize + 2);// ? int check = POOL_LANE_TITLE_HEIGHT - textRectHeight - thick; int paddingTop = thick; if (check > 0) { paddingTop = thick + (int) (check / 2); } else { textRectHeight = POOL_LANE_TITLE_HEIGHT - thick; } // ?? if (Diagram.VERTICAL.equals(diagram.getDirection())) { int width = rectBounds.getWidth() - paddingLeft * 2;// width???2?thick if (width < 0) { width = 0; } Element textRect = this.buildVmlTextBox(nodeShape, FPDLNames.LANE, paddingLeft, paddingTop, width, textRectHeight, titleLabel, true, "center"); nodeGroup.appendChild(textRect); } else {// ?? int height = rectBounds.getHeight() - paddingLeft * 2; Element textRect = this.buildVmlTextBox(nodeShape, FPDLNames.LANE, paddingTop, paddingLeft, textRectHeight, height, titleLabel, true, "center", "middle", false); nodeGroup.appendChild(textRect); } } // ? List<DiagramElement> children = nodeShape.getChildren(); if (children != null && children.size() > 0) { // ?? Element childrenGroup = document.createElement("v:group"); StringBuffer tmpStyle = new StringBuffer(); if (Diagram.VERTICAL.equals(diagram.getDirection())) { tmpStyle.append("position:absolute;").append("left:").append(thick).append("px;").append("top:") .append(POOL_LANE_TITLE_HEIGHT).append("px;").append("width:") .append(rectBounds.getWidth() - thick * 2).append("px;").append("height:") .append(rectBounds.getHeight() - POOL_LANE_TITLE_HEIGHT - thick).append("px"); } else { tmpStyle.append("position:absolute;").append("left:").append(POOL_LANE_TITLE_HEIGHT).append("px;") .append("top:").append(thick).append("px;").append("width:") .append(rectBounds.getWidth() - POOL_LANE_TITLE_HEIGHT - thick).append("px;") .append("height:").append(rectBounds.getHeight() - thick * 2).append("px"); } childrenGroup.setAttribute("style", tmpStyle.toString()); if (Diagram.VERTICAL.equals(diagram.getDirection())) { StringBuffer coordSizeBufTmp = new StringBuffer(); coordSizeBufTmp.append(rectBounds.getWidth() - thick * 2).append(",") .append(rectBounds.getHeight() - POOL_LANE_TITLE_HEIGHT - thick); childrenGroup.setAttribute("coordsize", coordSizeBufTmp.toString()); } else { StringBuffer coordSizeBufTmp = new StringBuffer(); coordSizeBufTmp.append(rectBounds.getWidth() - POOL_LANE_TITLE_HEIGHT - thick).append(",") .append(rectBounds.getHeight() - thick * 2); childrenGroup.setAttribute("coordsize", coordSizeBufTmp.toString()); } for (DiagramElement diagramElm : children) { if (diagramElm instanceof ProcessNodeShape) { Element elm = this.transformProcessNodeShape2Vml((ProcessNodeShape) diagramElm, false); if (elm != null) { childrenGroup.appendChild(elm); } } else if (diagramElm instanceof CommentShape) { Element elm = this.transformCommentShape2Vml((CommentShape) diagramElm, false); if (elm != null) { childrenGroup.appendChild(elm); } } else if (diagram instanceof GroupShape) { Element elm = this.transformGroupShape2Vml((GroupShape) diagram, false); if (elm != null) { childrenGroup.appendChild(elm); } } } nodeGroup.appendChild(childrenGroup); } return nodeGroup; }