@Override public void endElement(String uri, String localName, String qName) { if (qName.equals("target")) { // End 'target': Save the preceding raw text (if any). Then create a SoyMsg object from the // collected message data and add it to msgs list. if (currRawTextPart != null) { currMsgParts.add(SoyMsgRawTextPart.of(currRawTextPart)); currRawTextPart = null; } isInMsg = false; if (!currMsgParts.isEmpty()) { msgs.add( SoyMsg.builder() .setId(currMsgId) .setLocaleString(targetLocaleString) .setParts(currMsgParts) .build()); } } }
@Override public void endElement(String uri, String localName, String qName) { if (qName.equals("target")) { // End 'target': Save the preceding raw text (if any). Then create a SoyMsg object from the // collected message data and add it to msgs list. if (currRawTextPart != null) { currMsgParts.add(SoyMsgRawTextPart.of(currRawTextPart)); currRawTextPart = null; } isInMsg = false; if (!currMsgParts.isEmpty()) { msgs.add( SoyMsg.builder() .setId(currMsgId) .setLocaleString(targetLocaleString) .setParts(currMsgParts) .build()); } } }
/** * Returns a more memory-efficient version of the internal message bundle. * * <p>Only enough information is retained for rendering; not enough for message extraction. As a * side effect, this SoyMsgBundleCompactor instance will also retain references to parts of the * messages in order to reuse identical objects. */ public SoyMsgBundle compact(SoyMsgBundle input) { ImmutableList.Builder<SoyMsg> builder = ImmutableList.builder(); for (SoyMsg msg : input) { ImmutableList<SoyMsgPart> parts = compactParts(msg.getParts()); builder.add( SoyMsg.builder() .setId(msg.getId()) .setLocaleString(msg.getLocaleString()) .setIsPlrselMsg(MsgPartUtils.hasPlrselPart(parts)) .setParts(parts) .build()); } return new RenderOnlySoyMsgBundleImpl(input.getLocaleString(), builder.build()); }
/** Creates a new {@link Builder} based on the current instance. */ Builder toBuilder() { Builder builder = builder() .setId(getId()) .setIsHidden(isHidden()) .setParts(getParts()) .addAllSourceLocations(getSourceLocations()) .setIsPlrselMsg(isPlrselMsg()); if (getLocaleString() != null) { builder.setLocaleString(getLocaleString()); } if (getMeaning() != null) { builder.setMeaning(getMeaning()); } if (getDesc() != null) { builder.setDesc(getDesc()); } if (getAltId() != -1) { builder.setAltId(getAltId()); } if (getContentType() != null) { builder.setContentType(getContentType()); } return builder; }
/** * Returns a more memory-efficient version of the internal message bundle. * * <p>Only enough information is retained for rendering; not enough for message extraction. As a * side effect, this SoyMsgBundleCompactor instance will also retain references to parts of the * messages in order to reuse identical objects. */ public SoyMsgBundle compact(SoyMsgBundle input) { ImmutableList.Builder<SoyMsg> builder = ImmutableList.builder(); for (SoyMsg msg : input) { ImmutableList<SoyMsgPart> parts = compactParts(msg.getParts()); builder.add( SoyMsg.builder() .setId(msg.getId()) .setLocaleString(msg.getLocaleString()) .setIsPlrselMsg(MsgPartUtils.hasPlrselPart(parts)) .setParts(parts) .build()); } return new RenderOnlySoyMsgBundleImpl(input.getLocaleString(), builder.build()); }
@Override protected void visitMsgNode(MsgNode node) { MsgPartsAndIds msgPartsAndIds = MsgUtils.buildMsgPartsAndComputeMsgIdForDualFormat(node); SoyMsg.Builder builder = SoyMsg.builder().setId(msgPartsAndIds.id); if (node.getMeaning() != null) { builder.setMeaning(node.getMeaning()); } SoyMsg msg = builder .setDesc(node.getDesc()) .setIsHidden(node.isHidden()) .setContentType(node.getContentType()) .setSourceLocation(node.getSourceLocation()) .setIsPlrselMsg(node.isPlrselMsg()) .setParts(msgPartsAndIds.parts) .build(); msgs.add(msg); }
@Override protected void visitMsgNode(MsgNode node) { MsgPartsAndIds msgPartsAndIds = MsgUtils.buildMsgPartsAndComputeMsgIdForDualFormat(node); SoyMsg.Builder builder = SoyMsg.builder().setId(msgPartsAndIds.id); if (node.getMeaning() != null) { builder.setMeaning(node.getMeaning()); } SoyMsg msg = builder .setDesc(node.getDesc()) .setIsHidden(node.isHidden()) .setContentType(node.getContentType()) .addSourceLocation(node.getSourceLocation()) .setIsPlrselMsg(node.isPlrselMsg()) .setParts(msgPartsAndIds.parts) .build(); msgs.add(msg); }
/** Brings a message back to life from only its ID and parts. */ @SuppressWarnings("unchecked") // The constructor guarantees the type of ImmutableList. private SoyMsg resurrectMsg(long id, ImmutableList<SoyMsgPart> parts) { return SoyMsg.builder() .setId(id) .setLocaleString(localeString) .setIsPlrselMsg(MsgPartUtils.hasPlrselPart(parts)) .setParts(parts) .build(); }
/** Brings a message back to life from only its ID and parts. */ @SuppressWarnings("unchecked") // The constructor guarantees the type of ImmutableList. private SoyMsg resurrectMsg(long id, ImmutableList<SoyMsgPart> parts) { return SoyMsg.builder() .setId(id) .setLocaleString(localeString) .setIsPlrselMsg(MsgPartUtils.hasPlrselPart(parts)) .setParts(parts) .build(); }